Labyrinth/Writer/Render/CGI.pm

filter: Statementstmt 60.0% 27 / 45 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 8 / 12 Podpod 100% 4 / 4 totaltotal 60.0% 39 / 65 CC 3 SCAR 12.7
CC
3
Cov
55%
binary
12.0
new
2.0
redirect
2.0
CRAP 3.6
« Labyrinth/Audit.pm ↑ Summary Labyrinth/Constraints/Emails.pm »
1 package Labyrinth::Writer::Render::CGI;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 $VERSION = '5.32';
8  
9 =head1 NAME
10  
11 Labyrinth::Writer::Render::CGI - Output Handler via CGI for Labyrinth.
12  
13 =head1 SYNOPSIS
14  
15 use Labyrinth::Writer::Render::CGI;
16 my $render = Labyrinth::Writer::Render::CGI->new();
17  
18 $render->redirect($url); # HTTP redirect
19  
20 $render->publish($format, $text);
21  
22 =head1 DESCRIPTION
23  
24 Use CGI to output text or redirect.
25  
26 =cut
27  
28 # -------------------------------------
29 # Library Modules
30  
31 4 ▶use CGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 4 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 4 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 4 ▶use Labyrinth::Globals;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 4 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 # -------------------------------------
39 # Variables
40  
41 4 my $cgi = CGI->new();
42  
43 # -------------------------------------
44 # The Subs
45  
46 =head1 METHODS
47  
48 =over 4
49  
50 =item new
51  
52 Object constructor.
53  
54 =item redirect($url)
55  
56 Redirect to given URL.
57  
58 =item binary($vars)
59  
60 Shorthand output of binary data and files.
61  
62 =item publish($format, $text)
63  
64 Publishes text output.
65  
66 =back
67  
68 =cut
69  
70 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
71 0 my($class) = @_;
72  
73 0 my $self = bless { cgi => 1 }, $class;
74 0 $self;
75 }
76  
77 0 ▶sub redirect {
Subroutine redirect: not called CC=1 SCAR=6.9
Pod documented
78 0 my ($self, $url) = @_;
79 0 print $cgi->redirect($url);
80 }
81  
82 0 ▶sub binary {
Subroutine binary: not called CC=3 SCAR=24.8
Pod documented
83 0 my ($self, $vars) = @_;
84  
85 0 my $fh = IO::File->new($settings{webdir}.'/'.$vars->{file},'r');
86 0 ▶ if($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) 0 0 0
87 0 print $cgi->header( -type => $vars->{ctype} );
88 0 my $buffer;
89 0 ▶ while(read($fh,$buffer,1024)) { print $buffer }
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, $buffer, 1024) 0 0 0
90 0 $fh->close;
91 }
92 }
93  
94 0 ▶sub publish {
Subroutine publish: not called CC=1 SCAR=6.9
Pod documented
95 0 my ($self, $headers, $body) = @_;
96  
97 0 my %cgihash = map { '-' . $_ => $headers->{$_} } grep {$headers->{$_}} qw(type status cookie attachment charset);
98 #LogDebug("CGI Hash=".Dumper(\%cgihash));
99  
100 0 print $cgi->header( %cgihash ) . $$body;
101 }
102  
103 4 1;
104  
105 __END__
« Labyrinth/Audit.pm ↑ Summary Labyrinth/Constraints/Emails.pm »