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

filter: Statementstmt 65.4% 172 / 263 Branchbran 45.3% 58 / 128 Conditioncond 38.8% 35 / 90 MC/DCmcdc 9.8% 5 / 51 Subroutinesub 85.7% 18 / 21 Podpod 0.0% 0 / 4 totaltotal 51.7% 288 / 557 CC 103 SCAR 35.0
CC
103
Cov
55%
__ANON__
156.0
__ANON__
90.0
localized_error
42.0
CRAP 33.0
« blib/lib/Rose/HTML/Form/Field/Time/Hours.pm ↑ Summary blib/lib/Rose/HTML/Object/Message/Localizer.pm »
1 package Rose::HTML::Object::MakeMethods::Localization;
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.615';
10  
11 sub localized_message
12 153 ▶{
Subroutine localized_message: called CC=6 SCAR=22.3
Pod undocumented
13 153 my($class, $name, $args, $opts) = @_;
14  
15 153 my %methods;
16  
17 153 ▶ my $interface = $args->{'interface'} || 'get_set';
Condition50%1/2
$args->{'interface'} || 'get_set'
l!l
0153
MC/DC0%0/1
$args->{'interface'} || 'get_set'
$args->{'interface'}
Truth table50%1/2
A
A= $args->{'interface'}
Aresult
11
00
18 153 ▶ my $key = $args->{'hash_key'} || $name;
Condition33%1/3
$args->{'hash_key'} || $name
l!l&&r!l&&!r
01530
MC/DC0%0/2
$args->{'hash_key'} || $name
$args->{'hash_key'} $name
Truth table33%1/3
A || B
A= $args->{'hash_key'}B= $name
ABresult
1X1
011
000
19 153 ▶ my $id_method = $args->{'msg_id_method'} || $key . '_message_id';
Condition50%1/2
$args->{'msg_id_method'} || $key . '_message_id'
l!l
0153
MC/DC0%0/1
$args->{'msg_id_method'} || $key . '_message_id'
$args->{'msg_id_method'}
Truth table50%1/2
A
A= $args->{'msg_id_method'}
Aresult
11
00
20  
21 153 ▶ my $accept_msg_class = $args->{'accept_msg_class'} || 'Rose::HTML::Object::Message';
Condition50%1/2
$args->{'accept_msg_class'} || 'Rose::HTML::Object::Message'
l!l
0153
MC/DC0%0/1
$args->{'accept_msg_class'} || 'Rose::HTML::Object::Message'
$args->{'accept_msg_class'}
Truth table50%1/2
A
A= $args->{'accept_msg_class'}
Aresult
11
00
22  
23 153 require Rose::HTML::Object::Message::Localized;
24  
25 153 ▶ if($interface eq 'get_set')
Branch: 1 branch
BranchTrueFalseTotal
if ($interface eq 'get_set') { } 153 0 153
26 {
27 $methods{$name} = sub
28 2206 ▶ {
Subroutine __ANON__: called CC=8 SCAR=29.6
29 2206 my($self) = shift;
30  
31 2206 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 853 1353 2206
32 {
33 853 ▶ if(@_ > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 853 853
34 {
35 0 my($id) = shift;
36  
37 0 my @args;
38  
39 0 ▶ if(@_ == 1 && ref($_[0]) =~ /^(?:HASH|ARRAY)$/)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/) { } 0 0 0
Condition0%0/3
@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/
@_ == 1 ref($_[0]) =~ /^(?:HASH|ARRAY)$/
Truth table0%0/3
A and B
A= @_ == 1B= ref($_[0]) =~ /^(?:HASH|ARRAY)$/
ABresult
0X0
100
111
40 {
41 0 @args = (args => $_[0]);
42 }
43 else
44 {
45 0 @args = (args => [ @_ ]);
46 }
47  
48 0 ▶ unless($id =~ /^\d+$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($id =~ /^\d+$/) 0 0 0
49 {
50 0 ▶ $id = $self->localizer->get_message_id($id) ||
Condition0%0/2
$self->localizer->get_message_id($id) || Carp::croak("Unknown message id: '${id}'")
l!l
00
MC/DC0%0/1
$self->localizer->get_message_id($id) || Carp::croak("Unknown message id: '${id}'")
$self->localizer->get_message_id($id)
Truth table0%0/2
A
A= $self->localizer->get_message_id($id)
Aresult
11
00
51 Carp::croak "Unknown message id: '$id'";
52 }
53  
54 0 return $self->$name($self->localizer->message_class->new(id => $id, parent => $self, @args));
55 }
56  
57 853 my $msg = shift;
58  
59 853 ▶ if(UNIVERSAL::isa($msg, $accept_msg_class))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($msg, $accept_msg_class)) { } 483 370 853
60 {
61 483 $msg->parent($self);
62 483 return $self->{$key} = $msg;
63 }
64 else
65 {
66 370 return $self->{$key} = $self->localizer->message_class->new(text => $msg, parent => $self);
67 }
68 }
69  
70 1353 return $self->{$key};
71 153 };
72  
73 $methods{$id_method} = sub
74 363 ▶ {
Subroutine __ANON__: called CC=4 SCAR=16.6
75 363 my($self) = shift;
76  
77 363 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 363 0 363
78 {
79 363 my($id, @args) = @_;
80 363 ▶ return $self->$name(undef) unless(defined $id);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 14 349 363
81 349 return $self->$name($self->localizer->message_class->new(id => $id, args => \@args, parent => $self));
82 }
83  
84 0 my $error = $self->$name();
85 0 ▶ return $error->id if(UNIVERSAL::can($error, 'id'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($error, "id") 0 0 0
86 0 return undef;
87 153 };
88 }
89 0 else { Carp::croak "Unknown interface: $interface" }
90  
91 153 return \%methods;
92 }
93  
94 sub localized_error
95 0 ▶{
Subroutine localized_error: not called CC=6 SCAR=37.4
Pod undocumented
96 0 my($class, $name, $args) = @_;
97  
98 0 my %methods;
99  
100 0 ▶ my $interface = $args->{'interface'} || 'get_set';
Condition0%0/2
$args->{'interface'} || 'get_set'
l!l
00
MC/DC0%0/1
$args->{'interface'} || 'get_set'
$args->{'interface'}
Truth table0%0/2
A
A= $args->{'interface'}
Aresult
11
00
101 0 ▶ my $key = $args->{'hash_key'} || $name;
Condition0%0/3
$args->{'hash_key'} || $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'hash_key'} || $name
$args->{'hash_key'} $name
Truth table0%0/3
A || B
A= $args->{'hash_key'}B= $name
ABresult
1X1
011
000
102 0 ▶ my $id_method = $args->{'error_id_method'} || $key . '_id';
Condition0%0/2
$args->{'error_id_method'} || $key . '_id'
l!l
00
MC/DC0%0/1
$args->{'error_id_method'} || $key . '_id'
$args->{'error_id_method'}
Truth table0%0/2
A
A= $args->{'error_id_method'}
Aresult
11
00
103  
104 0 ▶ my $accept_error_class = $args->{'accept_error_class'} || 'Rose::HTML::Object::Error';
Condition0%0/2
$args->{'accept_error_class'} || 'Rose::HTML::Object::Error'
l!l
00
MC/DC0%0/1
$args->{'accept_error_class'} || 'Rose::HTML::Object::Error'
$args->{'accept_error_class'}
Truth table0%0/2
A
A= $args->{'accept_error_class'}
Aresult
11
00
105  
106 0 require Rose::HTML::Object::Error;
107  
108 0 ▶ if($interface eq 'get_set')
Branch: 1 branch
BranchTrueFalseTotal
if ($interface eq 'get_set') { } 0 0 0
109 {
110 $methods{$name} = sub
111 0 ▶ {
Subroutine __ANON__: not called CC=12 SCAR=50.5
112 0 my($self) = shift;
113  
114 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
115 {
116 0 ▶ return $self->{$key} = undef unless(defined $_[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
117  
118 0 my $localizer = $self->localizer;
119  
120 0 ▶ if(@_ > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
121 {
122 0 my($id) = shift;
123  
124 0 my @args;
125  
126 0 ▶ if(@_ == 1 && ref($_[0]) =~ /^(?:HASH|ARRAY)$/)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/) { } 0 0 0
Condition0%0/3
@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/
@_ == 1 ref($_[0]) =~ /^(?:HASH|ARRAY)$/
Truth table0%0/3
A and B
A= @_ == 1B= ref($_[0]) =~ /^(?:HASH|ARRAY)$/
ABresult
0X0
100
111
127 {
128 0 @args = (args => $_[0]);
129 }
130 else
131 {
132 0 @args = (args => [ @_ ]);
133 }
134  
135 0 ▶ unless($id =~ /^\d+$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($id =~ /^\d+$/) 0 0 0
136 {
137 0 ▶ $id = $self->localizer->get_error_id($id) ||
Condition0%0/2
$self->localizer->get_error_id($id) || Carp::croak("Attempt to call $name() with more than one ", 'argument, and the first argument is not a numeric ', "error id: '${id}'")
l!l
00
MC/DC0%0/1
$self->localizer->get_error_id($id) || Carp::croak("Attempt to call $name() with more than one ", 'argument, and the first argument is not a numeric ', "error id: '${id}'")
$self->localizer->get_error_id($id)
Truth table0%0/2
A
A= $self->localizer->get_error_id($id)
Aresult
11
00
138 Carp::croak "Attempt to call $name() with more than one ",
139 "argument, and the first argument is not a numeric ",
140 "error id: '$id'";
141 }
142  
143 0 unshift(@args, error_id => $id);
144  
145 0 my $message;
146  
147 0 ▶ if($self->can('message_for_error_id'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can('message_for_error_id')) { } 0 0 0
148 {
149 0 $message = $self->message_for_error_id(@args);
150  
151 0 ▶ unless(defined $message)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $message) 0 0 0
152 {
153 0 $message = $localizer->message_for_error_id(@args);
154 }
155 }
156 else
157 {
158 0 $message = $localizer->message_for_error_id(@args);
159 }
160  
161  
162 0 return $self->$name($localizer->error_class->new(id => $id,
163 parent => $self,
164 message => $message));
165 }
166  
167 0 my $error = shift;
168  
169 0 ▶ if(UNIVERSAL::isa($error, $accept_error_class))
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($error, $accept_error_class)) { } 0 0 0
elsif (defined $error) { } 0 0 0
170 {
171 0 $error->parent($self);
172 0 return $self->{$key} = $error;
173 }
174 elsif(defined $error)
175 {
176 0 return $self->{$key} =
177 $localizer->error_class->new(message => $localizer->messsage_class->new($error),
178 parent => $self);
179 }
180 }
181  
182 0 return $self->{$key};
183 0 };
184  
185 $methods{$id_method} = sub
186 0 ▶ {
Subroutine __ANON__: not called CC=9 SCAR=45.0
187 0 my($self) = shift;
188  
189 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
190 {
191 0 my($id) = shift;
192  
193 0 my $localizer = $self->localizer;
194  
195 0 my @args;
196  
197 0 ▶ if(@_ == 1 && ref($_[0]) =~ /^(?:HASH|ARRAY)$/)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/) { } 0 0 0
Condition0%0/3
@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/
@_ == 1 ref($_[0]) =~ /^(?:HASH|ARRAY)$/
Truth table0%0/3
A and B
A= @_ == 1B= ref($_[0]) =~ /^(?:HASH|ARRAY)$/
ABresult
0X0
100
111
198 {
199 0 @args = (args => $_[0]);
200 }
201 else
202 {
203 0 @args = (args => [ @_ ]);
204 }
205  
206 0 ▶ unless($id =~ /^\d+$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($id =~ /^\d+$/) 0 0 0
207 {
208 0 ▶ $id = $localizer->get_error_id($id) ||
Condition0%0/2
$localizer->get_error_id($id) || Carp::croak("Unknown error id: '${id}'")
l!l
00
MC/DC0%0/1
$localizer->get_error_id($id) || Carp::croak("Unknown error id: '${id}'")
$localizer->get_error_id($id)
Truth table0%0/2
A
A= $localizer->get_error_id($id)
Aresult
11
00
209 Carp::croak "Unknown error id: '$id'";
210 }
211  
212 0 unshift(@args, error_id => $id);
213  
214 0 my $message;
215  
216 0 ▶ if($self->can('message_for_error_id'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can('message_for_error_id')) { } 0 0 0
217 {
218 0 $message = $self->message_for_error_id(@args);
219  
220 0 ▶ unless(defined $message)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $message) 0 0 0
221 {
222 0 $message = $localizer->message_for_error_id(@args);
223 }
224 }
225 else
226 {
227 0 $message = $localizer->message_for_error_id(@args);
228 }
229  
230  
231 0 return $self->$name($localizer->error_class->new(id => $id,
232 parent => $self,
233 message => $message));
234 }
235  
236 0 my $error = $self->$name();
237 0 ▶ return $error->id if(UNIVERSAL::can($error, 'id'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($error, "id") 0 0 0
238 0 return undef;
239 0 };
240  
241 }
242 0 else { Carp::croak "Unknown interface: $interface" }
243  
244 0 return \%methods;
245 }
246  
247 sub localized_errors
248 43 ▶{
Subroutine localized_errors: called CC=15 SCAR=30.1
Pod undocumented
249 43 my($class, $name, $args) = @_;
250  
251 43 my %methods;
252  
253 43 ▶ my $interface = $args->{'interface'} || 'get_set';
Condition50%1/2
$args->{'interface'} || 'get_set'
l!l
043
MC/DC0%0/1
$args->{'interface'} || 'get_set'
$args->{'interface'}
Truth table50%1/2
A
A= $args->{'interface'}
Aresult
11
00
254 43 ▶ my $key = $args->{'hash_key'} || $name;
Condition33%1/3
$args->{'hash_key'} || $name
l!l&&r!l&&!r
0430
MC/DC0%0/2
$args->{'hash_key'} || $name
$args->{'hash_key'} $name
Truth table33%1/3
A || B
A= $args->{'hash_key'}B= $name
ABresult
1X1
011
000
255 43 ▶ my $plural_name = $args->{'plural_name'} || $name;
Condition33%1/3
$args->{'plural_name'} || $name
l!l&&r!l&&!r
0430
MC/DC0%0/2
$args->{'plural_name'} || $name
$args->{'plural_name'} $name
Truth table33%1/3
A || B
A= $args->{'plural_name'}B= $name
ABresult
1X1
011
000
256 43 ▶ my $singular_name = $args->{'singular_name'} || plural_to_singular($plural_name);
Condition33%1/3
$args->{'singular_name'} || plural_to_singular($plural_name)
l!l&&r!l&&!r
0430
MC/DC0%0/2
$args->{'singular_name'} || plural_to_singular($plural_name)
$args->{'singular_name'} plural_to_singular($plural_name)
Truth table33%1/3
A || B
A= $args->{'singular_name'}B= plural_to_singular($plural_name)
ABresult
1X1
011
000
257 43 ▶ my $has_method = $args->{'has_error_method'} || 'has_' . $plural_name;
Condition50%1/2
$args->{'has_error_method'} || 'has_' . $plural_name
l!l
043
MC/DC0%0/1
$args->{'has_error_method'} || 'has_' . $plural_name
$args->{'has_error_method'}
Truth table50%1/2
A
A= $args->{'has_error_method'}
Aresult
11
00
258 43 ▶ my $has_method2 = $args->{'has_errors_method'} || 'has_' . $singular_name;
Condition50%1/2
$args->{'has_errors_method'} || 'has_' . $singular_name
l!l
043
MC/DC0%0/1
$args->{'has_errors_method'} || 'has_' . $singular_name
$args->{'has_errors_method'}
Truth table50%1/2
A
A= $args->{'has_errors_method'}
Aresult
11
00
259 43 ▶ my $add_method = $args->{'add_error_method'} || 'add_' . $singular_name;
Condition50%1/2
$args->{'add_error_method'} || 'add_' . $singular_name
l!l
043
MC/DC0%0/1
$args->{'add_error_method'} || 'add_' . $singular_name
$args->{'add_error_method'}
Truth table50%1/2
A
A= $args->{'add_error_method'}
Aresult
11
00
260 43 ▶ my $adds_method = $args->{'add_errors_method'} || 'add_' . $plural_name;
Condition50%1/2
$args->{'add_errors_method'} || 'add_' . $plural_name
l!l
043
MC/DC0%0/1
$args->{'add_errors_method'} || 'add_' . $plural_name
$args->{'add_errors_method'}
Truth table50%1/2
A
A= $args->{'add_errors_method'}
Aresult
11
00
261 43 ▶ my $id_method = $args->{'error_id_method'} || $singular_name . '_id';
Condition50%1/2
$args->{'error_id_method'} || $singular_name . '_id'
l!l
043
MC/DC0%0/1
$args->{'error_id_method'} || $singular_name . '_id'
$args->{'error_id_method'}
Truth table50%1/2
A
A= $args->{'error_id_method'}
Aresult
11
00
262 43 ▶ my $ids_method = $args->{'error_ids_method'} || $singular_name . '_ids';
Condition50%1/2
$args->{'error_ids_method'} || $singular_name . '_ids'
l!l
043
MC/DC0%0/1
$args->{'error_ids_method'} || $singular_name . '_ids'
$args->{'error_ids_method'}
Truth table50%1/2
A
A= $args->{'error_ids_method'}
Aresult
11
00
263 43 ▶ my $add_id_method = $args->{'add_error_id_method'} || 'add_' . $singular_name . '_id';
Condition50%1/2
$args->{'add_error_id_method'} || 'add_' . $singular_name . '_id'
l!l
043
MC/DC0%0/1
$args->{'add_error_id_method'} || 'add_' . $singular_name . '_id'
$args->{'add_error_id_method'}
Truth table50%1/2
A
A= $args->{'add_error_id_method'}
Aresult
11
00
264 43 ▶ my $add_ids_method = $args->{'add_error_ids_method'} || 'add_' . $singular_name . '_ids';
Condition50%1/2
$args->{'add_error_ids_method'} || 'add_' . $singular_name . '_ids'
l!l
043
MC/DC0%0/1
$args->{'add_error_ids_method'} || 'add_' . $singular_name . '_ids'
$args->{'add_error_ids_method'}
Truth table50%1/2
A
A= $args->{'add_error_ids_method'}
Aresult
11
00
265  
266 43 ▶ my $accept_error_class = $args->{'accept_error_class'} || 'Rose::HTML::Object::Error';
Condition50%1/2
$args->{'accept_error_class'} || 'Rose::HTML::Object::Error'
l!l
043
MC/DC0%0/1
$args->{'accept_error_class'} || 'Rose::HTML::Object::Error'
$args->{'accept_error_class'}
Truth table50%1/2
A
A= $args->{'accept_error_class'}
Aresult
11
00
267  
268 43 require Rose::HTML::Object::Error;
269  
270 43 ▶ if($interface eq 'get_set')
Branch: 1 branch
BranchTrueFalseTotal
if ($interface eq 'get_set') { } 43 0 43
271 {
272 $methods{$plural_name} = sub
273 19 ▶ {
Subroutine __ANON__: called CC=7 SCAR=19.5
274 19 my($self) = shift;
275  
276 19 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 11 19
277 {
278 8 ▶ if(!defined $_[0] || (ref $_[0] eq 'ARRAY' && !@{$_[0]}))
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_[0] or ref $_[0] eq "ARRAY" and not @{$_[0];}) 2 6 8
Condition83%5/6
not defined $_[0] or ref $_[0] eq "ARRAY" and not @{$_[0];}
l!l&&r!l&&!r
116
ref $_[0] eq "ARRAY" and not @{$_[0];}
!ll&&!rl&&r
601
MC/DC66%2/3
not defined $_[0] or ref $_[0] eq "ARRAY" and not @{$_[0];}
not defined $_[0] ref $_[0] eq "ARRAY" not @{$_[0];}
Truth table75%3/4
not(A) or B and not(C)
A= not defined $_[0]B= ref $_[0] eq "ARRAY"C= not @{$_[0];}
ABCresult
1XX1
0111
00X0
0100
279 {
280 2 return $self->{$key} = undef;
281 }
282  
283 6 $self->{$key} = undef;
284 6 $self->$adds_method(@_);
285 }
286  
287 17 ▶ return wantarray ? @{$self->{$key} || []} : $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 11 6 17
Condition50%1/2
$self->{$key} || []
l!l
110
MC/DC0%0/1
$self->{$key} || []
$self->{$key}
Truth table50%1/2
A
A= $self->{$key}
Aresult
11
00
288 43 };
289  
290 $methods{$singular_name} = sub
291 6423 ▶ {
Subroutine __ANON__: called CC=12 SCAR=27.7
292 6423 my($self) = shift;
293  
294 6423 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4442 1981 6423
295 {
296 4442 ▶ return $self->{$key} = undef unless(defined $_[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 4422 20 4442
297  
298 20 my $localizer = $self->localizer;
299  
300 20 ▶ if(@_ > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 2 18 20
301 {
302 2 my($id) = shift;
303  
304 2 my @args;
305  
306 2 ▶ if(@_ == 1 && ref($_[0]) =~ /^(?:HASH|ARRAY)$/)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/) { } 2 0 2
Condition33%1/3
@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/
!ll&&!rl&&r
002
MC/DC0%0/2
@_ == 1 and ref($_[0]) =~ /^(?:HASH|ARRAY)$/
@_ == 1 ref($_[0]) =~ /^(?:HASH|ARRAY)$/
Truth table33%1/3
A and B
A= @_ == 1B= ref($_[0]) =~ /^(?:HASH|ARRAY)$/
ABresult
0X0
100
111
307 {
308 2 @args = (args => $_[0]);
309 }
310 else
311 {
312 0 @args = (args => [ @_ ]);
313 }
314  
315 2 ▶ unless($id =~ /^\d+$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($id =~ /^\d+$/) 0 2 2
316 {
317 0 ▶ $id = $localizer->get_error_id($id) ||
Condition0%0/2
$localizer->get_error_id($id) || Carp::croak("Attempt to call $singular_name() with more than one ", 'argument, and the first argument is not a numeric ', "error id: '${id}'")
l!l
00
MC/DC0%0/1
$localizer->get_error_id($id) || Carp::croak("Attempt to call $singular_name() with more than one ", 'argument, and the first argument is not a numeric ', "error id: '${id}'")
$localizer->get_error_id($id)
Truth table0%0/2
A
A= $localizer->get_error_id($id)
Aresult
11
00
318 Carp::croak "Attempt to call $singular_name() with more than one ",
319 "argument, and the first argument is not a numeric ",
320 "error id: '$id'";
321 }
322  
323 2 unshift(@args, error_id => $id);
324  
325 2 my $message;
326  
327 2 ▶ if($self->can('message_for_error_id'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can('message_for_error_id')) { } 2 0 2
328 {
329 2 $message = $self->message_for_error_id(@args);
330  
331 2 ▶ unless(defined $message)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $message) 2 0 2
332 {
333 2 $message = $localizer->message_for_error_id(@args);
334 }
335 }
336 else
337 {
338 0 $message = $localizer->message_for_error_id(@args);
339 }
340  
341 2 $self->{$key} =
342 [ $localizer->error_class->new(id => $id, parent => $self, message => $message) ];
343  
344 2 return $self->{$key}[-1];
345 }
346  
347 18 my $error = shift;
348  
349 18 ▶ if(UNIVERSAL::isa($error, $accept_error_class))
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($error, $accept_error_class)) { } 0 18 18
elsif (defined $error) { } 18 0 18
350 {
351 0 $error->parent($self);
352 0 $self->{$key} = [ $error ];
353 }
354 elsif(defined $error)
355 {
356 18 $self->{$key} =
357 [ $localizer->error_class->new(message => $localizer->message_class->new($error), parent => $self) ];
358 }
359 }
360  
361 1999 return $self->{$key}[-1];
362 43 };
363  
364 $methods{$adds_method} = sub
365 7 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.2
366 7 my($self) = shift;
367  
368 7 ▶ return unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 7 7
369  
370 7 my $localizer = $self->localizer;
371 7 my $errors = __errors_from_args($self, \@_, $localizer->error_class, $localizer->message_class, $accept_error_class, 0, 0);
372  
373 7 push(@{$self->{$key}}, @$errors);
374  
375 7 ▶ return wantarray ? @$errors : $errors;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 7 7
376 43 };
377  
378 $methods{$add_method} = sub
379 5 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.2
380 5 my($self) = shift;
381  
382 5 ▶ return unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 5 5
383  
384 5 my $localizer = $self->localizer;
385 5 my $errors = __errors_from_args($self, \@_, $localizer->error_class, $localizer->message_class, $accept_error_class, 0, 1);
386  
387 5 push(@{$self->{$key}}, @$errors);
388  
389 5 ▶ return wantarray ? @$errors : $errors;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 5 5
390 43 };
391  
392 $methods{$id_method} = sub
393 43 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
394 43 my($self) = shift;
395  
396 43 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 32 11 43
397 {
398 32 my $localizer = $self->localizer;
399 32 my $errors = __errors_from_args($self, \@_, $localizer->error_class, $localizer->message_class, $accept_error_class, 1, 1);
400 32 $self->{$key} = $errors;
401 32 return $errors->[-1]->id;
402 }
403  
404 11 ▶ return $self->{$key}[-1] ? $self->{$key}[-1]->id : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{$key}[-1] ? : 11 0 11
405 43 };
406  
407 $methods{$ids_method} = sub
408 1 ▶ {
Subroutine __ANON__: called CC=6 SCAR=23.5
409 1 my($self) = shift;
410  
411 1 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
412 {
413 0 my $localizer = $self->localizer;
414 0 my $errors = __errors_from_args($self, \@_, $localizer->error_class, $localizer->message_class, $accept_error_class, 1, 0);
415 0 $self->{$key} = $errors;
416 0 ▶ return wantarray ? @$errors : $errors;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
417 }
418  
419 1 ▶ if(defined(my $want = wantarray))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $want = wantarray)) 1 0 1
420 {
421 1 ▶ my @ids = map { $_->id } @{$self->{$key} || []};
Condition50%1/2
$self->{$key} || []
l!l
10
MC/DC0%0/1
$self->{$key} || []
$self->{$key}
Truth table50%1/2
A
A= $self->{$key}
Aresult
11
00
422 1 ▶ return $want ? @ids : \@ids;
Branch: 1 branch
BranchTrueFalseTotal
$want ? : 1 0 1
423 }
424  
425 0 return;
426 43 };
427  
428 $methods{$add_ids_method} = sub
429 1 ▶ {
Subroutine __ANON__: called CC=4 SCAR=16.3
430 1 my($self) = shift;
431  
432 1 ▶ return unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
433  
434 1 my $localizer = $self->localizer;
435 1 my $errors = __errors_from_args($self, \@_, $localizer->error_class, $localizer->message_class, $accept_error_class, 1, 1);
436  
437 1 push(@{$self->{$key}}, @$errors);
438  
439 1 ▶ if(defined(my $want = wantarray))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $want = wantarray)) 0 1 1
440 {
441 0 my @ids = map { $_->id } @$errors;
442 0 ▶ return $want ? @ids : \@ids;
Branch: 1 branch
BranchTrueFalseTotal
$want ? : 0 0 0
443 }
444  
445 1 return;
446 43 };
447  
448 $methods{$add_id_method} = sub
449 68 ▶ {
Subroutine __ANON__: called CC=4 SCAR=16.3
450 68 my($self) = shift;
451  
452 68 ▶ return unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 68 68
453  
454 68 my $localizer = $self->localizer;
455 68 my $errors = __errors_from_args($self, \@_, $localizer->error_class, $localizer->message_class, $accept_error_class, 1, 0);
456  
457 68 push(@{$self->{$key}}, @$errors);
458  
459 68 ▶ if(defined(my $want = wantarray))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $want = wantarray)) 0 68 68
460 {
461 0 my @ids = map { $_->id } @$errors;
462 0 ▶ return $want ? @ids : \@ids;
Branch: 1 branch
BranchTrueFalseTotal
$want ? : 0 0 0
463 }
464  
465 68 return;
466 43 };
467  
468 43 ▶ $methods{$has_method} = sub { scalar @{shift->{$key} || []} };
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
+(shift())->{$key} || []
l!l
1721
MC/DC100%1/1
+(shift())->{$key} || []
+(shift())->{$key}
Truth table100%2/2
A
A= +(shift())->{$key}
Aresult
11
00
469 43 $methods{$has_method2} = $methods{$has_method};
470 }
471 0 else { Carp::croak "Unknown interface: $interface" }
472  
473 43 return \%methods;
474 }
475  
476 sub plural_to_singular
477 43 ▶{
Subroutine plural_to_singular: called CC=2 SCAR=7.0
Pod undocumented
478 43 my($word) = shift;
479 43 ▶ return $word if($word =~ /[aeiouy]ss$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /[aeiouy]ss$/i 0 43 43
480 43 $word =~ s/s$//;
481 43 return $word;
482 }
483  
484 # Acceptable formats:
485 #
486 # <error object>, ...
487 # <numeric error id> (id method only)
488 # <list of numeric error ids> (non-singular id method only)
489 # <numeric error id> <list of args> (singular only)
490 # <numeric error id> <arrayref of args>, ...
491 # <numeric error id> <hashref of args>, ...
492 sub __errors_from_args
493 113 ▶{
Subroutine __errors_from_args: called CC=14 SCAR=26.9
494 113 my($self, $args, $error_class, $msg_class, $accept_error_class, $id_method, $singular) = @_;
495  
496 113 local $Carp::CarpLevel = 1;
497  
498 113 ▶ $args = $args->[0] if(@$args == 1 && ref($args->[0]) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if @$args == 1 and ref $args->[0] eq "ARRAY" 0 113 113
Condition66%2/3
@$args == 1 and ref $args->[0] eq "ARRAY"
!ll&&!rl&&r
63500
MC/DC0%0/2
@$args == 1 and ref $args->[0] eq "ARRAY"
@$args == 1 ref $args->[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @$args == 1B= ref $args->[0] eq "ARRAY"
ABresult
0X0
100
111
499  
500 113 my @errors;
501  
502 113 my $localizer = $self->localizer;
503  
504 113 ▶ for(my $i = 0; $i <= $#$args; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $args->$#*) 119 113 232
505 {
506 119 my $arg = $args->[$i];
507  
508 119 ▶ if(UNIVERSAL::isa($arg, $accept_error_class))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($arg, $accept_error_class)) 5 114 119
509 {
510 5 $arg->parent($self);
511 5 push(@errors, $arg);
512 5 next;
513 }
514  
515 114 my $id = $arg;
516  
517 114 ▶ if($id_method && $id !~ /^\d+$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($id_method and not $id =~ /^\d+$/) 3 111 114
Condition100%3/3
$id_method and not $id =~ /^\d+$/
!ll&&!rl&&r
12993
MC/DC100%2/2
$id_method and not $id =~ /^\d+$/
$id_method not $id =~ /^\d+$/
Truth table100%3/3
A and not(B)
A= $id_methodB= not $id =~ /^\d+$/
ABresult
0X0
100
111
518 {
519 3 ▶ $id = $localizer->get_error_id($id) ||
Condition50%1/2
$localizer->get_error_id($id) || Carp::croak("Unknown error id: '${id}'")
l!l
30
MC/DC0%0/1
$localizer->get_error_id($id) || Carp::croak("Unknown error id: '${id}'")
$localizer->get_error_id($id)
Truth table50%1/2
A
A= $localizer->get_error_id($id)
Aresult
11
00
520 Carp::croak "Unknown error id: '$id'";
521 }
522  
523 114 my @msg_args;
524  
525 114 ▶ if(ref($args->[$i + 1]) =~ /^(?:HASH|ARRAY)$/)
Branch: 2 branches
BranchTrueFalseTotal
if (ref($$args[$i + 1]) =~ /^(?:HASH|ARRAY)$/) { } 57 57 114
elsif ($singular and $i + 1 < $args->$#*) { } 0 109 109
526 {
527 57 @msg_args = (args => $args->[++$i]);
528 }
529 ▶ elsif($singular && ($i + 1) < $#$args)
Condition66%2/3
$singular and $i + 1 < $args->$#*
!ll&&!rl&&r
5250
MC/DC0%0/2
$singular and $i + 1 < $args->$#*
$singular $i + 1 < $args->$#*
Truth table66%2/3
A and B
A= $singularB= $i + 1 < $args->$#*
ABresult
0X0
100
111
530 {
531 0 @msg_args = (args => [ @$args[$i + 1 .. $#$args] ]);
532 0 $i = $#$args;
533 }
534  
535 114 unshift(@msg_args, error_id => $id, msg_class => $msg_class);
536  
537 114 my $message;
538  
539 114 ▶ if($id =~ /^\d+$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /^\d+$/) { } 105 9 114
540 {
541 105 ▶ if($self->can('message_for_error_id'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can('message_for_error_id')) { } 105 0 105
542 {
543 105 $message = $self->message_for_error_id(@msg_args);
544  
545 105 ▶ unless(defined $message)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $message) 68 37 105
546 {
547 68 $message = $localizer->message_for_error_id(@msg_args);
548 }
549 }
550 else
551 {
552 0 $message = $localizer->message_for_error_id(@msg_args);
553 }
554  
555 105 push(@errors, $error_class->new(id => $id,
556 message => $message,
557 parent => $self));
558 }
559 else
560 {
561 9 push(@errors, $error_class->new(message => $msg_class->new($id),
562 parent => $self));
563 }
564 }
565  
566 113 return \@errors;
567 }
568  
569 43 1;
« blib/lib/Rose/HTML/Form/Field/Time/Hours.pm ↑ Summary blib/lib/Rose/HTML/Object/Message/Localizer.pm »