blib/lib/Rose/HTML/Object/MakeMethods/Generic.pm

filter: Statementstmt 65.8% 77 / 117 Branchbran 57.5% 46 / 80 Conditioncond 48.7% 20 / 41 MC/DCmcdc 21.7% 5 / 23 Subroutinesub 83.3% 15 / 18 Podpod 0.0% 0 / 1 totaltotal 58.2% 163 / 280 CC 58 SCAR 30.3
CC
58
Cov
60%
__ANON__
72.0
array
36.2
__ANON__
22.4
CRAP 20.7
« blib/lib/Rose/HTML/Object/Message/Localizer.pm ↑ Summary blib/lib/Rose/HTML/Form.pm »
1 package Rose::HTML::Object::MakeMethods::Generic;
2  
3 43 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 43 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 43 ▶use base 'Rose::Object::MakeMethods';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 43 our $VERSION = '0.606';
10  
11 sub array
12 500 ▶{
Subroutine array: called CC=16 SCAR=35.9
Pod undocumented
13 500 my($class, $name, $args) = @_;
14  
15 500 require Rose::HTML::Text;
16  
17 500 my %methods;
18  
19 500 ▶ my $key = $args->{'hash_key'} || $name;
Condition66%2/3
$args->{'hash_key'} || $name
l!l&&r!l&&!r
431690
MC/DC0%0/2
$args->{'hash_key'} || $name
$args->{'hash_key'} $name
Truth table66%2/3
A || B
A= $args->{'hash_key'}B= $name
ABresult
1X1
011
000
20 500 ▶ my $interface = $args->{'interface'} || 'get_set';
Condition100%2/2
$args->{'interface'} || 'get_set'
l!l
47426
MC/DC100%1/1
$args->{'interface'} || 'get_set'
$args->{'interface'}
Truth table100%2/2
A
A= $args->{'interface'}
Aresult
11
00
21  
22 #unless($class->can('parent'))
23 #{
24 # $methods{'parent'} = sub
25 # {
26 # my($self) = shift;
27 # return Scalar::Util::weaken($self->{'parent'} = shift) if(@_);
28 # return $self->{'parent'};
29 # };
30 #}
31  
32 500 ▶ if($interface eq 'get_set_init')
Branch: 12 branches
BranchTrueFalseTotal
if ($interface eq 'get_set_init') { } 0 500 500
elsif ($interface eq 'get_set_inited') { } 43 457 500
elsif ($interface eq 'get_set_item') { } 0 457 457
elsif ($interface eq 'get_item') { } 43 414 457
elsif ($interface eq 'delete_item') { } 43 371 414
elsif ($interface eq 'unshift') { } 69 302 371
elsif ($interface eq 'shift') { } 69 233 302
elsif ($interface eq 'clear') { } 69 164 233
elsif ($interface eq 'reset') { } 0 164 164
elsif ($interface =~ /^(?:push|add)$/) { } 69 95 164
elsif ($interface eq 'pop') { } 69 26 95
elsif ($interface eq 'get_set') { } 26 0 26
33 {
34 0 ▶ my $init_method = $args->{'init_method'} || "init_$name";
Condition0%0/2
$args->{'init_method'} || "init_$name"
l!l
00
MC/DC0%0/1
$args->{'init_method'} || "init_$name"
$args->{'init_method'}
Truth table0%0/2
A
A= $args->{'init_method'}
Aresult
11
00
35  
36 $methods{$name} = sub
37 0 ▶ {
Subroutine __ANON__: not called CC=8 SCAR=42.8
38 0 my($self) = shift;
39  
40 # If called with no arguments, return array contents
41 0 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
42 {
43 0 ▶ $self->{$key} = $self->$init_method() unless(defined $self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 0 0 0
44 0 ▶ return wantarray ? @{$self->{$key} ||= []} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
Condition0%0/2
$self->{$key} ||= []
l!l
00
MC/DC0%0/1
$self->{$key} ||= []
$self->{$key}
Truth table0%0/2
A
A= $self->{$key}
Aresult
11
00
45 }
46  
47 # If called with a array ref, set new value
48 0 ▶ if(@_ == 1 && ref $_[0] eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
49 {
50 0 $self->{$key} = [ map { _coerce_html_object($self, $_) } @{$_[0]} ];
51 }
52 else
53 {
54 0 $self->{$key} = [ map { _coerce_html_object($self, $_) } @_ ];
55 }
56  
57 0 ▶ return wantarray ? @{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
58 }
59 0 }
60 elsif($interface eq 'get_set_inited')
61 {
62 $methods{$name} = sub
63 2630 ▶ {
Subroutine __ANON__: called CC=7 SCAR=19.5
64 2630 my($self) = shift;
65  
66 # If called with no arguments, return array contents
67 2630 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 2180 450 2630
68 {
69 2180 ▶ $self->{$key} = [] unless(defined $self->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 221 1959 2180
70 2180 ▶ return wantarray ? @{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 902 1278 2180
71 }
72  
73 # If called with a array ref, set new value
74 450 ▶ if(@_ == 1 && ref $_[0] eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 8 442 450
Condition100%3/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
14418
MC/DC100%2/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
75 {
76 8 $self->{$key} = [ map { _coerce_html_object($self, $_) } @{$_[0]} ];
77 }
78 else
79 {
80 442 $self->{$key} = [ map { _coerce_html_object($self, $_) } @_ ];
81 }
82  
83 0 ▶ return wantarray ? @{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 450 450
84 }
85 43 }
86 elsif($interface eq 'get_set_item')
87 {
88 $methods{$name} = sub
89 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
90 0 my($self) = shift;
91  
92 0 ▶ Carp::croak "Missing array index" unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
93  
94 0 ▶ if(@_ == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 0 0 0
95 {
96 0 return $self->{$key}[$_[0]] = _coerce_html_object($self, $_[1]);
97 }
98 else
99 {
100 0 return $self->{$key}[$_[0]]
101 }
102 }
103 0 }
104 elsif($interface eq 'get_item')
105 {
106 $methods{$name} = sub
107 7 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.1
108 7 my($self) = shift;
109 7 ▶ Carp::croak "Missing array index" unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 7 7
110 7 return $self->{$key}[$_[0]];
111 }
112 43 }
113 elsif($interface eq 'delete_item')
114 {
115 $methods{$name} = sub
116 3 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.2
117 3 my($self) = shift;
118 3 ▶ Carp::croak "Missing array index" unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 3 3
119 43 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
120 3 ▶ splice(@{$self->{$key} || []}, $_[0], 1);
Condition50%1/2
$self->{$key} || []
l!l
30
MC/DC0%0/1
$self->{$key} || []
$self->{$key}
Truth table50%1/2
A
A= $self->{$key}
Aresult
11
00
121 }
122 43 }
123 elsif($interface eq 'unshift')
124 {
125 $methods{$name} = sub
126 3 ▶ {
Subroutine __ANON__: called CC=5 SCAR=17.8
127 3 my($self) = shift;
128 3 ▶ Carp::croak "Missing value(s) to add" unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 3 3
129 0 ▶ unshift(@{$self->{$key} ||= []}, map { _coerce_html_object($self, $_) } (@_ == 1 && ref $_[0] eq 'ARRAY') ? @{$_[0]} : @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'ARRAY' ? : 0 3 3
Condition60%3/5
$self->{$key} ||= []
l!l
12
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
030
MC/DC100%1/1
$self->{$key} ||= []
$self->{$key}
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table100%2/2
A
A= $self->{$key}
Aresult
11
00
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
130 }
131 69 }
132 elsif($interface eq 'shift')
133 {
134 $methods{$name} = sub
135 3 ▶ {
Subroutine __ANON__: called CC=4 SCAR=18.9
136 3 my($self) = shift;
137 3 ▶ return splice(@{$self->{$key} ||= []}, 0, $_[0]) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 0 3
Condition50%1/2
$self->{$key} ||= []
l!l
30
MC/DC0%0/1
$self->{$key} ||= []
$self->{$key}
Truth table50%1/2
A
A= $self->{$key}
Aresult
11
00
138 0 ▶ return shift(@{$self->{$key} ||= []})
Condition0%0/2
$self->{$key} ||= []
l!l
00
MC/DC0%0/1
$self->{$key} ||= []
$self->{$key}
Truth table0%0/2
A
A= $self->{$key}
Aresult
11
00
139 }
140 69 }
141 elsif($interface eq 'clear')
142 {
143 $methods{$name} = sub
144 3 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
145 3 $_[0]->{$key} = []
146 }
147 69 }
148 elsif($interface eq 'reset')
149 {
150 $methods{$name} = sub
151 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
152 0 $_[0]->{$key} = undef;
153 }
154 0 }
155 elsif($interface =~ /^(?:push|add)$/)
156 {
157 $methods{$name} = sub
158 8 ▶ {
Subroutine __ANON__: called CC=6 SCAR=18.6
159 8 my($self) = shift;
160 8 ▶ Carp::croak "Missing value(s) to add" unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 8 8
161 0 ▶ push(@{$self->{$key} ||= []}, map { _coerce_html_object($self, $_) } (@_ == 1 && ref $_[0] && ref $_[0] eq 'ARRAY') ? @{$_[0]} : @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] && ref $_[0] eq 'ARRAY' ? : 0 8 8
Condition87%7/8
$self->{$key} ||= []
l!l
44
@_ == 1 and ref $_[0] and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
350
@_ == 1 and ref $_[0]
!ll&&!rl&&r
125
MC/DC100%1/1
$self->{$key} ||= []
$self->{$key}
MC/DC0%0/3
@_ == 1 and ref $_[0] and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] ref $_[0] eq "ARRAY"
Truth table100%2/2
A
A= $self->{$key}
Aresult
11
00
Truth table75%3/4
A and B and C
A= @_ == 1B= ref $_[0]C= ref $_[0] eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
162 }
163 69 }
164 elsif($interface eq 'pop')
165 {
166 $methods{$name} = sub
167 5 ▶ {
Subroutine __ANON__: called CC=5 SCAR=18.9
168 5 my($self) = shift;
169  
170 5 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 0 5
171 {
172 5 ▶ my $a = $self->{$key} ||= [];
Condition50%1/2
$self->{$key} ||= []
l!l
50
MC/DC0%0/1
$self->{$key} ||= []
$self->{$key}
Truth table50%1/2
A
A= $self->{$key}
Aresult
11
00
173 5 my $offset = @$a - $_[0];
174 5 ▶ return splice(@$a, $offset < 0 ? 0 : $offset)
Branch: 1 branch
BranchTrueFalseTotal
$offset < 0 ? : 1 4 5
175 }
176  
177 0 ▶ return pop(@{$self->{$key} ||= []})
Condition0%0/2
$self->{$key} ||= []
l!l
00
MC/DC0%0/1
$self->{$key} ||= []
$self->{$key}
Truth table0%0/2
A
A= $self->{$key}
Aresult
11
00
178 }
179 69 }
180 elsif($interface eq 'get_set')
181 {
182 $methods{$name} = sub
183 2404 ▶ {
Subroutine __ANON__: called CC=7 SCAR=31.1
184 2404 my($self) = shift;
185  
186 # If called with no arguments, return array contents
187 2404 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 2404 0 2404
188 {
189 2404 ▶ return wantarray ? (defined $self->{$key} ? @{$self->{$key}} : ()) : $self->{$key}
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 2404 0 2404
defined $self->{$key} ? : 36 2368 2404
190 }
191  
192 # If called with a array ref, set new value
193 0 ▶ if(@_ == 1 && ref $_[0] eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
194 {
195 0 $self->{$key} = [ map { _coerce_html_object($self, $_) } @{$_[0]} ];
196 }
197 else
198 {
199 0 $self->{$key} = [ map { _coerce_html_object($self, $_) } @_ ];
200 }
201  
202 0 ▶ return wantarray ? @{$self->{$key}} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
203 }
204 26 }
205 0 else { Carp::croak "Unknown interface: $interface" }
206  
207 500 return \%methods;
208 }
209  
210 sub _coerce_html_object
211 463 ▶{
Subroutine _coerce_html_object: called CC=3 SCAR=11.2
212 463 my($self, $arg) = (shift, shift);
213  
214 463 ▶ if(!ref $arg)
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $arg) { } 35 428 463
elsif (not $arg->isa('Rose::HTML::Object')) { } 0 428 428
215 {
216 35 return Rose::HTML::Text->new(text => $arg, parent => $self);
217 }
218 elsif(!$arg->isa('Rose::HTML::Object'))
219 {
220 0 return Rose::HTML::Text->new(text => $arg, parent => $self);
221 }
222  
223 428 $arg->parent($self);
224  
225 428 return $arg;
226 }
227  
228 43 1;
« blib/lib/Rose/HTML/Object/Message/Localizer.pm ↑ Summary blib/lib/Rose/HTML/Form.pm »