Instrumented/Control.pm

filter: Statementstmt 13.3% 17 / 127 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 19.2% 5 / 26 Podpod 100% 18 / 18 totaltotal 17.0% 40 / 234 CC 29 SCAR 31.5
CC
29
Cov
9%
to_text
90.0
args
30.0
eq
12.0
CRAP 23.4
« Instrumented/Form/Control.pm ↑ Summary Instrumented/Loop.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package
5 XHTML::Instrumented::Control;
6  
7 4 ▶use Params::Validate qw (validate ARRAYREF HASHREF );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new()
10 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
11 0 my $class = shift;
12 0 my %p = Params::Validate::validate( @_, {
13 src => 0,
14 text => 0,
15 args => 0,
16 replace => 0,
17 remove_tag => 0,
18 remove => 0,
19 id_count => 0,
20 }
21 );
22 0 delete $p{remove};
23 0 bless({args => {}, @_}, $class);
24 }
25  
26 sub remove_self()
27 0 ▶{
Subroutine remove_self: not called CC=2 SCAR=17.9
Pod documented
28 0 my $self = shift;
29  
30 0 ▶ $self->{remove_tag} || 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"remove_tag"} or 0 0 0 0
31 }
32  
33 sub has_name
34 0 ▶{
Subroutine has_name: not called CC=1 SCAR=6.9
Pod documented
35 0 my $self = shift;
36  
37 0 exists $self->{args}{name};
38 }
39  
40 sub name
41 0 ▶{
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
42 0 my $self = shift;
43  
44 0 $self->{args}{name};
45 }
46  
47 sub remove()
48 0 ▶{
Subroutine remove: not called CC=1 SCAR=6.9
Pod documented
49 0 my $self = shift;
50  
51 0 $self->{remove};
52 }
53  
54 sub args
55 0 ▶{
Subroutine args: not called CC=5 SCAR=34.0
Pod documented
56 0 my $self = shift;
57 0 my %args = @_;
58 0 ▶ my %hash = ( %args, %{$self->{args} || {}} );
Condition0%0/2
$self->{'args'} || {}
l!l
00
MC/DC0%0/1
$self->{'args'} || {}
$self->{'args'}
Truth table0%0/2
A
A= $self->{'args'}
Aresult
11
00
59  
60 0 ▶ if (my $idc = $self->id_count) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $idc = $self->id_count) 0 0 0
61  
62 0 ▶ if ($hash{for}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash{"for"}) 0 0 0
63 0 $hash{for} .= '.' . $idc;
64 }
65 0 ▶ if ($hash{id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash{"id"}) 0 0 0
66 0 $hash{id} .= '.' . $idc;
67 }
68 }
69  
70 0 %hash;
71 }
72  
73 sub eq
74 0 ▶{
Subroutine eq: not called CC=3 SCAR=24.8
Pod documented
75 0 my $self = shift;
76 0 my $ret = 0;
77
78 0 for my $item (@_) {
79 0 ▶ $ret = 1 if $item eq $self->{text};
Branch: 1 branch
BranchTrueFalseTotal
if $item eq $self->{"text"} 0 0 0
80 }
81 0 return $ret;
82 }
83  
84 sub if
85 0 ▶{
Subroutine if: not called CC=3 SCAR=24.8
Pod documented
86 0 my $self = shift;
87  
88 0 ▶ !!($self->{text} || keys %{$self->{args} || {}});
Condition0%0/5
$self->{'text'} || keys %{$self->{'args'} or {};}
l!l&&r!l&&!r
000
$self->{'args'} || {}
l!l
00
MC/DC0%0/2
$self->{'text'} || keys %{$self->{'args'} or {};}
$self->{'text'} keys %{$self->{'args'} or {};}
MC/DC0%0/1
$self->{'args'} || {}
$self->{'args'}
Truth table0%0/3
A || B
A= $self->{'text'}B= keys %{$self->{'args'} or {};}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $self->{'args'}
Aresult
11
00
89 }
90  
91 sub _fixup
92 0 ▶{
Subroutine _fixup: not called CC=3 SCAR=24.8
93 0 my @ret;
94 0 for my $data (@_) {
95 0 ▶ next unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 0 0
96 0 $data =~ s/&/&/g;
97 0 my $x = $data;
98 # $data = Encode::decode_utf8( $x );
99 0 push @ret, $data;
100 }
101 0 @ret;
102 }
103  
104 #####################
105 #
106 #
107 #
108 sub exp_args
109 0 ▶{
Subroutine exp_args: not called CC=3 SCAR=24.8
Pod documented
110 0 my $self = shift;
111  
112 0 ▶ die ref($_[0]), caller if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
113  
114 0 my %args = $self->args(@_);
115  
116 0 my $nargs = { %args };
117  
118 0 ▶ my $ret = join('', map({ defined($nargs->{$_}) ? qq( $_="$nargs->{$_}") : ''; } sort keys(%args)));
Branch: 1 branch
BranchTrueFalseTotal
defined $nargs->{$_} ? : 0 0 0
119 0 $ret =~ s/&/&/g;
120 0 return $ret;
121 }
122  
123 4 our %special_tag = ( a => 1, div => 1, textarea => 1 );
124  
125 sub expand_content
126 0 ▶{
Subroutine expand_content: not called CC=3 SCAR=24.8
Pod documented
127 0 my $self = shift;
128  
129 0 ▶ if ($self->{remove}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"remove"}) 0 0 0
130 0 return '';
131 }
132 0 ▶ if (defined $self->{text}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'text'}) { } 0 0 0
133 0 $self->{text};
134 } else {
135 0 @_;
136 }
137 }
138  
139 sub children
140 0 ▶{
Subroutine children: not called CC=3 SCAR=24.8
Pod documented
141 0 my $self = shift;
142 0 my %p = validate(@_, {
143 children => ARRAYREF,
144 context => { isa => 'XHTML::Instrumented::Context' },
145 });
146 0 my $context = $p{context};
147 0 my @ret;
148  
149 0 for my $element (@{$p{children}}) {
150 0 ▶ if (UNIVERSAL::isa($element, 'XHTML::Instrumented::Entry')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($element, 'XHTML::Instrumented::Entry')) { } 0 0 0
151 0 push(@ret, $element->expand(context => $context));
152 } else {
153 0 push(@ret, $element);
154 }
155 }
156 0 return @ret;
157 }
158  
159 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
160  
161 sub to_text
162 0 ▶{
Subroutine to_text: not called CC=9 SCAR=45.0
Pod documented
163 0 my $self = shift;
164 0 my %p = validate(@_, {
165 tag => 1,
166 children => ARRAYREF,
167 args => HASHREF,
168 flags => HASHREF,
169 context => { isa => 'XHTML::Instrumented::Context' },
170 special => 0,
171 });
172  
173 0 my $flags = $p{flags};
174  
175 0 ▶ if ($p{special}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"special"}) 0 0 0
176 0 return @{$p{special}};
177 }
178  
179 0 my $args = { %{$p{args}} };
180  
181 0 my $test = !!$p{flags}->{if};
182 0 my @children;
183 0 ▶ if ($p{flags}->{eq}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"flags"}{"eq"}) 0 0 0
184 0 $test++;
185 }
186  
187 0 ▶ if ($test) { # This is only a test of the Entry
Branch: 1 branch
BranchTrueFalseTotal
if ($test) { } 0 0 0
188 0 @children = @{$p{children}};
189 } else {
190 0 @children = $self->expand_content(@{$p{children}});
191 }
192  
193 0 @children = $self->children(context => $p{context}, children => \@children);
194  
195 0 ▶ if ($self->remove) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->remove) 0 0 0
196 0 return ();
197 }
198 0 ▶ if ($self->remove_self || $flags->{rs}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->remove_self or $flags->{"rs"}) 0 0 0
Condition0%0/3
$self->remove_self or $flags->{"rs"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->remove_self or $flags->{"rs"}
$self->remove_self $flags->{"rs"}
Truth table0%0/3
A or B
A= $self->remove_selfB= $flags->{"rs"}
ABresult
1X1
011
000
199 return (
200 0 @children,
201 );
202 }
203  
204 0 my $tag = $p{tag};
205 #die Dumper \@children if $p{tag} eq 'input' and $p{args}{name} eq 'test2';
206  
207 0 my @ret;
208 0 ▶ if ($special_tag{$tag} || @children) {
Branch: 1 branch
BranchTrueFalseTotal
if ($XHTML::Instrumented::Control::special_tag{$tag} or @children) { } 0 0 0
Condition0%0/3
$XHTML::Instrumented::Control::special_tag{$tag} or @children
l!l&&r!l&&!r
000
MC/DC0%0/2
$XHTML::Instrumented::Control::special_tag{$tag} or @children
$XHTML::Instrumented::Control::special_tag{$tag} @children
Truth table0%0/3
A or B
A= $XHTML::Instrumented::Control::special_tag{$tag}B= @children
ABresult
1X1
011
000
209 0 @ret = ('<' . $tag . $self->exp_args(%$args) . '>',
210 @children,
211 '</' . $tag . '>');
212 } else {
213 0 @ret = ('<' . $tag . $self->exp_args(%$args) . '/>');
214 }
215 0 return @ret;
216 }
217  
218 sub set_id_count
219 0 ▶{
Subroutine set_id_count: not called CC=1 SCAR=6.9
Pod documented
220 0 my $self = shift;
221 0 my $data = shift;
222  
223 0 $self->{id_count} = $data;
224 }
225  
226 sub id_count
227 0 ▶{
Subroutine id_count: not called CC=2 SCAR=17.9
Pod documented
228 0 my $self = shift;
229 0 my $ret;
230 0 ▶ if ($self->in_loop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_loop) 0 0 0
231 0 $ret = $self->{id_count};
232 }
233 0 return $ret;
234 }
235  
236 sub in_loop
237 0 ▶{
Subroutine in_loop: not called CC=1 SCAR=6.9
Pod documented
238 0 my $self = shift;
239  
240 0 defined $self->{id_count};
241 }
242  
243 sub form
244 0 ▶{
Subroutine form: not called CC=1 SCAR=6.9
Pod documented
245 0 undef;
246 }
247  
248 sub required
249 0 ▶{
Subroutine required: not called CC=1 SCAR=6.9
Pod documented
250 0 shift;
251  
252 0 @_;
253 }
254  
255 sub set_tag
256 0 ▶{
Subroutine set_tag: not called CC=3 SCAR=24.8
Pod documented
257 0 my $self = shift;
258 0 my %p = @_;
259  
260 0 $self->{tag} = $p{tag};
261  
262 $self->{_args} = {
263 0 ▶ %{$p{args} || {}},
Condition0%0/2
$p{'args'} || {}
l!l
00
MC/DC0%0/1
$p{'args'} || {}
$p{'args'}
Truth table0%0/2
A
A= $p{'args'}
Aresult
11
00
264 0 ▶ %{$self->{args} || {}}
Condition0%0/2
$self->{'args'} || {}
l!l
00
MC/DC0%0/1
$self->{'args'} || {}
$self->{'args'}
Truth table0%0/2
A
A= $self->{'args'}
Aresult
11
00
265 };
266 }
267  
268 package
269 XHTML::Instrumented::Control::Dummy;
270  
271 4 ▶use base 'XHTML::Instrumented::Control';
Subroutine BEGIN: called CC=1 SCAR=0.0
272  
273 sub if
274 0 ▶{
Subroutine if: not called CC=1 SCAR=6.9
275 0 0;
276 }
277  
278 sub is_dummy
279 0 ▶{
Subroutine is_dummy: not called CC=1 SCAR=6.9
280 0 1;
281 }
282  
283 4 1;
284 __END__
« Instrumented/Form/Control.pm ↑ Summary Instrumented/Loop.pm »