| 1 | package Labyrinth::Writer; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 12 | $VERSION = '5.32'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Labyrinth::Writer - Output Management for Labyrinth | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | use Labyrinth::Writer; | ||||||||||||||||||||||||||||
| 16 | Publish('mytemplate.html'); | ||||||||||||||||||||||||||||
| 17 | PublishCode('MESSAGE'); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | The Publish package contains one function, Publish(), which handles | ||||||||||||||||||||||||||||
| 22 | the parsing of a given template with global variables and prints the result. | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 EXPORT | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | Publish | ||||||||||||||||||||||||||||
| 27 | PublishCode | ||||||||||||||||||||||||||||
| 28 | UnPublish | ||||||||||||||||||||||||||||
| 29 | Transform | ||||||||||||||||||||||||||||
| 30 | Croak | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 35 | # Export Details | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 12 | require Exporter; | |||||||||||||||||||||||||||
| 38 | 12 | @ISA = qw( Exporter ); | |||||||||||||||||||||||||||
| 39 | 12 | @EXPORT_OK = qw( Publish PublishCode UnPublish Transform Croak ); | |||||||||||||||||||||||||||
| 40 | 12 | @EXPORT = qw( Publish PublishCode UnPublish Transform Croak ); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 43 | # Library Modules | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 12 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 12 | ▶ | use MIME::Types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 12 | ▶ | use Labyrinth::Audit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 12 | ▶ | use Labyrinth::Globals; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 12 | ▶ | use Labyrinth::Variables; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 12 | ▶ | use Labyrinth::MLUtils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 54 | # Variables | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 12 | my ($PARSER,$RENDER); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 12 | my $published; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 12 | my %codes = ( | |||||||||||||||||||||||||||
| 61 | BADLAYOUT => 'public/badlayout.html', | ||||||||||||||||||||||||||||
| 62 | BADPAGE => 'public/badpage.html', | ||||||||||||||||||||||||||||
| 63 | BADCMD => 'public/badcommand.html', | ||||||||||||||||||||||||||||
| 64 | MESSAGE => 'public/error_message.html', | ||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 12 | my %binary = ( | |||||||||||||||||||||||||||
| 68 | pdf => 'application/pdf' | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 12 | my %knowntypes = ( | |||||||||||||||||||||||||||
| 72 | html => 'text/html', | ||||||||||||||||||||||||||||
| 73 | ics => 'text/calendar', | ||||||||||||||||||||||||||||
| 74 | #js => 'application/javascript', | ||||||||||||||||||||||||||||
| 75 | js => 'text/html', | ||||||||||||||||||||||||||||
| 76 | json => 'application/json', | ||||||||||||||||||||||||||||
| 77 | rss => 'application/xml', | ||||||||||||||||||||||||||||
| 78 | txt => 'text/plain', | ||||||||||||||||||||||||||||
| 79 | xml => 'application/xml', | ||||||||||||||||||||||||||||
| 80 | yml => 'text/yaml', | ||||||||||||||||||||||||||||
| 81 | yaml => 'text/yaml' | ||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 85 | # The Subs | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =over 4 | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =item Config() | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Configure template parser and output method. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub Config { | ||||||||||||||||||||||||||
|
Subroutine
Config: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $settings{'writer-parser'} ||= 'TT'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$Labyrinth::Writer::settings{"writer-parser"} ||= "TT"
MC/DC0%0/1
$Labyrinth::Writer::settings{"writer-parser"} ||= "TT"
$Labyrinth::Writer::settings{"writer-parser"}
Truth table0%0/2
A
A= $Labyrinth::Writer::settings{"writer-parser"}
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $settings{'writer-render'} ||= 'CGI'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$Labyrinth::Writer::settings{"writer-render"} ||= "CGI"
MC/DC0%0/1
$Labyrinth::Writer::settings{"writer-render"} ||= "CGI"
$Labyrinth::Writer::settings{"writer-render"}
Truth table0%0/2
A
A= $Labyrinth::Writer::settings{"writer-render"}
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | my $parser = 'Labyrinth::Writer::Parser::' . $settings{'writer-parser'}; | |||||||||||||||||||||||||||
| 102 | 0 | my $render = 'Labyrinth::Writer::Render::' . $settings{'writer-render'}; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | eval { | |||||||||||||||||||||||||||
| 105 | 0 | eval "CORE::require $parser"; | |||||||||||||||||||||||||||
| 106 | 0 | $PARSER = $parser->new(); | |||||||||||||||||||||||||||
| 107 | }; | ||||||||||||||||||||||||||||
| 108 | 0 | ▶ | die "Cannot load Writer::Parser package for '$settings{'writer-parser'}': $@" if($@); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | eval { | |||||||||||||||||||||||||||
| 111 | 0 | eval "CORE::require $render"; | |||||||||||||||||||||||||||
| 112 | 0 | $RENDER = $render->new(); | |||||||||||||||||||||||||||
| 113 | }; | ||||||||||||||||||||||||||||
| 114 | 0 | ▶ | die "Cannot load Writer::Render package for '$settings{'writer-render'}': $@" if($@); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =item Publish() | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Publish() parses a given template, via Template Toolkit, and prints the | ||||||||||||||||||||||||||||
| 121 | result. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =item PublishCode | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Publishes a template based on an internal code. Current codes and associated | ||||||||||||||||||||||||||||
| 126 | templates are: | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | BADLAYOUT => 'public/badlayout.html', | ||||||||||||||||||||||||||||
| 129 | BADPAGE => 'public/badpage.html', | ||||||||||||||||||||||||||||
| 130 | BADCMD => 'public/badcommand.html', | ||||||||||||||||||||||||||||
| 131 | MESSAGE => 'public/error_message.html', | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | TODO: Provide these and more as configurable codes. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =item UnPublish | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | Used to reset publishing status. Usually only applicable in mod_perl | ||||||||||||||||||||||||||||
| 138 | environments. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =item Transform | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | Given a template and a set of variables, parse without publishing the content. | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub Publish { | ||||||||||||||||||||||||||
|
Subroutine
Publish: not called CC=27 SCAR=66.3
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | return if($published); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | Config() unless($PARSER && $RENDER); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$PARSER and $RENDER
MC/DC0%0/2
$PARSER and $RENDER
$PARSER
$RENDER
Truth table0%0/3
A and B
A= $PARSERB= $RENDER
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | # redirects require minimal processing | ||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if($tvars{redirect} && $tvars{redirect} ne $tvars{request}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Labyrinth::Writer::tvars{"redirect"} and $Labyrinth::Writer::tvars{"redirect"} ne $Labyrinth::Writer::tvars{"request"}
MC/DC0%0/2
$Labyrinth::Writer::tvars{"redirect"} and $Labyrinth::Writer::tvars{"redirect"} ne $Labyrinth::Writer::tvars{"request"}
$Labyrinth::Writer::tvars{"redirect"}
$Labyrinth::Writer::tvars{"redirect"} ne $Labyrinth::Writer::tvars{"request"}
Truth table0%0/3
A and B
A= $Labyrinth::Writer::tvars{"redirect"}B= $Labyrinth::Writer::tvars{"redirect"} ne $Labyrinth::Writer::tvars{"request"}
| |||||||||||||||||||||||||||||
| 153 | 0 | $RENDER->redirect($tvars{redirect}); | |||||||||||||||||||||||||||
| 154 | 0 | $published = 1; | |||||||||||||||||||||||||||
| 155 | 0 | return; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # binary files handled directly | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if($tvars{contenttype} && $binary{$tvars{contenttype}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Labyrinth::Writer::tvars{"contenttype"} and $binary{$Labyrinth::Writer::tvars{"contenttype"}}
MC/DC0%0/2
$Labyrinth::Writer::tvars{"contenttype"} and $binary{$Labyrinth::Writer::tvars{"contenttype"}}
$Labyrinth::Writer::tvars{"contenttype"}
$binary{$Labyrinth::Writer::tvars{"contenttype"}}
Truth table0%0/3
A and B
A= $Labyrinth::Writer::tvars{"contenttype"}B= $binary{$Labyrinth::Writer::tvars{"contenttype"}}
| |||||||||||||||||||||||||||||
| 160 | 0 | $tvars{'writer'} = { 'ctype' => $binary{$tvars{'contenttype'}}, 'file' => $tvars{'file'} }; | |||||||||||||||||||||||||||
| 161 | 0 | $RENDER->binary($tvars{'writer'}); | |||||||||||||||||||||||||||
| 162 | 0 | $published = 1; | |||||||||||||||||||||||||||
| 163 | 0 | return; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $path = $settings{'templates'} || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$Labyrinth::Writer::settings{'templates'} || ''
MC/DC0%0/1
$Labyrinth::Writer::settings{'templates'} || ''
$Labyrinth::Writer::settings{'templates'}
Truth table0%0/2
A
A= $Labyrinth::Writer::settings{'templates'}
| |||||||||||||||||||||||||||||
| 167 | 0 | my $vars = \%tvars; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | unless($vars->{'layout'} && -r "$path/$vars->{'layout'}") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$vars->{"layout"} and -r qq[$path/$vars->{"layout"}]
MC/DC0%0/2
$vars->{"layout"} and -r qq[$path/$vars->{"layout"}]
$vars->{"layout"}
-r qq[$path/$vars->{"layout"}]
Truth table0%0/3
A and B
A= $vars->{"layout"}B= -r qq[$path/$vars->{"layout"}]
| |||||||||||||||||||||||||||||
| 170 | 0 | $vars->{'badlayout'} = $vars->{'layout'}; | |||||||||||||||||||||||||||
| 171 | 0 | $vars->{'layout'} = $codes{BADLAYOUT}; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | 0 | ▶ | unless($vars->{'content'} && -r "$path/$vars->{'content'}") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$vars->{"content"} and -r qq[$path/$vars->{"content"}]
MC/DC0%0/2
$vars->{"content"} and -r qq[$path/$vars->{"content"}]
$vars->{"content"}
-r qq[$path/$vars->{"content"}]
Truth table0%0/3
A and B
A= $vars->{"content"}B= -r qq[$path/$vars->{"content"}]
| |||||||||||||||||||||||||||||
| 174 | 0 | $vars->{'badcontent'} = $vars->{'content'}; | |||||||||||||||||||||||||||
| 175 | 0 | $vars->{'content'} = $codes{BADPAGE}; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | 0 | my $layout = $vars->{'layout'}; | |||||||||||||||||||||||||||
| 178 | 0 | my $content = $vars->{'content'}; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # LogDebug( "layout=[$layout]" ); | ||||||||||||||||||||||||||||
| 181 | # LogDebug( "content=[$content]" ); | ||||||||||||||||||||||||||||
| 182 | # LogDebug( "cookie=[$vars->{cookie}]" ) if($vars->{cookie}); | ||||||||||||||||||||||||||||
| 183 | # use Data::Dumper; | ||||||||||||||||||||||||||||
| 184 | # LogDebug( "vars=".Dumper($vars) ); | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | $vars->{evalperl} = ($content eq $codes{BADPAGE} ? 1 : 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | #LogDebug("<!-- $layout : $content -->"); | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | my $output; | |||||||||||||||||||||||||||
| 192 | 0 | eval { $output = $PARSER->parser($layout,$vars) }; | |||||||||||||||||||||||||||
| 193 | 0 | ▶ | if($@ || !$output) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or not $output
MC/DC0%0/2
$@ or not $output
$@
not $output
Truth table0%0/3
A or not(B)
A= $@B= not $output
| |||||||||||||||||||||||||||||
| 194 | 0 | LogDebug( "template error=$@" ); | |||||||||||||||||||||||||||
| 195 | 0 | $$output = $@; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | my ($ext) = $layout =~ m/\.(\w+)$/; | |||||||||||||||||||||||||||
| 199 | 0 | ▶ | $ext ||= 'html'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$ext ||= "html"
MC/DC0%0/1
$ext ||= "html"
$ext
Truth table0%0/2
A
A= $ext
| |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # split HTML and process etc | ||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if($ext =~ /htm/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if(defined $settings{parsehtml} && $settings{parsehtml}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $Labyrinth::Writer::settings{"parsehtml"} and $Labyrinth::Writer::settings{"parsehtml"}
MC/DC0%0/2
defined $Labyrinth::Writer::settings{"parsehtml"} and $Labyrinth::Writer::settings{"parsehtml"}
defined $Labyrinth::Writer::settings{"parsehtml"}
$Labyrinth::Writer::settings{"parsehtml"}
Truth table0%0/3
A and B
A= defined $Labyrinth::Writer::settings{"parsehtml"}B= $Labyrinth::Writer::settings{"parsehtml"}
| |||||||||||||||||||||||||||||
| 204 | 0 | my ($top,$body,$tail) = ($$output =~ m!^(.*?<body[^>]*>)(.*?)(</body>.*)$!si); | |||||||||||||||||||||||||||
| 205 | # LogDebug( "parsehtml=[$settings{parsehtml}]" ); | ||||||||||||||||||||||||||||
| 206 | # LogDebug( "html=[$html]" ); | ||||||||||||||||||||||||||||
| 207 | # LogDebug( "top=[$top]" ); | ||||||||||||||||||||||||||||
| 208 | # LogDebug( "tail=[$tail]" ); | ||||||||||||||||||||||||||||
| 209 | # LogDebug( "body=[$body]" ); | ||||||||||||||||||||||||||||
| 210 | 0 | my $html = $top . process_html($body,0,1) . $tail; | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if($settings{parsetest}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 0 | DumpToFile($settings{parsetest},"=== ORIGINAL ===",$$output,"=== PROCESSED ===",$html,"=== END ==="); | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | 0 | $output = \$html; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 0 | ▶ | $tvars{headers}{type} = $knowntypes{$ext} || do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$knowntypes{$ext} || do {
my $types = 'MIME::Types'->new;
my $mime = $types->mimeTypeOf($ext);
$mime->type or 'text/html'
}
MC/DC0%0/2
$knowntypes{$ext} || do {
my $types = 'MIME::Types'->new;
my $mime = $types->mimeTypeOf($ext);
$mime->type or 'text/html'
}
$knowntypes{$ext}
do {
my $types = 'MIME::Types'->new;
my $mime = $types->mimeTypeOf($ext);
$mime->type or 'text/html'
}
Truth table0%0/3
A || B
A= $knowntypes{$ext}B= do {
my $types = 'MIME::Types'->new;
my $mime = $types->mimeTypeOf($ext);
$mime->type or 'text/html'
}
| |||||||||||||||||||||||||||||
| 220 | 0 | my $types = MIME::Types->new; | |||||||||||||||||||||||||||
| 221 | 0 | my $mime = $types->mimeTypeOf($ext); | |||||||||||||||||||||||||||
| 222 | 0 | ▶ | $mime->type || 'text/html'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$mime->type || 'text/html'
MC/DC0%0/1
$mime->type || 'text/html'
$mime->type
Truth table0%0/2
A
A= $mime->type
| |||||||||||||||||||||||||||||
| 223 | }; | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 0 | $tvars{headers}{'charset'} = 'utf-8'; | |||||||||||||||||||||||||||
| 226 | 0 | ▶ | $tvars{headers}{'status'} = '404 Page Not Found' if($content eq $codes{BADPAGE} || $content eq $codes{BADCMD}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$content eq $codes{"BADPAGE"} or $content eq $codes{"BADCMD"}
MC/DC0%0/2
$content eq $codes{"BADPAGE"} or $content eq $codes{"BADCMD"}
$content eq $codes{"BADPAGE"}
$content eq $codes{"BADCMD"}
Truth table0%0/3
A or B
A= $content eq $codes{"BADPAGE"}B= $content eq $codes{"BADCMD"}
| |||||||||||||||||||||||||||||
| 227 | 0 | ▶ | $tvars{headers}{'cookie'} = $tvars{cookie} if($tvars{cookie}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | 0 | ▶ | $tvars{headers}{'attachment'} = basename($content) if($layout =~ /\.ics$/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | $published = 1; | |||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | return $RENDER->publish($tvars{headers}, $output); | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub PublishCode { | ||||||||||||||||||||||||||
|
Subroutine
PublishCode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 236 | 0 | $tvars{'content'} = $codes{$_[0]}; | |||||||||||||||||||||||||||
| 237 | 0 | return Publish(); | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 2 | ▶ | sub UnPublish { | ||||||||||||||||||||||||||
|
Subroutine
UnPublish: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 241 | 2 | $published = 0; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 0 | ▶ | sub Transform { | ||||||||||||||||||||||||||
|
Subroutine
Transform: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 245 | 0 | my ($template,$vars,$file,$binary) = @_; | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | my $path = $settings{'templates'}; | |||||||||||||||||||||||||||
| 248 | 0 | my $layout = "$path/$template"; | |||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 0 | ▶ | die "Missing template [$layout]\n" unless(-e $layout); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | Config() unless($PARSER && $RENDER); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$PARSER and $RENDER
MC/DC0%0/2
$PARSER and $RENDER
$PARSER
$RENDER
Truth table0%0/3
A and B
A= $PARSERB= $RENDER
| |||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if($file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | 0 | $PARSER->parse_to_file($layout,$vars,$file,$binary); | |||||||||||||||||||||||||||
| 256 | 0 | return; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | my $output = $PARSER->parser($layout,$vars); | |||||||||||||||||||||||||||
| 260 | 0 | return $$output; | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | =item Croak | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | A shorthand call to publish and record errors. | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | =cut | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 0 | ▶ | sub Croak { | ||||||||||||||||||||||||||
|
Subroutine
Croak: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 270 | 0 | my $errmess = join(" ",@_); | |||||||||||||||||||||||||||
| 271 | 0 | LogError($errmess); | |||||||||||||||||||||||||||
| 272 | 0 | print STDERR "$errmess\n"; | |||||||||||||||||||||||||||
| 273 | 0 | PublishCode('MESSAGE'); | |||||||||||||||||||||||||||
| 274 | 0 | exit; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 12 | 1; | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | __END__ | ||||||||||||||||||||||||||||