lib/Acme/Sub/Parms.pm

filter: Statementstmt 90.8% 209 / 230 Branchbran 77.0% 77 / 100 Conditioncond 59.5% 25 / 42 MC/DCmcdc 43.4% 10 / 23 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 2 totaltotal 81.4% 333 / 409 CC 71 SCAR 32.9
CC
71
Cov
84%
filter
40.7
_parse_bind_spec
22.8
bind_spec
19.2
CRAP 26.8
↑ Summary
1 package Acme::Sub::Parms;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Filter::Util::Call;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 $Acme::Sub::Parms::VERSION = '1.03';
9 5 %Acme::Sub::Parms::args = ();
10 5 %Acme::Sub::Parms::raw_args = ();
11 5 $Acme::Sub::Parms::line_counter = 0;
12 }
13  
14 445 ▶sub _NORMALIZE () { return ':normalize'; };
Subroutine _NORMALIZE: called CC=1 SCAR=0.0
15 473 ▶sub _NO_VALIDATION () { return ':no_validation'; };
Subroutine _NO_VALIDATION: called CC=1 SCAR=0.0
16 445 ▶sub _DUMP () { return ':dump_to_stdout'; };
Subroutine _DUMP: called CC=1 SCAR=0.0
17 sub _DEBUG () { 0; };
18  
19 5 ▶sub _legal_option {
Subroutine _legal_option: called CC=1 SCAR=0.0
20 return {
21 _NORMALIZE() => 1,
22 _NO_VALIDATION() => 1,
23 _DUMP() => 1,
24 5 }->{$_[0]};
25 }
26  
27 ####
28  
29 4 ▶sub import {
Subroutine import: called CC=3 SCAR=11.8
30 4 my $class = shift;
31 4 my $options = {
32 _NORMALIZE() => 0,
33 _NO_VALIDATION() => 0,
34 _DUMP() => 0,
35 };
36 4 foreach my $item (@_) {
37 5 ▶ if (not _legal_option($item)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_legal_option($item)) 0 5 5
38 0 my $package = __PACKAGE__;
39 0 require Carp;
40 0 Carp::croak("'$item' not a valid option for 'use $package'\n");
41 }
42 5 $options->{$item} = 1;
43 }
44 4 $Acme::Sub::Parms::line_counter = 0;
45 4 my $ref = {'options' => $options, 'bind_block' => 0 };
46 4 filter_add(bless $ref); # imported from Filter::Util::Call
47 }
48  
49 ####
50  
51 28 ▶sub _parse_bind_spec {
Subroutine _parse_bind_spec: called CC=17 SCAR=31.3
52 28 my ($self, $raw_spec) = @_;
53  
54 28 my $spec = $raw_spec;
55  
56 28 my $spec_tokens = {
57 'is_defined' => 0,
58 'required' => 1,
59 'optional' => 0,
60 };
61 28 ▶ while ($spec ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec ne "") 56 28 84
62 56 ▶ if ($spec =~ s/^required(\s*,\s*|$)//) { # 'required' flag
Branch: 4 branches
BranchTrueFalseTotal
if ($spec =~ s/^required(\s*,\s*|$)//) { } 8 48 56
elsif ($spec =~ s/^optional(\s*,\s*|$)//) { } 16 32 48
elsif ($spec =~ s/^is_defined(\s*,\s*|$)//) { } 8 24 32
elsif ($spec =~ s/^(can|isa|type|callback|default)\s*=\s*//) { } 24 0 24
63 8 $spec_tokens->{'required'} = 1;
64 8 $spec_tokens->{'optional'} = 0;
65  
66 } elsif ($spec =~ s/^optional(\s*,\s*|$)//) { # 'optional' flag
67 16 $spec_tokens->{'required'} = 0;
68 16 $spec_tokens->{'optional'} = 1;
69  
70 } elsif ($spec =~ s/^is_defined(\s*,\s*|$)//) { # 'is_defined' flag
71 8 $spec_tokens->{'is_defined'} = 1;
72  
73 } elsif ($spec =~ s/^(can|isa|type|callback|default)\s*=\s*//) { # 'something="somevalue"'
74 24 my $spec_key = $1;
75  
76 # Simple unquoted text with no embedded ws
77 24 ▶ if ($spec =~ s/^([^\s"',]+)(\s*,\s*|$)//) {
Branch: 4 branches
BranchTrueFalseTotal
if ($spec =~ s/^([^\s"',]+)(\s*,\s*|$)//) { } 20 4 24
elsif ($spec =~ s[^'([^'/]+)'\s*,\s*][]) { } 0 4 4
elsif ($spec =~ s[^"([^"/]+)"\s*,\s*][]) { } 0 4 4
elsif ($spec =~ s/^(['"])//) { } 4 0 4
78 20 $spec_tokens->{$spec_key} = $1;
79  
80 # Single quoted text with no embedded quotes
81 } elsif ($spec =~ s/^'([^'\/]+)'\s*,\s*//) {
82 0 $spec_tokens->{$spec_key} = "'$1'";
83  
84 # Double quoted text with no embedded quotes or escapes
85 } elsif ($spec =~ s/^"([^"\/]+)"\s*,\s*//) {
86 0 $spec_tokens->{$spec_key} = '"' . $1 . '"';
87  
88 # It is a tricky case with quoted characters. One character at a time it is.
89 } elsif ($spec =~ s/^(['"])//) {
90 4 my $quote = $1;
91 4 my $upend_spec = reverse $spec;
92 4 my $block_done = 0;
93 4 my $escape_next = 0;
94 4 my $token = $quote;
95 4 ▶ until ($block_done || ($upend_spec eq '')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($block_done or $upend_spec eq "") 32 4 36
Condition66%2/3
$block_done or $upend_spec eq ""
l!l&&r!l&&!r
4032
MC/DC50%1/2
$block_done or $upend_spec eq ""
$block_done $upend_spec eq ""
Truth table66%2/3
A or B
A= $block_doneB= $upend_spec eq ""
ABresult
1X1
011
000
96 32 my $ch = chop $upend_spec;
97 32 ▶ if ($escape_next) {
Branch: 3 branches
BranchTrueFalseTotal
if ($escape_next) { } 0 32 32
elsif ($ch eq '\\' and not $escape_next) { } 0 32 32
elsif ($ch eq $quote) { } 4 28 32
98 0 $token .= $ch;
99 0 $escape_next = 0;
100  
101 ▶ } elsif (($ch eq "\\") && (not $escape_next)) {
Condition33%1/3
$ch eq "\\" and not $escape_next
!ll&&!rl&&r
3200
MC/DC0%0/2
$ch eq "\\" and not $escape_next
$ch eq "\\" not $escape_next
Truth table33%1/3
A and not(B)
A= $ch eq "\\"B= not $escape_next
ABresult
0X0
100
111
102 0 $token .= $ch;
103 0 $escape_next = 1;
104  
105 } elsif ($ch eq $quote) {
106 4 $block_done = 1;
107  
108 } else {
109 28 $token .= $ch;
110 }
111 }
112 4 ▶ if ($escape_next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escape_next) 0 4 4
113 0 die("Syntax error in BindParms spec: $raw_spec\n");
114 }
115 4 $spec = reverse $upend_spec;
116 4 $spec_tokens->{$spec_key} = $token . $quote;
117  
118 } else {
119 0 die("Syntax error in BindParms spec: $raw_spec\n");
120 }
121 } else {
122 0 die("Syntax error in BindParms spec: $raw_spec\n");
123 }
124 }
125 28 return $spec_tokens;
126 }
127  
128 ###############################################################################
129 # bind_spec is intentionally a a non-POD documented'public' method. It can be overridden in a sub-class
130 # to provide alternative features.
131 #
132 # It takes two parameters:
133 #
134 # $raw_spec - this is the content of the [....] block (not including the '[' and ']' block delimitters)
135 # $field_name - the hash key for the field being processed
136 #
137 # As each line of the BindParms block is processed the two parameters for each line are passed to the bind_spec
138 # method for evaluation. bind_spec should return a string containing any Perl code generated as a result of
139 # the bind specification.
140 #
141 # Good style dictates that the returned output should be *ONE* line (it could be a very *long* line)
142 # so that line numbering in the source file is preserved for any error messages.
143 #
144 28 ▶sub bind_spec {
Subroutine bind_spec: called CC=19 SCAR=29.6
Pod undocumented
145 28 my $self = shift;
146 28 my ($raw_spec, $field_name) = @_;
147  
148 28 my $options = $self->{'options'};
149 28 my $no_validation = $options->{_NO_VALIDATION()};
150  
151 28 my $spec_tokens = $self->_parse_bind_spec($raw_spec);
152  
153 28 my $has_side_effects = 0;
154 28 my $output = '';
155  
156 28 my @spec_tokens_list = keys %$spec_tokens;
157 28 ▶ if ((0 == @spec_tokens_list) || ((1 == @spec_tokens_list) && ($spec_tokens->{'optional'}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == @spec_tokens_list or 1 == @spec_tokens_list and $spec_tokens->{"optional"}) 0 28 28
Condition33%2/6
0 == @spec_tokens_list or 1 == @spec_tokens_list and $spec_tokens->{"optional"}
l!l&&r!l&&!r
0028
1 == @spec_tokens_list and $spec_tokens->{"optional"}
!ll&&!rl&&r
2800
MC/DC0%0/3
0 == @spec_tokens_list or 1 == @spec_tokens_list and $spec_tokens->{"optional"}
0 == @spec_tokens_list 1 == @spec_tokens_list $spec_tokens->{"optional"}
Truth table25%1/4
A or B and C
A= 0 == @spec_tokens_listB= 1 == @spec_tokens_listC= $spec_tokens->{"optional"}
ABCresult
1XX1
0111
00X0
0100
158 0 return;
159 }
160  
161 ######################
162 # default="some value"
163 28 ▶ if (defined $spec_tokens->{'default'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec_tokens->{"default"}) 4 24 28
164 4 ▶ if ($spec_tokens->{'optional'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec_tokens->{'optional'}) { } 4 0 4
165 4 $output .= "unless (exists (\$Acme::Sub::Parms::args\{'$field_name'\})) \{ \$Acme::Sub::Parms::args\{'$field_name'\} = " . $spec_tokens->{'default'} . ";\} ";
166 } else { # required
167 0 $output .= "unless (defined (\$Acme::Sub::Parms::args\{'$field_name'\})) \{ \$Acme::Sub::Parms::args\{'$field_name'\} = " . $spec_tokens->{'default'} . ";\} ";
168 }
169 4 $has_side_effects = 1;
170 }
171  
172 ######################
173 # callback="some_subroutine"
174 28 ▶ if ($spec_tokens->{'callback'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec_tokens->{"callback"}) 8 20 28
175 $output .= "\{ my (\$callback_is_valid, \$callback_error) = "
176 8 . $spec_tokens->{'callback'}
177 . "(\'$field_name\', \$Acme::Sub::Parms::args\{\'$field_name\'\}, \\\%Acme::Sub::Parms::args);"
178 . "unless (\$callback_is_valid) { require Carp; Carp::croak(\"$field_name error: \$callback_error\"); }} ";
179 8 $has_side_effects = 1;
180 }
181  
182 ######################
183 # required
184 28 ▶ if ((! $no_validation) && $spec_tokens->{'required'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $no_validation and $spec_tokens->{"required"}) 4 24 28
Condition100%3/3
not $no_validation and $spec_tokens->{"required"}
!ll&&!rl&&r
1684
MC/DC100%2/2
not $no_validation and $spec_tokens->{"required"}
not $no_validation $spec_tokens->{"required"}
Truth table100%3/3
not(A) and B
A= not $no_validationB= $spec_tokens->{"required"}
ABresult
0X0
100
111
185 4 $output .= "unless (exists (\$Acme::Sub::Parms::args\{\'$field_name\'\})) { require Carp; Carp::croak(\"Missing required parameter \'$field_name\'\"); } ";
186 }
187  
188 ######################
189 # is_defined
190 28 ▶ if ($spec_tokens->{'is_defined'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec_tokens->{"is_defined"}) 8 20 28
191 8 $output .= "if (exists (\$Acme::Sub::Parms::args\{\'$field_name\'\}) and (! defined (\$Acme::Sub::Parms::args\{\'$field_name\'\}))) { require Carp; Carp::croak(\"parameter \'$field_name\' cannot be undef\"); } ";
192 }
193  
194 28 my $type_requirements = $spec_tokens->{'type'};
195 28 my $isa_requirements = $spec_tokens->{'isa'};
196 28 my $can_requirements = $spec_tokens->{'can'};
197  
198 28 ▶ if (defined ($type_requirements ) || defined($isa_requirements) || defined($can_requirements)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type_requirements or defined $isa_requirements or defined $can_requirements) 12 16 28
Condition100%6/6
defined $type_requirements or defined $isa_requirements or defined $can_requirements
l!l&&r!l&&!r
8416
defined $type_requirements or defined $isa_requirements
l!l&&r!l&&!r
4420
MC/DC100%3/3
defined $type_requirements or defined $isa_requirements or defined $can_requirements
defined $type_requirements defined $isa_requirements defined $can_requirements
Truth table100%4/4
A or B or C
A= defined $type_requirementsB= defined $isa_requirementsC= defined $can_requirements
ABCresult
1XX1
01X1
0011
0000
199 12 $output .= "if (exists (\$Acme::Sub::Parms::args\{\'$field_name\'\})) \{";
200  
201 #####################
202 # type="SomeRefType" or type="SomeRefType, SomeOtherRefType, ..."
203 12 ▶ if (defined $type_requirements) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type_requirements) 4 8 12
204 4 $type_requirements =~ s/^['"]//;
205 4 $type_requirements =~ s/['"]$//;
206 4 my @type_classes = split(/[,\s]+/, $type_requirements);
207 4 $output .= "unless (";
208 4 my @type_tests = ();
209 4 foreach my $class_name (@type_classes) {
210 4 push (@type_tests, "ref(\$Acme::Sub::Parms::args\{'$field_name'\}) eq '$class_name')");
211 }
212 4 $output .= join(' || ',@type_tests) . " \{ require Carp; Carp::croak(\'parameter \\\'$field_name\\\' must be a " . join(' or ',@type_classes) . "\'); \}";
213 }
214  
215 #####################
216 # isa="SomeRefType" or isa="SomeRefType, SomeOtherRefType, ..."
217 12 ▶ if (defined $isa_requirements) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $isa_requirements) 4 8 12
218 4 $isa_requirements =~ s/^['"]//;
219 4 $isa_requirements =~ s/['"]$//;
220 4 my @isa_classes = split(/[,\s]+/, $isa_requirements);
221 4 $output .= "unless (";
222 4 my @isa_tests = ();
223 4 foreach my $class_name (@isa_classes) {
224 4 push (@isa_tests, "\$Acme::Sub::Parms::args\{'$field_name'\}->isa('$class_name')");
225 }
226 4 $output .= join(' || ',@isa_tests) . ") \{ require Carp; Carp::croak(\'parameter \\\'$field_name\\\' must be a " . join(' or ',@isa_classes) . " instance or subclass\'); \}";
227 }
228  
229 #####################
230 # can="somemethod" or can="somemethod, someothermethod, ..."
231 12 ▶ if (defined $can_requirements) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $can_requirements) 4 8 12
232 4 $can_requirements =~ s/^['"]//;
233 4 $can_requirements =~ s/['"]$//;
234 4 my @can_methods = split(/[,\s]+/, $can_requirements);
235 4 $output .= "unless (";
236 4 my @can_tests = ();
237 4 foreach my $method_name (@can_methods) {
238 4 push (@can_tests, "\$Acme::Sub::Parms::args\{'$field_name'\}->can('$method_name')");
239 }
240 4 $output .= join(' && ',@can_tests) . ") \{ require Carp; Carp::croak(\'parameter \\\'$field_name\\\' must be an object with a " . join(' and a ',@can_methods) . " method\'); \}";
241 }
242  
243 12 $output .= "\}";
244 }
245  
246 28 return ($has_side_effects,$output);
247 }
248  
249 ####
250  
251 436 ▶sub filter {
Subroutine filter: called CC=35 SCAR=37.1
Pod undocumented
252 436 my $self = shift;
253  
254 436 my $options = $self->{'options'};
255 436 my $dump_to_stdout = $options->{_DUMP()};
256 436 my $normalize = $options->{_NORMALIZE()};
257 436 my $no_validation = $options->{_NO_VALIDATION()};
258 436 my $bind_block = $self->{'bind_block'};
259  
260 436 my $status;
261  
262 436 ▶ if ($status = filter_read() > 0) { # imported from Filter::Util::Call
Branch: 1 branch
BranchTrueFalseTotal
if ($status = &filter_read() > 0) 432 4 436
263 432 $Acme::Sub::Parms::line_counter++;
264
265 432 if (_DEBUG) {
266 print STDERR "input line $Acme::Sub::Parms::line_counter: $_";
267 }
268
269 #############################################
270 # If we are in a bind block, handle it
271 432 ▶ if ($bind_block) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bind_block) { } 36 396 432
272 36 my $bind_entries = $self->{'bind_entries'};
273 36 my $simple_bind = $self->{'simple_bind'};
274  
275 ##############################
276 # Last line of the bind block? Generate the working code.
277 36 ▶ if (m/^\s*\)(\s*$|\s*#.*$)/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^\s*\)(\s*$|\s*#.*$)/) { } 4 32 36
elsif (() = /^\s*(\S.*?)\s+:\s+([^'"\s\[]+.*?)\s*(;\s*|;\s*#.*)$/) { } 28 4 32
elsif (/^(\s*|\s*#.*)$/) { } 4 0 4
278
279 4 my $block_trailing_comment = $2;
280 4 ▶ $block_trailing_comment = defined($block_trailing_comment) ? $block_trailing_comment : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $block_trailing_comment ? : 0 4 4
281 4 $block_trailing_comment =~ s/[\r\n]+$//s;
282 4 my $side_effects = 0;
283 4 my $args = 'local %Acme::Sub::Parms::args; '; # needed?
284 4 ▶ if ($normalize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($normalize) { } 2 2 4
285 2 $args .= '{ local $_; local %Acme::Sub::Parms::raw_args = @_; %Acme::Sub::Parms::args = map { lc($_) => $Acme::Sub::Parms::raw_args{$_} } keys %Acme::Sub::Parms::raw_args; }' . "\n";
286 } else {
287 2 $args .= '%Acme::Sub::Parms::args = @_;' . "\n";
288 }
289 # If we have validation or defaults, handle them
290 4 my $padding_lines = 0;
291 4 ▶ if (! $simple_bind) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($simple_bind) 4 0 4
292 4 my @parm_declarations = ();
293 4 foreach my $entry (@$bind_entries) {
294 32 my $variable_decl = $entry->{'variable'};
295 32 my $field_name = $entry->{'field'};
296 32 my $spec = $entry->{'spec'};
297 32 my $trailing_comment = $entry->{'trailing_comment'};
298 32 ▶ if ( (! defined($spec)) || ($spec eq '')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $spec or $spec eq "") 4 28 32
Condition66%2/3
not defined $spec or $spec eq ""
l!l&&r!l&&!r
0428
MC/DC50%1/2
not defined $spec or $spec eq ""
not defined $spec $spec eq ""
Truth table66%2/3
not(A) or B
A= not defined $specB= $spec eq ""
ABresult
1X1
011
000
299 # push(@parm_declarations, $trailing_comment);
300 4 next;
301 }
302 # The hard case. We have validation requirements.
303 28 my ($has_side_effects, $bind_spec_output) = $self->bind_spec($spec, $field_name);
304 28 $side_effects += $has_side_effects;
305 28 push (@parm_declarations, "$bind_spec_output$trailing_comment");
306 }
307 4 $args .= join("\n",@parm_declarations,'');
308 }
309  
310 # Generate the actual parameter data binding
311 4 my @var_declarations = ();
312 4 my @hard_var_declarations = ();
313 4 my @field_declarations = ();
314 4 my @fields_list = ();
315 4 foreach my $entry (@$bind_entries) {
316 32 my $spec = $entry->{'spec'};
317 32 ▶ next if ((not defined $spec) || ($spec eq ''));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $spec or $spec eq "" 4 28 32
Condition66%2/3
not defined $spec or $spec eq ""
l!l&&r!l&&!r
0428
MC/DC50%1/2
not defined $spec or $spec eq ""
not defined $spec $spec eq ""
Truth table66%2/3
not(A) or B
A= not defined $specB= $spec eq ""
ABresult
1X1
011
000
318 28 my $raw_var = $entry->{'variable'};
319 28 my $field_name = $entry->{'field'};
320
321 28 push (@fields_list, "'$field_name'");
322 28 my ($variable_name) = $raw_var =~ m/^my\s+(\S+)$/;
323 28 ▶ if (defined $variable_name) { # simple 'my $variable :' entries are special-cased for performance
Branch: 1 branch
BranchTrueFalseTotal
if (defined $variable_name) { } 28 0 28
324 28 push (@var_declarations, $variable_name);
325 28 push (@field_declarations, "'$field_name'");
326  
327 } else { # Otherwise make a seperate entry for this binding
328 0 push (@hard_var_declarations, "$raw_var = \$Acme::Sub::Parms::args\{$field_name\};");
329 }
330 }
331 4 my $hard_args = join(' ',@hard_var_declarations);
332 4 my $arg_line = '';
333 4 ▶ if (0 < @var_declarations) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < @var_declarations) 4 0 4
334
335 4 ▶ if ($simple_bind && (! $normalize) && $no_validation && (0 == $side_effects) && (0 == @hard_var_declarations)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($simple_bind and not $normalize and $no_validation and 0 == $side_effects and 0 == @hard_var_declarations) { } 0 4 4
Condition33%4/12
$simple_bind and not $normalize and $no_validation and 0 == $side_effects and 0 == @hard_var_declarations
!ll&&!rl&&r
400
$simple_bind and not $normalize and $no_validation and 0 == $side_effects
!ll&&!rl&&r
400
$simple_bind and not $normalize and $no_validation
!ll&&!rl&&r
400
$simple_bind and not $normalize
!ll&&!rl&&r
400
MC/DC0%0/5
$simple_bind and not $normalize and $no_validation and 0 == $side_effects and 0 == @hard_var_declarations
$simple_bind not $normalize $no_validation 0 == $side_effects 0 == @hard_var_declarations
Truth table16%1/6
A and not(B) and C and D and E
A= $simple_bindB= not $normalizeC= $no_validationD= 0 == $side_effectsE= 0 == @hard_var_declarations
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
336 0 $args = "\n my (" . join(",", @var_declarations) . ') = @{{@_}}{' . join(',',@field_declarations) . '}; ';
337  
338 } else {
339
340 4 $arg_line = 'my (' . join(",", @var_declarations) . ') = @Acme::Sub::Parms::args{' . join(',',@field_declarations) . '}; ';
341 }
342 }
343 4 my $unknown_parms_check = '';
344 4 ▶ unless ($no_validation) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($no_validation) 2 2 4
345 2 $unknown_parms_check = 'delete @Acme::Sub::Parms::args{' . join(',',@fields_list) . '}; if (0 < @Acme::Sub::Parms::args) { require Carp; Carp::croak(\'Unexpected parameters passed: \' . join(\', \',@Acme::Sub::Parms::args)); } ';
346  
347 }
348 4 $self->{'bind_block'} = 0;
349 4 my $original_block_length = $Acme::Sub::Parms::line_counter - $self->{'line_block_start'};
350 4 my $new_block = $args . join(' ',$arg_line, $hard_args, $unknown_parms_check) . "$block_trailing_comment\n";
351 4 $new_block =~ s/\n+/\n/gs;
352 4 my $new_block_lines = $new_block =~ m/\n/gs;
353
354 4 my $additional_lines = $original_block_length - $new_block_lines;
355 #warn("Need $additional_lines extra lines\n---\n$new_block---\n");
356 4 ▶ if ($additional_lines > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($additional_lines > 0) { } 4 0 4
357 4 $_ = $new_block . ("\n" x $additional_lines);
358 } else {
359 0 $_ = $new_block;
360 }
361  
362 ########################
363 # Bind block parameter line
364 } elsif (my($bind_var, $bind_field,$trailing_comment) = m/^\s*(\S.*?)\s+:\s+([^'"\s\[]+.*?)\s*(;\s*|;\s*#.*)$/) {
365 28 ▶ $trailing_comment = defined($trailing_comment) ? $trailing_comment : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $trailing_comment ? : 28 0 28
366 28 $trailing_comment =~ s/[\r\n]+$//s;
367 28 $trailing_comment =~ s/^;//;
368 28 my $bind_entry = { 'variable' => $bind_var, 'field' => $bind_field, trailing_comment => $trailing_comment };
369 28 push (@$bind_entries, $bind_entry);
370 28 ▶ if ($bind_var !~ m/^my \$\S+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bind_var =~ /^my \$\S+$/) 0 28 28
371 0 $self->{'simple_bind'} = 0;
372 }
373 28 ▶ if ($bind_field =~ m/^(\S+)\s*\[(.*)\]$/) { # Complex spec
Branch: 2 branches
BranchTrueFalseTotal
if ($bind_field =~ /^(\S+)\s*\[(.*)\]$/) { } 26 2 28
elsif ($bind_field =~ /^\w+$/) { } 2 0 2
374 26 $bind_entry->{'field'} = $1;
375 26 $bind_entry->{'spec'} = $2;
376 26 ▶ unless ($no_validation && ($bind_field !~ m/[\s\[,](default|callback)\s*=\s*/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($no_validation and not $bind_field =~ /[\s\[,](default|callback)\s*=\s*/) 18 8 26
Condition100%3/3
$no_validation and not $bind_field =~ /[\s\[,](default|callback)\s*=\s*/
!ll&&!rl&&r
1268
MC/DC100%2/2
$no_validation and not $bind_field =~ /[\s\[,](default|callback)\s*=\s*/
$no_validation not $bind_field =~ /[\s\[,](default|callback)\s*=\s*/
Truth table100%3/3
A and not(B)
A= $no_validationB= not $bind_field =~ /[\s\[,](default|callback)\s*=\s*/
ABresult
0X0
100
111
377 18 $self->{'simple_bind'} = 0;
378 }
379 } elsif ($bind_field =~ m/^\w+$/) { # my $thing : something;
380 2 $bind_entry->{'spec'} = 'required';
381 2 ▶ unless ($no_validation) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($no_validation) 0 2 2
382 0 $self->{'simple_bind'} = 0;
383 }
384 } else {
385 0 die("Failed to parse BindParms block line $Acme::Sub::Parms::line_counter: $_");
386 }
387 28 undef $trailing_comment;
388 28 undef $bind_var;
389 28 undef $bind_field;
390 28 $_ = '';
391  
392 ############################
393 # Blank and comment only lines
394 } elsif (m/^(\s*|\s*#.*)$/) {
395 4 my $trailing_comment = $1;
396 4 ▶ $trailing_comment = defined ($trailing_comment) ? $trailing_comment : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $trailing_comment ? : 4 0 4
397 4 $trailing_comment =~ s/[\r\n]+$//s;
398
399 4 my $bind_entry = { spec => '', trailing_comment => $trailing_comment};
400 4 push (@$bind_entries, $bind_entry);
401 4 $_ = '';
402
403 } else {
404 0 die("Failed to parse BindParms block line $Acme::Sub::Parms::line_counter: $_");
405 }
406  
407 } else { # Start of a bind block
408 396 ▶ if (m/^\s*BindParms\s+:\s+\((\s*#.*$|\s*$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*BindParms\s+:\s+\((\s*#.*$|\s*$)/) 4 392 396
409 4 $self->{'simple_bind'} = 1;
410 4 $self->{'bind_entries'} = [];
411 4 $self->{'bind_block'} = 1;
412 4 $self->{'line_block_start'} = $Acme::Sub::Parms::line_counter;
413 4 my $block_head_comment = $2;
414 4 ▶ $block_head_comment = defined ($block_head_comment) ? $block_head_comment : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $block_head_comment ? : 0 4 4
415 4 $block_head_comment =~ s/[\r\n]+$//s;
416 4 $_ = $block_head_comment;
417  
418 #######
419 # ################################
420 # # Invokation : $self;
421 # } elsif (my ($ihead,$ivar,$itail) = m/^(\s*)Invokation\s+:\s+(\S+.*?)\s*;(.*)$/) {
422 # $_ = $ihead . " my $ivar = shift @_;$itail\n";
423 #
424 # ################################
425 # # ParmsHash : %args;
426 # } elsif (my ($fhead,$func_hash_ident,$ftail) = m/^(\s*)ParmsHash\s+:\s+(\S+.*?)\s*;(.*)$/) {
427 # if ($normalize) {
428 # $_ = "${fhead}my $func_hash_ident; { local \%Acme::Sub::Parms::raw_args = \@\_; $func_hash_ident = map \{ lc(\$\_\) \=\> \$Acme::Sub::Parms::raw_args\{\$\_\} \} keys \%Acme::Sub::Parms::raw_args; } $ftail\n";
429 # } else {
430 # $_ = "${fhead}my $func_hash_ident = \@\_;$ftail\n";
431 # }
432 #
433 # ################################
434 # # MethodParms : $self, %args;
435 # } elsif (my ($mhead,$method_invokation,$method_hash_ident,$mtail) = m/^(\s*)MethodParms\s+:\s+(\S+.*?)\s*,\s*(\S+.*?)\s*;(.*)$/) {
436 # if ($normalize) {
437 # $_ = "${mhead}my $method_invokation = shift; my $method_hash_ident; { local \$_; local \%Acme::Sub::Parms::raw_args = \@\_; $method_hash_ident = map \{ lc(\$\_\) \=\> \$Acme::Sub::Parms::raw_args\{\$\_\} \} keys \%Acme::Sub::Parms::raw_args; } $mtail\n";
438 # } else {
439 # $_ = "${mhead}my $method_invokation = shift; my $method_hash_ident = \@\_; $mtail\n";
440 # }
441 #######
442 }
443 }
444 }
445 436 if (_DEBUG) {
446 print STDERR "output as: $_";
447 }
448 436 ▶ if ($dump_to_stdout) { print $_; }
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_to_stdout) 110 326 436
449  
450 436 return $status;
451 }
452  
453 ####
454  
455 5 1;
456  
↑ Summary