CGI/Builder.pm

filter: Statementstmt 95.4% 146 / 153 Branchbran 72.5% 45 / 62 Conditioncond 54.7% 23 / 42 MC/DCmcdc 28.0% 7 / 25 Subroutinesub 83.3% 35 / 42 Podpod 100% 11 / 11 totaltotal 79.7% 267 / 335 CC 49 SCAR 16.6
CC
49
Cov
83%
switch_to
15.2
process
11.1
import
6.1
CRAP 5.3
↑ Summary CGI/Builder/Conf.pm »
1 package CGI::Builder ;
2 2 $VERSION = 1.36 ;
3 3 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # This file uses the "Perlish" coding style
6 # please read http://perl.4pro.net/perlish_coding_style.html
7  
8 ; use 5.006_001
9 3 ▶; use Carp
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶; $Carp::Internal{+__PACKAGE__}++
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ; $Carp::Internal{__PACKAGE__.'::_'}++
12 ; use IO::Util
13 3 ▶; use Class::Util
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶; use warnings::register
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶; my @phase
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ; BEGIN
18 3 ▶ { @phase = qw | CB_INIT
Subroutine BEGIN: called CC=2 SCAR=7.0
19 GET_PAGE
20 PRE_PROCESS
21 SWITCH_HANDLER
22 PRE_PAGE
23 PAGE_HANDLER
24 FIXUP
25 RESPONSE
26 REDIR
27 CLEANUP
28 |
29 3 ▶ ; no strict 'refs'
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 ; foreach my $i (0..$#phase)
31 0 ▶ { *{$phase[$i]} = sub(){$i}
Subroutine __ANON__: not called CC=1 SCAR=1.2
32 20 }
33 }
34
35 ; sub phase
36 0 ▶ { $phase[$_[1]||$_[0]->PHASE]
Subroutine phase: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$_[1] || $_[0]->PHASE
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[1] || $_[0]->PHASE
$_[1] $_[0]->PHASE
Truth table0%0/3
A || B
A= $_[1]B= $_[0]->PHASE
ABresult
1X1
011
000
37 }
38  
39 ; sub capture
40 11 ▶ { my ($s, $h, @args) = @_
Subroutine capture: called CC=1 SCAR=0.0
Pod documented
41 11 ▶ ; IO::Util::capture{ $s->$h(@args) }
Subroutine __ANON__: called CC=1 SCAR=0.0
42 11 }
43  
44 ; sub import
45 11 ▶ { my ($cbb, $CB, @ext) = (scalar caller, @_)
Subroutine import: called CC=6 SCAR=18.0
46 11 ; Class::Util::load for @ext
47 2 ▶ ; no strict 'refs'
Subroutine BEGIN: called CC=1 SCAR=0.0
48 2 ; foreach my $c (reverse @_)
49 15 ▶ { push @{$cbb.'::ISA'}, $c unless $cbb->isa($c)
Branch: 1 branch
BranchTrueFalseTotal
unless $cbb->isa($c) 15 0 15
50 }
51 11 ▶ ; $cbb->isa('Apache::CGI::Builder') && $Apache::CGI::Builder::usage
Branch: 1 branch
BranchTrueFalseTotal
$cbb->isa("Apache::CGI::Builder") and $Apache::CGI::Builder::usage and carp($Apache::CGI::Builder::usage) 0 11 11
Condition33%1/3
$cbb->isa("Apache::CGI::Builder") and $Apache::CGI::Builder::usage
!ll&&!rl&&r
1100
MC/DC0%0/2
$cbb->isa("Apache::CGI::Builder") and $Apache::CGI::Builder::usage
$cbb->isa("Apache::CGI::Builder") $Apache::CGI::Builder::usage
Truth table33%1/3
A and B
A= $cbb->isa("Apache::CGI::Builder")B= $Apache::CGI::Builder::usage
ABresult
0X0
100
111
52 && carp $Apache::CGI::Builder::usage
53 ; my $sub = sub
54 25 ▶ { +{ map
Subroutine __ANON__: called CC=3 SCAR=11.0
55 25 { my $h = $_
56 ; my @op = grep
57 125 ▶ { defined &{$_.'::OH_'.$h}
Branch: 1 branch
BranchTrueFalseTotal
$h =~ /up$/ ? : 50 75 125
58 }
59 $h =~ /up$/ # ;-)
60 ? reverse ($CB, @ext, $cbb)
61 : ($CB, @ext, $cbb)
62 125 ▶ ; @op ? ($h => \@op) : ()
Branch: 1 branch
BranchTrueFalseTotal
@op ? : 15 110 125
63 }
64 qw| init pre_process pre_page fixup cleanup |
65 }
66 }
67 11 ; eval qq
68 2 ▶ ! package $cbb
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
69 ; use Class::groups
70 { name => 'overrun_handler_map'
71 , default => \$sub
72 }
73 ; *import = sub{} unless defined &import
74 !
75 }
76  
77 2 ; my $exec = \&CGI::Builder::_::exec
78
79 ; sub CGI::Builder::_::exec
80 65 ▶ { my $s = shift
Subroutine exec: called CC=1 SCAR=0.0
81 65 ; my $h = shift
82 65 ▶ ; Class::Util::gather { $s->$_(@_) } '&OH_'.$h
Subroutine __ANON__: called CC=1 SCAR=0.0
83 , $s->overrun_handler_map($h)
84 }
85  
86 ; use Class::constr
87 2 ▶ ( { init => \&CGI::Builder::_::init
Subroutine BEGIN: called CC=1 SCAR=0.0
88 , no_strict => 1
89 }
90 )
91
92 2 ; sub CGI::Builder::_::init
93 16 ▶ { my $s = shift
Subroutine init: called CC=1 SCAR=0.2
94 0 ▶ ; local $SIG{__DIE__} = sub{$s->die_handler(@_)}
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 16 ; $s->$exec('init', @_)
96 }
97
98 2 ▶; use Class::groups qw | overrun_handler_map
Subroutine BEGIN: called CC=1 SCAR=0.0
99 switch_handler_map
100 page_handler_map
101 |
102 2 ▶; use Object::groups qw | param
Subroutine BEGIN: called CC=1 SCAR=0.0
103 header
104 page_error
105 |
106 2 ; use Class::props
107 2 ▶ ( { name => 'no_page_content_status'
Subroutine BEGIN: called CC=1 SCAR=0.0
108 , default => '204 No Content'
109 }
110 )
111
112 2 ; use Object::props
113 2 ▶ ( { name => 'PHASE'
Subroutine BEGIN: called CC=1 SCAR=0.5
114 , default => CB_INIT
115 , allowed => qr/^CGI::Builder/ # only settable from CBF
116 }
117 , { name => 'cgi_page_param'
118 , default => 'p'
119 }
120 , { name => 'cgi'
121 6 ▶ , default => sub{ shift()->cgi_new }
Subroutine __ANON__: called CC=1 SCAR=0.0
122 }
123 , { name => 'page_name'
124 , default => 'index'
125 }
126 , { name => 'requested_page'
127 , allowed => qw/^CGI::Builder::process$/
128 }
129 , { name => 'page_path'
130 , default => './tm'
131 , no_strict => 1 # doesn't croak if ./tm is not a directory
132 0 ▶ , validation => sub { -d or croak "'$_' is not a directory, died" }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
-d $_ or croak("'${_}' is not a directory, died") 0 0 0
133 }
134 2 , { name => [ qw| page_content page_suffix | ]
135 , default => ''
136 }
137 , 'dont_send_header'
138 )
139  
140 2 ; our $AUTOLOAD
141 8 ▶; sub AUTOLOAD : lvalue # param AUTOLOADING
Subroutine AUTOLOAD: called CC=4 SCAR=14.9
142 8 { (my $n = $AUTOLOAD) =~ s/.*://
143 8 ▶ ; carp qq(Use of unprefixed autoloaded parameter "$n". )
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() and not $n =~ /^(?:my)?_/ 0 8 8
Condition33%1/3
warnings::enabled() and not $n =~ /^(?:my)?_/
!ll&&!rl&&r
080
MC/DC0%0/2
warnings::enabled() and not $n =~ /^(?:my)?_/
warnings::enabled() not $n =~ /^(?:my)?_/
Truth table33%1/3
A and not(B)
A= warnings::enabled()B= not $n =~ /^(?:my)?_/
ABresult
0X0
100
111
144 . qq(Autoloaded parameters should start with 'my_' or '_')
145 if warnings::enabled && $n !~ /^(?:my)?_/
146 ; @_ == 2
147 ? ( $_[0]{param}{$n} = $_[1] )
148 8 ▶ : $_[0]{param}{$n}
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 5 3 8
149 }
150
151 0 ▶; sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
152  
153 ; sub cgi_new
154 6 ▶ { require CGI
Subroutine cgi_new: called CC=1 SCAR=0.0
Pod documented
155 6 ; CGI->new
156 }
157  
158 ; sub process
159 11 ▶ { my ($s, $p) = @_
Subroutine process: called CC=11 SCAR=24.1
Pod documented
160 4 ▶ ; local $SIG{__DIE__} = sub{$s->die_handler(@_)}
Subroutine __ANON__: called CC=1 SCAR=0.0
161 11 ; $s->PHASE(GET_PAGE)
162 11 ▶ ; if ( defined $p && length $p )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p and length $p) { } 3 8 11
Condition66%2/3
defined $p and length $p
!ll&&!rl&&r
803
MC/DC50%1/2
defined $p and length $p
defined $p length $p
Truth table66%2/3
A and B
A= defined $pB= length $p
ABresult
0X0
100
111
163 3 { $s->requested_page($p)
164 3 ; $s->page_name($p)
165 }
166 else
167 8 { $s->requested_page( $s->get_page_name() )
168 }
169 11 ▶ ; if ($s->PHASE < PRE_PROCESS)
Branch: 1 branch
BranchTrueFalseTotal
if ($s->PHASE < 2) 11 0 11
170 11 { $s->PHASE(PRE_PROCESS)
171 11 ; $s->$exec('pre_process')
172 }
173 11 ▶ ; if ($s->PHASE < SWITCH_HANDLER)
Branch: 1 branch
BranchTrueFalseTotal
if ($s->PHASE < 3) 9 2 11
174 9 { $s->switch_to( $s->page_name )
175 }
176 11 ▶ ; if ($s->PHASE < FIXUP)
Branch: 1 branch
BranchTrueFalseTotal
if ($s->PHASE < 6) 10 1 11
177 10 { $s->PHASE(FIXUP)
178 10 ; $s->$exec('fixup')
179 }
180 11 ▶ ; if ($s->PHASE < RESPONSE)
Branch: 1 branch
BranchTrueFalseTotal
if ($s->PHASE < 7) 10 1 11
181 10 { $s->PHASE(RESPONSE)
182 10 ; my $has_content = $s->page_content_check
183 ; $s->header( -status => $s->no_page_content_status )
184 unless $has_content || defined $s->header->{-status}
185 10 ▶ ; $s->send_header() unless $s->dont_send_header
Branch: 2 branches
BranchTrueFalseTotal
unless $has_content or defined $s->header->{"-status"} 3 7 10
unless $s->dont_send_header 10 0 10
Condition66%2/3
$has_content or defined $s->header->{"-status"}
l!l&&r!l&&!r
703
MC/DC50%1/2
$has_content or defined $s->header->{"-status"}
$has_content defined $s->header->{"-status"}
Truth table66%2/3
A or B
A= $has_contentB= defined $s->header->{"-status"}
ABresult
1X1
011
000
186 10 ▶ ; $s->send_content() if $has_content
Branch: 1 branch
BranchTrueFalseTotal
if $has_content 7 3 10
187 }
188 11 ; $s->PHASE(CLEANUP)
189 11 ; $s->$exec('cleanup') # done however
190 }
191  
192 ; sub switch_to
193 15 ▶ { my ($s, $p) = splice @_, 0, 2
Subroutine switch_to: called CC=14 SCAR=27.2
Pod documented
194 15 ▶ ; $s->PHASE < PRE_PROCESS && croak 'Too early to call switch_to(), died'
Branch: 1 branch
BranchTrueFalseTotal
$s->PHASE < 2 and croak("Too early to call switch_to(), died") 0 15 15
195 15 ▶ ; $s->PHASE > FIXUP && croak 'Too late to call switch_to(), died'
Branch: 1 branch
BranchTrueFalseTotal
$s->PHASE > 6 and croak("Too late to call switch_to(), died") 0 15 15
196 15 ▶ ; defined $p && length $p || croak 'No page_name name passed, died'
Branch: 1 branch
BranchTrueFalseTotal
defined $p and length $p or croak("No page_name name passed, died") 15 0 15
Condition33%1/3
defined $p and length $p
!ll&&!rl&&r
0015
MC/DC0%0/2
defined $p and length $p
defined $p length $p
Truth table33%1/3
A and B
A= defined $pB= length $p
ABresult
0X0
100
111
197 15 ; $s->page_name($p)
198 15 ; $s->PHASE(SWITCH_HANDLER)
199 15 ; my $shm = $s->switch_handler_map
200 15 ▶ ; my $SH = $$shm{$p} || $s->can("SH_$p")
Condition66%2/3
$shm->{$p} || $s->can("SH_$p")
l!l&&r!l&&!r
0312
MC/DC50%1/2
$shm->{$p} || $s->can("SH_$p")
$shm->{$p} $s->can("SH_$p")
Truth table66%2/3
A || B
A= $shm->{$p}B= $s->can("SH_$p")
ABresult
1X1
011
000
201 15 ▶ ; $s->$SH(@_) if $SH
Branch: 1 branch
BranchTrueFalseTotal
if $SH 3 12 15
202 15 ▶ ; if ($s->PHASE < PRE_PAGE)
Branch: 1 branch
BranchTrueFalseTotal
if ($s->PHASE < 4) 13 2 15
203 13 { $s->PHASE(PRE_PAGE)
204 13 ; $s->$exec('pre_page')
205 }
206 15 ▶ ; if ($s->PHASE < PAGE_HANDLER)
Branch: 1 branch
BranchTrueFalseTotal
if ($s->PHASE < 5) 13 2 15
207 13 { $s->PHASE(PAGE_HANDLER)
208 13 ; my $phm = $s->page_handler_map
209 ; my $PH = $$phm{$p} || $s->can("PH_$p")
210 || ! $s->page_content_check
211 13 ▶ && ($$phm{AUTOLOAD} || $s->can('PH_AUTOLOAD'))
Condition75%9/12
$phm->{$p} || $s->can("PH_$p") || !$s->page_content_check && ($phm->{'AUTOLOAD'} || $s->can('PH_AUTOLOAD'))
l!l&&r!l&&!r
1111
$phm->{$p} or $s->can("PH_$p")
l!l&&r!l&&!r
0112
not $s->page_content_check and $phm->{"AUTOLOAD"} || $s->can("PH_AUTOLOAD")
!ll&&!rl&&r
011
$phm->{"AUTOLOAD"} or $s->can("PH_AUTOLOAD")
l!l&&r!l&&!r
011
MC/DC40%2/5
$phm->{$p} || $s->can("PH_$p") || !$s->page_content_check && ($phm->{'AUTOLOAD'} || $s->can('PH_AUTOLOAD'))
$phm->{$p} $s->can("PH_$p") not $s->page_content_check $phm->{"AUTOLOAD"} $s->can("PH_AUTOLOAD")
Truth table50%3/6
A or B || not(C) and D or E
A= $phm->{$p}B= $s->can("PH_$p")C= not $s->page_content_checkD= $phm->{"AUTOLOAD"}E= $s->can("PH_AUTOLOAD")
ABCDEresult
1XXXX1
01XXX1
0011X1
001011
000XX0
001000
212 13 ▶ ; $s->$PH(@_) if $PH
Branch: 1 branch
BranchTrueFalseTotal
if $PH 12 1 13
213 }
214 }
215  
216 ; sub get_page_name
217 8 ▶ { my $s = shift
Subroutine get_page_name: called CC=3 SCAR=11.0
Pod documented
218 8 ; my $p = $s->cgi->param($s->cgi_page_param)
219 8 ▶ ; $s->page_name($p) if defined($p) && length($p)
Branch: 1 branch
BranchTrueFalseTotal
if defined $p and length $p 5 3 8
Condition66%2/3
defined $p and length $p
!ll&&!rl&&r
305
MC/DC50%1/2
defined $p and length $p
defined $p length $p
Truth table66%2/3
A and B
A= defined $pB= length $p
ABresult
0X0
100
111
220 }
221  
222 ; sub page_content_check
223 12 ▶ { length $_[0]->page_content
Subroutine page_content_check: called CC=1 SCAR=0.0
Pod documented
224 }
225
226 ; sub send_header
227 10 ▶ { print $_[0]->cgi->header( %{$_[0]->header} )
Subroutine send_header: called CC=1 SCAR=0.0
Pod documented
228 }
229  
230 ; sub send_content
231 7 ▶ { my $pc = $_[0]->page_content
Subroutine send_content: called CC=4 SCAR=17.1
Pod documented
232 7 ▶ ; if ( ref $pc eq 'CODE' )
Branch: 3 branches
BranchTrueFalseTotal
if (ref $pc eq 'CODE') { } 0 7 7
elsif (ref $pc eq 'SCALAR') { } 0 7 7
elsif (not ref $pc) { } 7 0 7
233 0 { $_[0]->$pc
234 }
235 elsif ( ref $pc eq 'SCALAR' )
236 0 { print $$pc
237 }
238 elsif ( not ref $pc )
239 7 { print $pc
240 }
241 }
242  
243 ; sub redirect
244 1 ▶ { my ($s, $url) = @_
Subroutine redirect: called CC=5 SCAR=17.3
Pod documented
245 1 ▶ ; $s->PHASE < GET_PAGE && croak 'Too early to call redirect(), died'
Branch: 1 branch
BranchTrueFalseTotal
$s->PHASE < 1 and croak("Too early to call redirect(), died") 0 1 1
246 1 ▶ ; $s->PHASE > RESPONSE && croak 'Too late to call redirect(), died'
Branch: 1 branch
BranchTrueFalseTotal
$s->PHASE > 7 and croak("Too late to call redirect(), died") 0 1 1
247 1 ▶ ; defined $url && length $url || croak 'No URL passed, died'
Branch: 1 branch
BranchTrueFalseTotal
defined $url and length $url or croak("No URL passed, died") 1 0 1
Condition33%1/3
defined $url and length $url
!ll&&!rl&&r
001
MC/DC0%0/2
defined $url and length $url
defined $url length $url
Truth table33%1/3
A and B
A= defined $urlB= length $url
ABresult
0X0
100
111
248 1 ; $s->PHASE(REDIR)
249 1 ; $s->header(-url => $url)
250 1 ; print $s->cgi->redirect( %{$s->header} )
251 }
252  
253 ; sub die_handler
254 4 ▶ { my ( $s, $msg ) = @_
Subroutine die_handler: called CC=4 SCAR=14.6
Pod documented
255 4 ▶ ; for ( my $i = 1
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = (caller $i)[3]) 8 0 8
256 ; my $sub = (caller($i))[3]
257 ; $i++
258 )
259 8 ▶ { die $msg if $sub eq '(eval)' && (caller($i+1))[3]
Branch: 1 branch
BranchTrueFalseTotal
if $sub eq "(eval)" and (caller $i + 1)[3] 4 4 8
Condition66%2/3
$sub eq "(eval)" and (caller $i + 1)[3]
!ll&&!rl&&r
404
MC/DC50%1/2
$sub eq "(eval)" and (caller $i + 1)[3]
$sub eq "(eval)" (caller $i + 1)[3]
Truth table66%2/3
A and B
A= $sub eq "(eval)"B= (caller $i + 1)[3]
ABresult
0X0
100
111
260 }
261 0 ; die sprintf 'Fatal error in phase %s for page "%s": %s'
262 , $s->phase
263 , $s->page_name
264 , $msg
265 }
266
267 2 ; 1
268  
269 __END__
↑ Summary CGI/Builder/Conf.pm »