lib/Test/FitNesse/Slim/StatementExecutor.pm

filter: Statementstmt 97.2% 285 / 293 Branchbran 93.8% 152 / 162 Conditioncond 69.8% 37 / 53 MC/DCmcdc 50.0% 16 / 32 Subroutinesub 95.1% 39 / 41 Podpod 100% 23 / 23 totaltotal 91.3% 552 / 604 CC 109 SCAR 27.3
CC
109
Cov
93%
_call
40.6
create
12.0
exception_result
11.0
CRAP 15.4
↑ Summary lib/Test/FitNesse/Slim/Server.pm »
1 package Test::FitNesse::Slim::StatementExecutor;
2  
3 82 ▶use 5.36.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 82 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 82 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 82 ▶use HTML::TreeBuilder;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 82 ▶use Scalar::Util qw(reftype refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 82 ▶use Time::HiRes qw(alarm);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 82 ▶use Test::FitNesse::Slim::Statement;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 82 ▶use Test::FitNesse::Slim::SlimHelperLibrary;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 82 ▶use Test::FitNesse::Slim::MapResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 82 ▶use Test::FitNesse::Slim::ConverterRegistry;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 82 my $FIXTURE_HANDLES_SYMBOLS = "SLIM_AGENT_FIXTURE_HANDLES_SYMBOLS";
16  
17 174 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
18 174 my($class,%options) = @_;
19 my $self = bless {
20 imports => [],
21 instance => {},
22 library => [],
23 symbol => {},
24 fixture_symbol_pattern => undef,
25 stop_requested => undef,
26 converters => Test::FitNesse::Slim::ConverterRegistry->new,
27 statement_timeout => $options{statement_timeout},
28 174 } => $class;
29  
30 $self->{instance}{__slim_helper_library} =
31 174 Test::FitNesse::Slim::SlimHelperLibrary->new($self->{instance});
32 174 push @{ $self->{library} }, {
33 id => "__slim_helper_library",
34 object => $self->{instance}{__slim_helper_library},
35 174 };
36 174 $self;
37 }
38  
39 91 ▶sub add_import {
Subroutine add_import: called CC=1 SCAR=0.0
Pod documented
40 91 my($self, $prefix) = @_;
41 91 push @{ $self->{imports} }, $self->slim_to_perl_class($prefix);
42 }
43  
44 152 ▶sub path_to_class {
Subroutine path_to_class: called CC=1 SCAR=0.0
Pod documented
45 152 my($self,$name) = @_;
46 152 $name =~ s!::!/!g;
47 152 $name . ".pm";
48 }
49  
50 1 ▶sub require {
Subroutine require: called CC=2 SCAR=7.0
Pod documented
51 1 my($self,$class) = @_;
52 1 eval { require $self->path_to_class($class) };
53 1 ▶ return $class unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 1 1
54 1 chomp $@;
55 1 die "message:<<COULD_NOT_INVOKE_CONSTRUCTOR $class $@>>\n";
56 }
57  
58 236 ▶sub slim_to_perl_class {
Subroutine slim_to_perl_class: called CC=1 SCAR=0.0
Pod documented
59 236 my($self,$name) = @_;
60 236 $name =~ s/\s+(\w)/\u$1/g;
61 236 join "::" => map "\u$_", split /\.|::/, $name;
62 }
63  
64 142 ▶sub resolve_class {
Subroutine resolve_class: called CC=3 SCAR=11.0
Pod documented
65 142 my($self, $name) = @_;
66  
67 142 my $class = $self->slim_to_perl_class($name);
68  
69 # A nested import must remain usable when a page also imports its parent
70 # package (for example, table fixtures for fixture-managed symbols).
71 142 my @imports = reverse @{ $self->{imports} };
72 my @candidates = (
73 142 (map("${_}::${class}", sort { length($b) <=> length($a) } @imports)),
74 $class,
75 );
76  
77 142 for my $candidate (@candidates) {
78 150 my $path = $self->path_to_class($candidate);
79 150 ▶ return $candidate if eval { require $path; 1 };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { require $path; 1 } } 138 12 150
80 }
81  
82 4 die "message:<<NO_CLASS $class>>\n";
83 }
84  
85 727 ▶sub slim_to_perl_method {
Subroutine slim_to_perl_method: called CC=1 SCAR=0.0
Pod documented
86 727 my($self,$name) = @_;
87 # Split acronym suffixes from a following title-cased word, then ordinary
88 # lower/digit-to-upper camelCase boundaries. A final one-letter boundary
89 # handles names such as makeATestPage without splitting IPv6.
90 727 $name =~ s/([A-Z]{2,})([A-Z][a-z])/$1_$2/g;
91 727 $name =~ s/([a-z0-9])([A-Z])/$1_$2/g;
92 727 $name =~ s/([A-Z])([A-Z][a-z]+)(?!\d)/$1_$2/g;
93 727 lc $name;
94 }
95  
96 439 ▶sub _method_for {
Subroutine _method_for: called CC=7 SCAR=19.5
97 439 my ($self, $object, $requested) = @_;
98 439 ▶ return unless $object && ref $object;
Branch: 1 branch
BranchTrueFalseTotal
unless $object and ref $object 47 392 439
Condition66%2/3
$object and ref $object
!ll&&!rl&&r
470392
MC/DC50%1/2
$object and ref $object
$object ref $object
Truth table66%2/3
A and B
A= $objectB= ref $object
ABresult
0X0
100
111
99  
100 392 my $translated = $self->slim_to_perl_method($requested);
101 392 my @candidates = ($requested);
102 392 ▶ push @candidates, $translated if $translated ne $requested;
Branch: 1 branch
BranchTrueFalseTotal
if $translated ne $requested 203 189 392
103 392 for my $candidate (@candidates) {
104 588 ▶ return $candidate if $object->can($candidate);
Branch: 1 branch
BranchTrueFalseTotal
if $object->can($candidate) 308 280 588
105 }
106 # Perl's declared AUTOLOAD is an explicit dynamic-dispatch hook. Only use it
107 # after both concrete spellings have been checked.
108 84 ▶ return $requested if $object->can('AUTOLOAD');
Branch: 1 branch
BranchTrueFalseTotal
if $object->can("AUTOLOAD") 2 82 84
109 82 return;
110 }
111  
112 102 ▶sub _enum_types_for {
Subroutine _enum_types_for: called CC=3 SCAR=11.0
113 102 my ($self, $fixture) = @_;
114 102 ▶ my $class = ref($fixture) || $fixture;
Condition66%2/3
ref $fixture || $fixture
l!l&&r!l&&!r
88140
MC/DC0%0/2
ref $fixture || $fixture
ref $fixture $fixture
Truth table66%2/3
A || B
A= ref $fixtureB= $fixture
ABresult
1X1
011
000
115 102 ▶ return {} unless $class->can('slim_enum_types');
Branch: 1 branch
BranchTrueFalseTotal
unless $class->can("slim_enum_types") 65 37 102
116 37 return $self->{converters}->validate_enum_types($class->slim_enum_types);
117 }
118  
119 146 ▶sub create {
Subroutine create: called CC=12 SCAR=24.8
Pod documented
120 146 my($self,$id,$class,$args) = @_;
121 146 my $is_library = $id =~ /^library/;
122 146 my ($registered, $had_instance, $previous_instance, $library_entry);
123  
124 146 eval {
125 146 ($class) = $self->replace_symbols($class);
126  
127 146 my $object;
128 146 ▶ if (ref $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) { } 4 142 146
129 4 $object = $class;
130 }
131 else {
132 142 $class = $self->resolve_class($class);
133 138 my @constructor_args =
134 $self->replace_tables_with_hashes($self->replace_symbols(@$args));
135 138 ▶ my $signature = $class->can('slim_constructor_signature')
Branch: 1 branch
BranchTrueFalseTotal
$class->can('slim_constructor_signature') ? : 14 124 138
136 ? $class->slim_constructor_signature
137 : undef;
138 138 ▶ if ($signature) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature) 14 124 138
139 14 $signature = {
140 %$signature,
141 enum_types => $self->_enum_types_for($class),
142 };
143 }
144 $self->{converters}->validate_arity(
145 138 $signature, "$class constructor", scalar @constructor_args,
146 'constructor', $class
147 );
148 @constructor_args = $self->{converters}->convert_arguments(
149 134 ▶ $signature, "$class constructor", @constructor_args
Branch: 1 branch
BranchTrueFalseTotal
if $signature 10 124 134
150 ) if $signature;
151 132 ▶ $object = $self->_timed(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
152 132 $class->new(@constructor_args);
153 132 });
154 }
155  
156 132 ▶ if ($is_library) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_library) { } 21 111 132
157 21 $library_entry = { id => $id, object => $object };
158 21 push @{ $self->{library} }, $library_entry;
159 21 $registered = 1;
160 }
161 else {
162 111 $had_instance = exists $self->{instance}{$id};
163 111 ▶ $previous_instance = $self->{instance}{$id} if $had_instance;
Branch: 1 branch
BranchTrueFalseTotal
if $had_instance 6 105 111
164 111 $self->{instance}{$id} = $object;
165 111 $registered = 1;
166 }
167 132 ▶ $object->set_statement_executor($self)
Branch: 1 branch
BranchTrueFalseTotal
if $object->can("set_statement_executor") 12 120 132
168 if $object->can('set_statement_executor');
169 };
170 146 ▶ return "OK" unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 128 18 146
171  
172 18 my $error = $@;
173 18 ▶ if ($registered) {
Branch: 1 branch
BranchTrueFalseTotal
if ($registered) 4 14 18
174 4 ▶ if ($is_library) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_library) { } 2 2 4
elsif ($had_instance) { } 1 1 2
175 2 my $entry_id = refaddr($library_entry);
176 6 @{ $self->{library} } = grep { refaddr($_) != $entry_id }
177 2 @{ $self->{library} };
178 }
179 elsif ($had_instance) {
180 1 $self->{instance}{$id} = $previous_instance;
181 }
182 else {
183 1 delete $self->{instance}{$id};
184 }
185 }
186  
187 18 $self->exception_result($error, 1);
188 }
189  
190 0 ▶sub construct_instance {
Subroutine construct_instance: not called CC=2 SCAR=17.9
Pod documented
191 0 my($self,$id,$class,$args) = @_;
192  
193 0 eval {
194 0 $self->{instance}{$id} = $class->new(
195 $self->replace_tables_with_hashes($self->replace_symbols(@$args))
196 );
197 };
198 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
199 0 return $self->{instance}{$id};
200 }
201  
202 625 ▶sub replace_symbols {
Subroutine replace_symbols: called CC=9 SCAR=22.0
Pod documented
203 625 my($self,@args) = @_;
204  
205 625 my @result;
206 625 for (@args) {
207 405 ▶ if (ref $_ eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_ eq 'ARRAY') { } 25 380 405
elsif (defined $_ and not ref $_ and /^\$(\w+)\z/u) { } 38 342 380
208 25 push @result, [ $self->replace_symbols(@$_) ];
209 }
210 ▶ elsif (defined($_) && !ref($_) && /^\$(\w+)\z/) {
Condition83%5/6
defined $_ and not ref $_ and /^\$(\w+)\z/u
!ll&&!rl&&r
433838
defined $_ and not ref $_
!ll&&!rl&&r
04376
MC/DC66%2/3
defined $_ and not ref $_ and /^\$(\w+)\z/u
defined $_ not ref $_ /^\$(\w+)\z/u
Truth table75%3/4
A and not(B) and C
A= defined $_B= not ref $_C= /^\$(\w+)\z/u
ABCresult
0XX0
10X0
1100
1111
211 38 my $name = $1;
212 push @result, exists $self->{symbol}{$name}
213 38 ▶ ? $self->{symbol}{$name}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'symbol'}{$name} ? : 36 2 38
214 : $_;
215 }
216 else {
217 342 s{ (?<orig> \$ (?<sym> \w+ ) ) } [
218 exists $self->{symbol}{$+{sym}}
219 ? (defined $self->{symbol}{$+{sym}} ? $self->{symbol}{$+{sym}} : 'null')
220 : $+{orig}
221 8 ▶ ]gex;
Branch: 2 branches
BranchTrueFalseTotal
exists $self->{'symbol'}{$+{'sym'}} ? : 5 3 8
defined $self->{'symbol'}{$+{'sym'}} ? : 4 1 5
222 342 push @result, $_;
223 }
224 }
225  
226 625 @result;
227 }
228  
229 448 ▶sub replace_tables_with_hashes {
Subroutine replace_tables_with_hashes: called CC=1 SCAR=0.0
Pod documented
230 448 my($self,@args) = @_;
231 448 map $self->replace_table_with_hash($_), @args;
232 }
233  
234 229 ▶sub replace_table_with_hash {
Subroutine replace_table_with_hash: called CC=9 SCAR=22.0
Pod documented
235 229 my($self,$arg) = @_;
236 229 ▶ return $arg unless defined($arg) && !ref($arg);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg and not ref $arg 32 197 229
Condition100%3/3
defined $arg and not ref $arg
!ll&&!rl&&r
230197
MC/DC100%2/2
defined $arg and not ref $arg
defined $arg not ref $arg
Truth table100%3/3
A and not(B)
A= defined $argB= not ref $arg
ABresult
0X0
100
111
237  
238 197 my $hash = eval {
239 197 my $p = HTML::TreeBuilder->new_from_content($arg);
240 197 my $table = $p->guts->look_down(_tag => "table");
241 191 ▶ die "no table" unless $table;
Branch: 1 branch
BranchTrueFalseTotal
unless $table 182 9 191
242  
243 9 my %result;
244 9 foreach my $row ($table->look_down(_tag => "tr")) {
245 13 my @cols = map $_->content_list, $row->look_down(_tag => "td");
246 13 ▶ die "bad columns"
Branch: 1 branch
BranchTrueFalseTotal
unless @cols == 2 and grep((!ref($_)), @cols) 3 10 13
Condition66%2/3
@cols == 2 and grep((!ref($_)), @cols)
!ll&&!rl&&r
3010
MC/DC50%1/2
@cols == 2 and grep((!ref($_)), @cols)
@cols == 2 grep((!ref($_)), @cols)
Truth table66%2/3
A and B
A= @cols == 2B= grep((!ref($_)), @cols)
ABresult
0X0
100
111
247 unless @cols == 2 && grep(!ref($_), @cols);
248 10 s/^\s+//, s/\s+$// for @cols;
249 10 $result{ $cols[0] } = $cols[1];
250 }
251  
252 6 \%result;
253 };
254  
255 197 ▶ return $@ eq "" ? $hash : $arg;
Branch: 1 branch
BranchTrueFalseTotal
$@ eq '' ? : 6 191 197
256 }
257  
258 28 ▶sub instance {
Subroutine instance: called CC=5 SCAR=16.1
Pod documented
259 28 my($self,$id) = @_;
260 28 ▶ return $self->{instance}{$id} if exists $self->{instance}{$id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"instance"}{$id} 20 8 28
261 8 ▶ if ($id =~ /^library/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /^library/u) 5 3 8
262 5 for my $library (@{ $self->{library} }) {
263 13 ▶ return $library->{object} if $library->{id} eq $id;
Branch: 1 branch
BranchTrueFalseTotal
if $library->{"id"} eq $id 5 8 13
264 }
265 }
266 3 return;
267 }
268  
269 58 ▶sub set_symbol {
Subroutine set_symbol: called CC=4 SCAR=13.9
Pod documented
270 58 my($self,$symbol,$value) = @_;
271 58 $self->{symbol}{$symbol} = $value;
272 58 ▶ if ($symbol eq $FIXTURE_HANDLES_SYMBOLS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol eq $FIXTURE_HANDLES_SYMBOLS) 4 54 58
273 4 $self->{fixture_symbol_pattern} = undef;
274 4 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 2 4
275 2 my $pattern = eval { qr/$value/ };
276 2 ▶ $self->{fixture_symbol_pattern} = $pattern unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 2 0 2
277 }
278 }
279 58 return $value;
280 }
281  
282 19 ▶sub get_symbol {
Subroutine get_symbol: called CC=1 SCAR=0.0
Pod documented
283 19 my($self,$symbol,$value) = @_;
284 19 $self->{symbol}{$symbol};
285 }
286  
287 3 ▶sub add_converter {
Subroutine add_converter: called CC=1 SCAR=0.0
Pod documented
288 3 my ($self, @args) = @_;
289 3 $self->{converters}->add_converter(@args);
290 }
291  
292 3 ▶sub get_converter {
Subroutine get_converter: called CC=1 SCAR=0.0
Pod documented
293 3 my ($self, @args) = @_;
294 3 $self->{converters}->get_converter(@args);
295 }
296  
297 0 ▶sub reset_converters {
Subroutine reset_converters: not called CC=1 SCAR=6.9
Pod documented
298 0 my ($self) = @_;
299 0 $self->{converters}->reset;
300 0 return;
301 }
302  
303 290 ▶sub call {
Subroutine call: called CC=2 SCAR=6.9
Pod documented
304 290 my($self,@args) = @_;
305 290 my $result = $self->_call(@args);
306 290 ▶ return defined($result) ? $result : "null";
Branch: 1 branch
BranchTrueFalseTotal
defined $result ? : 257 33 290
307 }
308  
309 35 ▶sub call_and_assign {
Subroutine call_and_assign: called CC=4 SCAR=13.9
Pod documented
310 35 my($self,$symbol,@args) = @_;
311 35 my ($result, $raw_result) = $self->_call(@args);
312 $self->set_symbol($symbol, ref($raw_result) ? $raw_result : $result)
313 35 ▶ unless $self->{call_failed};
Branch: 2 branches
BranchTrueFalseTotal
unless $self->{"call_failed"} 34 1 35
ref $raw_result ? : 13 21 34
314 35 ▶ return defined($result) ? $result : "null";
Branch: 1 branch
BranchTrueFalseTotal
defined $result ? : 32 3 35
315 }
316  
317 325 ▶sub _call {
Subroutine _call: called CC=40 SCAR=37.0
318 325 my($self,$instance,$method,@args) = @_;
319 325 $self->{call_failed} = 0;
320  
321 325 my $requested_method = $method;
322 325 my $translated_method = $self->slim_to_perl_method($method);
323  
324 # FitNesse routes this helper call through the reserved "null" actor.
325 325 ▶ if ($instance eq "null" && $translated_method eq "clone_symbol" && @args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($instance eq "null" and $translated_method eq "clone_symbol" and @args == 1) 3 322 325
Condition66%4/6
$instance eq "null" and $translated_method eq "clone_symbol" and @args == 1
!ll&&!rl&&r
32203
$instance eq "null" and $translated_method eq "clone_symbol"
!ll&&!rl&&r
32203
MC/DC33%1/3
$instance eq "null" and $translated_method eq "clone_symbol" and @args == 1
$instance eq "null" $translated_method eq "clone_symbol" @args == 1
Truth table50%2/4
A and B and C
A= $instance eq "null"B= $translated_method eq "clone_symbol"C= @args == 1
ABCresult
0XX0
10X0
1100
1111
326 3 return ($self->replace_symbols(@args))[0];
327 }
328  
329 322 my $has_instance = exists $self->{instance}{$instance};
330 322 my $obj = $self->{instance}{$instance};
331 322 ▶ if (!$has_instance && $instance =~ /^library/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $has_instance and $instance =~ /^library/u) 6 316 322
Condition100%3/3
not $has_instance and $instance =~ /^library/u
!ll&&!rl&&r
306106
MC/DC100%2/2
not $has_instance and $instance =~ /^library/u
not $has_instance $instance =~ /^library/u
Truth table100%3/3
not(A) and B
A= not $has_instanceB= $instance =~ /^library/u
ABresult
0X0
100
111
332 6 for my $library (@{ $self->{library} }) {
333 15 ▶ if ($library->{id} eq $instance) {
Branch: 1 branch
BranchTrueFalseTotal
if ($library->{"id"} eq $instance) 6 9 15
334 6 $obj = $library->{object};
335 6 $has_instance = 1;
336 6 last;
337 }
338 }
339 }
340 322 my $method_obj;
341 322 ▶ my $invoked_method = $has_instance
Branch: 1 branch
BranchTrueFalseTotal
$has_instance ? : 312 10 322
342 ? $self->_method_for($obj, $requested_method)
343 : undef;
344 322 ▶ $method_obj = $obj if $invoked_method;
Branch: 1 branch
BranchTrueFalseTotal
if $invoked_method 256 66 322
345  
346 322 ▶ unless ($method_obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($method_obj) 66 256 322
347 66 ▶ my $sut = $has_instance ? $self->_system_under_test($obj) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$has_instance ? : 56 10 66
348 66 $invoked_method = $self->_method_for($sut, $requested_method);
349 66 ▶ $method_obj = $sut if $invoked_method;
Branch: 1 branch
BranchTrueFalseTotal
if $invoked_method 12 54 66
350 }
351 322 ▶ unless ($has_instance) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_instance) 10 312 322
352 10 for my $lib_id (reverse @{ $self->{library} }) {
353 10 my $lib = $lib_id->{object};
354 10 ▶ next unless $lib && ref $lib;
Branch: 1 branch
BranchTrueFalseTotal
unless $lib and ref $lib 0 10 10
Condition33%1/3
$lib and ref $lib
!ll&&!rl&&r
0010
MC/DC0%0/2
$lib and ref $lib
$lib ref $lib
Truth table33%1/3
A and B
A= $libB= ref $lib
ABresult
0X0
100
111
355 10 ▶ if (my $candidate = $self->_method_for($lib, $requested_method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $candidate = $self->_method_for($lib, $requested_method)) 6 4 10
356 6 $obj = $lib;
357 6 $method_obj = $lib;
358 6 $invoked_method = $candidate;
359 6 last;
360 }
361 }
362 10 ▶ return $Test::FitNesse::Slim::Statement::EXCEPTION_TAG
Branch: 1 branch
BranchTrueFalseTotal
unless $obj 4 6 10
363 . "message:<<NO_INSTANCE $instance.$requested_method.>>"
364 unless $obj;
365 }
366  
367 318 ▶ unless ($method_obj && $invoked_method) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($method_obj and $invoked_method) 44 274 318
Condition66%2/3
$method_obj and $invoked_method
!ll&&!rl&&r
440274
MC/DC50%1/2
$method_obj and $invoked_method
$method_obj $invoked_method
Truth table66%2/3
A and B
A= $method_objB= $invoked_method
ABresult
0X0
100
111
368 44 for my $lib_id (reverse @{ $self->{library} }) {
369 51 my $lib = $lib_id->{object};
370 51 ▶ next unless $lib && ref $lib;
Branch: 1 branch
BranchTrueFalseTotal
unless $lib and ref $lib 0 51 51
Condition33%1/3
$lib and ref $lib
!ll&&!rl&&r
0051
MC/DC0%0/2
$lib and ref $lib
$lib ref $lib
Truth table33%1/3
A and B
A= $libB= ref $lib
ABresult
0X0
100
111
371 51 ▶ if (my $candidate = $self->_method_for($lib, $requested_method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $candidate = $self->_method_for($lib, $requested_method)) 36 15 51
372 36 $method_obj = $lib;
373 36 $invoked_method = $candidate;
374 36 last;
375 }
376 }
377 }
378  
379 318 my $n = @args;
380 318 my $class = ref $obj;
381 318 ▶ return $Test::FitNesse::Slim::Statement::EXCEPTION_TAG
Branch: 1 branch
BranchTrueFalseTotal
unless $method_obj and $invoked_method 8 310 318
Condition66%2/3
$method_obj and $invoked_method
!ll&&!rl&&r
80310
MC/DC50%1/2
$method_obj and $invoked_method
$method_obj $invoked_method
Truth table66%2/3
A and B
A= $method_objB= $invoked_method
ABresult
0X0
100
111
382 . "message:<<NO_METHOD_IN_CLASS $requested_method\[$n] $class>>"
383 unless $method_obj && $invoked_method;
384  
385 310 my ($result, $raw_result, $retain_raw_result);
386 310 eval {
387 310 my @call_args = @args;
388 310 ▶ unless ($self->{fixture_symbol_pattern}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"fixture_symbol_pattern"} and ("$instance.$requested_method") =~ /\A(?:$self->{"fixture_symbol_pattern"})\z/u) 308 2 310
Condition66%2/3
$self->{"fixture_symbol_pattern"} and ("$instance.$requested_method") =~ /\A(?:$self->{"fixture_symbol_pattern"})\z/u
!ll&&!rl&&r
30802
MC/DC50%1/2
$self->{"fixture_symbol_pattern"} and ("$instance.$requested_method") =~ /\A(?:$self->{"fixture_symbol_pattern"})\z/u
$self->{"fixture_symbol_pattern"} ("$instance.$requested_method") =~ /\A(?:$self->{"fixture_symbol_pattern"})\z/u
Truth table66%2/3
A and B
A= $self->{"fixture_symbol_pattern"}B= ("$instance.$requested_method") =~ /\A(?:$self->{"fixture_symbol_pattern"})\z/u
ABresult
0X0
100
111
389 && "$instance.$requested_method" =~ /\A(?:$self->{fixture_symbol_pattern})\z/) {
390 308 @call_args = $self->replace_symbols(@call_args);
391 }
392 310 @call_args = $self->replace_tables_with_hashes(@call_args);
393 310 ▶ my $signature = $method_obj->can('slim_method_signature')
Branch: 1 branch
BranchTrueFalseTotal
$method_obj->can('slim_method_signature') ? : 104 206 310
394 ? $method_obj->slim_method_signature($invoked_method)
395 : undef;
396 310 ▶ if ($signature) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature) 88 222 310
397 88 $signature = {
398 %$signature,
399 enum_types => $self->_enum_types_for($method_obj),
400 };
401 }
402 $self->{converters}->validate_arity(
403 310 $signature, $requested_method, scalar @call_args,
404 'method', ref($method_obj)
405 );
406 @call_args = $self->{converters}->convert_arguments(
407 303 ▶ $signature, $requested_method, @call_args
Branch: 1 branch
BranchTrueFalseTotal
if $signature 81 222 303
408 ) if $signature;
409 295 ▶ $result = $self->_timed(sub { $method_obj->$invoked_method(@call_args) });
Subroutine __ANON__: called CC=1 SCAR=0.0
410 269 $raw_result = $result;
411 $retain_raw_result = $signature
412 && $self->{converters}->is_typed_sequence(
413 $signature->{return}, $signature->{enum_types}
414 269 ▶ );
Condition100%3/3
$signature && $self->{'converters'}->is_typed_sequence($signature->{'return'}, $signature->{'enum_types'})
!ll&&!rl&&r
1965815
MC/DC100%2/2
$signature && $self->{'converters'}->is_typed_sequence($signature->{'return'}, $signature->{'enum_types'})
$signature $self->{'converters'}->is_typed_sequence($signature->{'return'}, $signature->{'enum_types'})
Truth table100%3/3
A && B
A= $signatureB= $self->{'converters'}->is_typed_sequence($signature->{'return'}, $signature->{'enum_types'})
ABresult
0X0
100
111
415 269 ▶ ($result) = $self->{converters}->convert_result($signature, $result)
Branch: 1 branch
BranchTrueFalseTotal
if $signature 73 196 269
416 if $signature;
417 268 ▶ $result = Test::FitNesse::Slim::MapResult->convert($result)
Branch: 1 branch
BranchTrueFalseTotal
if ref $result eq "HASH" 3 265 268
418 if ref($result) eq "HASH";
419 };
420 310 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 268 42 310
421 268 ▶ $result =~ s/\s+$// if defined($result) && !ref($result);
Branch: 1 branch
BranchTrueFalseTotal
if defined $result and not ref $result 212 56 268
Condition100%3/3
defined $result and not ref $result
!ll&&!rl&&r
3620212
MC/DC100%2/2
defined $result and not ref $result
defined $result not ref $result
Truth table100%3/3
A and not(B)
A= defined $resultB= not ref $result
ABresult
0X0
100
111
422 return wantarray
423 268 ▶ ? ($result, $retain_raw_result ? $raw_result : undef)
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 33 235 268
$retain_raw_result ? : 14 19 33
424 : $result;
425 }
426  
427 42 $self->{call_failed} = 1;
428 42 $self->exception_result($@)
429 }
430  
431 60 ▶sub exception_result {
Subroutine exception_result: called CC=11 SCAR=24.0
Pod documented
432 60 my($self,$error,$pretty_print) = @_;
433 60 chomp $error;
434  
435 60 ▶ return $Test::FitNesse::Slim::Statement::EXCEPTION_TAG . $error
Branch: 1 branch
BranchTrueFalseTotal
if $error =~ /^message:<<.*?>>\nTried to invoke: .*$/su 21 39 60
436 if $error =~ /^message:<<.*?>>\nTried to invoke: .*$/s;
437  
438 39 ▶ return $Test::FitNesse::Slim::Statement::EXCEPTION_TAG . $error
Branch: 1 branch
BranchTrueFalseTotal
if $error =~ /^message:<<.*>>$/su 7 32 39
439 if $error =~ /^message:<<.*>>$/s;
440  
441 32 ▶ if ($error =~ /^[\w.\$]*IgnoreScriptTest[\w.\$]*:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /^[\w.\$]*IgnoreScriptTest[\w.\$]*:/u) 1 31 32
442 1 $self->{stop_requested} = 'ignore_script';
443 1 return $Test::FitNesse::Slim::Statement::EXCEPTION_TAG . 'IGNORE_SCRIPT_TEST:';
444 }
445 31 ▶ if ($error =~ /^[\w.\$]*IgnoreAllTests[\w.\$]*:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /^[\w.\$]*IgnoreAllTests[\w.\$]*:/u) 3 28 31
446 3 $self->{stop_requested} = 'ignore_all';
447 3 return $Test::FitNesse::Slim::Statement::EXCEPTION_TAG . 'IGNORE_ALL_TESTS:';
448 }
449  
450 28 ▶ if ($error =~ /([\w.\$]*StopTest\w*Exception):\s*(.*)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /([\w.\$]*StopTest\w*Exception):\s*(.*)/su) 2 26 28
451 2 $self->{stop_requested} = 'test';
452 2 ▶ return $Test::FitNesse::Slim::Statement::EXCEPTION_TAG
Branch: 1 branch
BranchTrueFalseTotal
$pretty_print ? : 0 2 2
453 . "ABORT_SLIM_TEST:"
454 . ($pretty_print ? "message:<<$1: $2>>" : "$1: $2");
455 }
456 26 ▶ if ($error =~ /([\w.\$]*StopSuite\w*Exception):\s*(.*)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /([\w.\$]*StopSuite\w*Exception):\s*(.*)/su) 1 25 26
457 1 $self->{stop_requested} = 'suite';
458 1 ▶ return $Test::FitNesse::Slim::Statement::EXCEPTION_TAG
Branch: 1 branch
BranchTrueFalseTotal
$pretty_print ? : 1 0 1
459 . "ABORT_SLIM_SUITE:"
460 . ($pretty_print ? "message:<<$1: $2>>" : "$1: $2");
461 }
462  
463 25 ▶ if ($error =~ /^((?:java|fitnesse)\.[\w.\$]+):\s*(.*)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /^((?:java|fitnesse)\.[\w.\$]+):\s*(.*)/su) 13 12 25
464 13 ▶ return $Test::FitNesse::Slim::Statement::EXCEPTION_TAG
Branch: 1 branch
BranchTrueFalseTotal
$pretty_print ? : 1 12 13
465 . ($pretty_print ? "message:<<$1: $2>>" : "$1: $2");
466 }
467  
468 12 $Test::FitNesse::Slim::Statement::EXCEPTION_TAG . "message:<<$error>>"
469 }
470  
471 427 ▶sub _timed {
Subroutine _timed: called CC=5 SCAR=16.1
472 427 my($self,$code) = @_;
473 427 my $timeout = $self->{statement_timeout};
474 427 ▶ return $code->() unless defined $timeout;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout 422 5 427
475  
476 5 my $previous = alarm 0;
477 5 ▶ local $SIG{ALRM} = sub { die "message:<<TIMED_OUT $timeout>>\n" };
Subroutine __ANON__: called CC=1 SCAR=0.0
478 5 my($result,$ok,$error);
479 5 $ok = eval {
480 5 alarm $timeout;
481 5 $result = $code->();
482 4 1;
483 };
484 5 ▶ $error = $@ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 4 5
485 5 alarm 0;
486 5 ▶ alarm $previous if $previous;
Branch: 1 branch
BranchTrueFalseTotal
if $previous 0 5 5
487 5 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 4 5
488 4 return $result;
489 }
490  
491 389 ▶sub stop_requested { $_[0]->{stop_requested} }
Subroutine stop_requested: called CC=1 SCAR=0.0
Pod documented
492 130 ▶sub reset_stop_requested { $_[0]->{stop_requested} = undef }
Subroutine reset_stop_requested: called CC=1 SCAR=0.0
Pod documented
493  
494 56 ▶sub _system_under_test {
Subroutine _system_under_test: called CC=6 SCAR=19.0
495 56 my($self,$fixture) = @_;
496 56 ▶ return unless ref($fixture) && (reftype($fixture) || '') eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fixture and (builtin::reftype($fixture) || "") eq "HASH" 0 56 56
Condition40%2/5
ref $fixture and (builtin::reftype($fixture) || "") eq "HASH"
!ll&&!rl&&r
0056
builtin::reftype($fixture) || ''
l!l
560
MC/DC0%0/2
ref $fixture and (builtin::reftype($fixture) || "") eq "HASH"
ref $fixture builtin::reftype($fixture)
Truth table33%1/3
A and B
A= ref $fixtureB= builtin::reftype($fixture)
ABresult
0X0
100
111
497 my $sut = exists $fixture->{system_under_test}
498 ? $fixture->{system_under_test}
499 56 ▶ : $fixture->{systemUnderTest};
Branch: 1 branch
BranchTrueFalseTotal
exists $fixture->{'system_under_test'} ? : 18 38 56
500 56 ▶ return ref($sut) ? $sut : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $sut ? : 19 37 56
501 }
502  
503 82 1;
504  
505 =head1 NAME
506  
507 Test::FitNesse::Slim::StatementExecutor - Own fixture and symbol state for a SLiM session
508  
509 =head1 DESCRIPTION
510  
511 The statement executor owns imported Perl package prefixes, actors,
512 registered libraries, symbols, stop state, and a per-session
513 L<Test::FitNesse::Slim::ConverterRegistry>. It resolves fixture classes and methods,
514 constructs fixtures, substitutes symbols, applies declared conversions,
515 dispatches calls, and formats results and exceptions.
516  
517 Method dispatch checks an actor first, then its declared system under test,
518 then registered libraries newest-first. Fixture class imports prefer the
519 most-specific imported package; later imports win among equally specific
520 candidates. Failed construction restores executor-owned actor or library
521 registration state. These rules preserve the current Perl fixture model and
522 do not implement Java reflection or overload selection.
523  
524 =head1 METHODS
525  
526 =head2 new
527  
528 my $executor = Test::FitNesse::Slim::StatementExecutor->new(%options);
529  
530 Create isolated session state. C<statement_timeout> optionally bounds each
531 fixture invocation.
532  
533 =head2 add_import
534  
535 Register a FitNesse import prefix for later fixture class resolution.
536  
537 =head2 path_to_class and require
538  
539 C<path_to_class> maps a Perl package name to its module path. C<require>
540 loads that module and wraps load errors as constructor-resolution errors.
541 Both methods are internal class-loading helpers.
542  
543 =head2 slim_to_perl_class and slim_to_perl_method
544  
545 Translate FitNesse-style fixture class names and method names to Perl
546 package and snake_case spellings. Method invocation checks the exact
547 requested name before the translated spelling.
548  
549 =head2 resolve_class
550  
551 Resolve and load a fixture class using the imported package precedence.
552 Return its Perl package name or throw a structured C<NO_CLASS> error.
553  
554 =head2 create
555  
556 my $result = $executor->create($id, $class, \@arguments);
557  
558 Construct a fixture and register it as an actor or library according to
559 its identifier. Declared constructor arity and conversions are validated
560 before construction. A constructor or initialization failure returns a
561 structured SLiM exception and does not leave a partial executor
562 registration.
563  
564 =head2 instance
565  
566 Return an actor or explicitly named library object by identifier, or
567 C<undef> when none is registered.
568  
569 =head2 construct_instance
570  
571 Construct and register an already-resolved class directly. This lower-level
572 helper is retained for internal callers; normal SLiM C<make> instructions
573 use C<create> so conversion, initialization, and registration rollback are
574 applied.
575  
576 =head2 replace_symbols
577  
578 Resolve exact symbol references without stringifying their values, and
579 interpolate embedded scalar references. Return the transformed values in
580 argument order.
581  
582 =head2 replace_tables_with_hashes and replace_table_with_hash
583  
584 Convert FitNesse two-column HTML tables to Perl hashes where fixture
585 arguments use table data. Non-table strings pass through unchanged.
586  
587 =head2 set_symbol
588  
589 Store a value in the session symbol table and update the special fixture
590 symbol-handling pattern when its control symbol is assigned. Return the
591 stored value.
592  
593 =head2 get_symbol
594  
595 Return the current value of a session symbol, or C<undef> if it is absent.
596  
597 =head2 add_converter
598  
599 Register a converter in this executor's registry.
600  
601 =head2 get_converter
602  
603 Resolve a converter in this executor's registry.
604  
605 =head2 reset_converters
606  
607 Restore built-in converters and discard custom registrations for this
608 executor only.
609  
610 =head2 call
611  
612 Invoke a method through actor, SUT, and library resolution. Return the
613 formatted result or a structured SLiM exception string.
614  
615 =head2 call_and_assign
616  
617 Invoke a method and store its result in a symbol. Typed sequence results
618 retain their raw array reference in the symbol table while returning the
619 declared display string.
620  
621 =head2 exception_result
622  
623 Convert fixture exceptions and FitNesse stop/ignore markers into protocol
624 exception strings. Stop markers also set batch control state.
625  
626 =head2 stop_requested and reset_stop_requested
627  
628 Inspect or clear a FitNesse stop/ignore request raised by the most recent
629 instruction. The list executor clears this state between batches.
630  
631 =head1 FIXTURE METADATA
632  
633 Fixtures may implement C<slim_constructor_signature>,
634 C<slim_method_signature>, and C<slim_enum_types>. See
635 C<docs/fixture-conversion.md> for executable declarations and conversion
636 limits.
637  
638 =cut
↑ Summary lib/Test/FitNesse/Slim/Server.pm »