blib/lib/Nice/Try.pm

filter: Statementstmt 81.3% 670 / 824 Branchbran 55.3% 322 / 582 Conditioncond 58.7% 164 / 279 MC/DCmcdc 34.6% 53 / 153 Subroutinesub 81.1% 43 / 53 Podpod 57.1% 4 / 7 totaltotal 66.1% 1256 / 1898 CC 413 SCAR 50.8
CC
413
Cov
69%
_parse
266.1
__ANON__
232.6
_process_loop_breaks
228.9
CRAP 160.0
↑ Summary
1 ##----------------------------------------------------------------------------
2 ## A real Try Catch Block Implementation Using Perl Filter - ~/lib/Nice/Try.pm
3 ## Version v1.4.0
4 ## Copyright(c) 2025 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2020/05/17
7 ## Modified 2026/04/29
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Nice::Try;
14 BEGIN
15 31 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 31 require 5.16.0;
17 31 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 31 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 31 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 31 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 $CATCH $DIED $EXCEPTION $FINALLY $HAS_CATCH @RETVAL $SENTINEL $TRY $WANTARRAY
22 $VERSION $ERROR
23 31 );
24 31 ▶ use PPI 1.277;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 31 ▶ use Filter::Util::Call;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 31 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 31 ▶ use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28 31 ▶ use Wanted ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 31 our $VERSION = 'v1.4.0';
30 31 our $ERROR;
31 31 our( $CATCH, $DIED, $EXCEPTION, $FINALLY, $HAS_CATCH, @RETVAL, $SENTINEL, $TRY, $WANTARRAY );
32 }
33  
34 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 # Taken from Try::Harder version 0.005
38 31 our $SENTINEL = bless( {} => __PACKAGE__ . '::SENTINEL' );
39  
40 sub import
41 32 ▶{
Subroutine import: called CC=11 SCAR=28.1
42 32 my( $this, @arguments ) = @_ ;
43 32 my $class = CORE::caller();
44 32 my $hash = { @arguments };
45 32 ▶ $hash->{debug} = 0 if( !CORE::exists( $hash->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{"debug"} 32 0 32
46 32 ▶ $hash->{no_filter} = 0 if( !CORE::exists( $hash->{no_filter} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{"no_filter"} 32 0 32
47 32 ▶ $hash->{debug_code} = 0 if( !CORE::exists( $hash->{debug_code} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{"debug_code"} 32 0 32
48 32 ▶ $hash->{debug_dump} = 0 if( !CORE::exists( $hash->{debug_dump} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{"debug_dump"} 32 0 32
49 32 ▶ $hash->{dont_want} = 0 if( !CORE::exists( $hash->{dont_want} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{"dont_want"} 32 0 32
50 # We use the $class to process the __DATA__ or __END__ token section
51 32 $hash->{class} = $class;
52 # We check if we are running under tie and if so we cannot use Wanted features,
53 # because they would trigger a segmentation fault.
54 32 $hash->{is_tied} = 0;
55 32 ▶ if( $class->can( 'TIESCALAR' ) || $class->can( 'TIEHASH' ) || $class->can( 'TIEARRAY' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can("TIESCALAR") or $class->can("TIEHASH") or $class->can("TIEARRAY")) 0 32 32
Condition33%2/6
$class->can("TIESCALAR") or $class->can("TIEHASH") or $class->can("TIEARRAY")
l!l&&r!l&&!r
0032
$class->can("TIESCALAR") or $class->can("TIEHASH")
l!l&&r!l&&!r
0032
MC/DC0%0/3
$class->can("TIESCALAR") or $class->can("TIEHASH") or $class->can("TIEARRAY")
$class->can("TIESCALAR") $class->can("TIEHASH") $class->can("TIEARRAY")
Truth table25%1/4
A or B or C
A= $class->can("TIESCALAR")B= $class->can("TIEHASH")C= $class->can("TIEARRAY")
ABCresult
1XX1
01X1
0011
0000
56 {
57 0 $hash->{is_tied} = 1;
58 }
59 32 require overload;
60 32 ▶ $hash->{is_overloaded} = overload::Overloaded( $class ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
overload::Overloaded($class) ? : 0 32 32
61 32 $hash->{no_context} = 0;
62 # 2021-05-17 (Jacques): the following was a bad idea as it was indiscriminate and
63 # would also affect use of caller outside of try-catch blocks
64 # *{"${class}::caller"} = \&{"Nice::Try::caller"};
65 32 ▶ filter_add( bless( $hash => ( ref( $this ) || $this ) ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0320
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
66 }
67  
68 sub unimport
69 0 ▶{
Subroutine unimport: not called CC=1 SCAR=6.9
70 0 filter_del();
71 }
72  
73 sub caller($;$)
74 6 ▶{
Subroutine caller: called CC=2 SCAR=6.9
Pod documented
75 6 my $where = shift( @_ );
76 6 my $n = shift( @_ );
77 # Offsetting our internal call frames
78 6 my $map =
79 {
80 try => 3,
81 catch => 3,
82 finally => 5,
83 };
84 6 ▶ my @info = defined( $n ) ? CORE::caller( int( $n ) + $map->{ $where } ) : CORE::caller( 1 + $map->{ $where } );
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 3 3 6
85 6 return( @info );
86 }
87  
88 3 ▶sub caller_try { return( &Nice::Try::caller( try => @_ ) ); }
Subroutine caller_try: called CC=1 SCAR=0.0
Pod undocumented
89  
90 1 ▶sub caller_catch { return( &Nice::Try::caller( catch => @_ ) ); }
Subroutine caller_catch: called CC=1 SCAR=0.0
Pod undocumented
91  
92 2 ▶sub caller_finally { return( &Nice::Try::caller( finally => @_ ) ); }
Subroutine caller_finally: called CC=1 SCAR=0.0
Pod undocumented
93  
94 sub filter
95 49 ▶{
Subroutine filter: called CC=24 SCAR=43.3
Pod documented
96 49 my( $self ) = @_ ;
97 49 my( $status, $last_line );
98 49 my $line = 0;
99 49 my $code = '';
100 49 ▶ if( $self->{no_filter} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"no_filter"}) 0 49 49
101 {
102 0 filter_del();
103 0 $status = 1;
104 0 ▶ $self->_message( 3, "Skiping filtering." ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 0 0
105 0 return( $status );
106 }
107 49 ▶ while( $status = filter_read() )
Branch: 1 branch
BranchTrueFalseTotal
if ($status = &filter_read()) 3033 49 3082
108 {
109 # Error
110 3033 ▶ if( $status < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($status < 0) 0 3033 3033
111 {
112 0 ▶ $self->_message( 3, "An error occurred in fiilter, aborting." ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 0 0
113 0 return( $status );
114 }
115 3033 $line++;
116 3033 $code .= $_;
117 3033 $_ = '';
118 }
119 49 ▶ return( $line ) if( !$line );
Branch: 1 branch
BranchTrueFalseTotal
unless $line 17 32 49
120 32 ▶ unless( $status < 0 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($status < 0) 32 0 32
121 {
122 # 2021-06-05 (Jacques): fixes the issue No. 3 <https://gitlab.com/jackdeguest/Nice-Try/issues/3>
123 # Make sure there is at least a space at the beginning
124 32 $code = ' ' . $code;
125 32 ▶ if( index( $code, 'try' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($code, 'try') != -1) { } 28 4 32
126 {
127 28 ▶ $self->_message( 4, "Processing $line lines of code." ) if( $self->{debug} >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 4 0 28 28
128 28 ▶ $self->_message( 4, "Processing code:\n${code}" ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 28 28
129 28 ▶ my $doc = PPI::Document->new( \$code, readonly => 1 ) || die( "Unable to parse: ", PPI::Document->errstr, "\n$code\n" );
Condition50%1/2
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
l!l
280
MC/DC0%0/1
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
'PPI::Document'->new(\$code, 'readonly', 1)
Truth table50%1/2
A
A= 'PPI::Document'->new(\$code, 'readonly', 1)
Aresult
11
00
130 # Remove pod
131 # $doc->prune('PPI::Token::Pod');
132 28 ▶ $self->_browse( $doc ) if( $self->{debug_dump} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug_dump"} 0 28 28
133 # It is easy for us to do a simple check as to whether there is potentially a __DATA__ or a __END__ token,
134 # so we avoid wasting resources and time checking it using PPI::Element::find()
135 28 ▶ if( $doc = $self->_parse( $doc,
Branch: 2 branches
BranchTrueFalseTotal
if ($doc = $self->_parse($doc, {'has_data', index($code, '__DATA__') != -1 || index($code, '__END__') != -1 ? 1 : 0})) { } 28 0 28
index($code, '__DATA__') != -1 || index($code, '__END__') != -1 ? : 13 15 28
Condition100%3/3
index($code, "__DATA__") != -1 or index($code, "__END__") != -1
l!l&&r!l&&!r
31015
MC/DC100%2/2
index($code, "__DATA__") != -1 or index($code, "__END__") != -1
index($code, "__DATA__") != -1 index($code, "__END__") != -1
Truth table100%3/3
A or B
A= index($code, "__DATA__") != -1B= index($code, "__END__") != -1
ABresult
1X1
011
000
136 {
137 has_data => ( ( CORE::index( $code, '__DATA__' ) != -1 || CORE::index( $code, '__END__' ) != -1 ) ? 1 : 0 ),
138 }) )
139 {
140 28 $_ = $doc->serialize;
141 # $doc->save( "./dev/debug-parsed.pl" );
142 # $status = 1;
143 }
144 # Rollback
145 else
146 {
147 0 $_ = $code;
148 # $status = -1;
149 # filter_del();
150 }
151 }
152 else
153 {
154 4 ▶ $self->_message( 4, "There does not seem to be any try block in this code, so skipping." ) if( $self->{debug} >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 4 0 4 4
155 4 $_ = $code;
156 }
157
158 32 ▶ if( CORE::length( $last_line ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $last_line) 0 32 32
159 {
160 0 $_ .= $last_line;
161 }
162 }
163 32 ▶ unless( $status <= 0 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($status <= 0) 0 32 32
164 {
165 0 ▶ while( $status = filter_read() )
Branch: 1 branch
BranchTrueFalseTotal
if ($status = &filter_read()) 0 0 0
166 {
167 0 ▶ $self->_message( 4, "Reading more line: $_" ) if( $self->{debug} >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 4 0 0 0
168 0 ▶ return( $status ) if( $status < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $status < 0 0 0 0
169 0 $line++;
170 }
171 }
172 # $self->_message( 4, "Resulting code:\n${_}" ) if( $self->{debug} >= 5 );
173 32 ▶ if( $self->{debug_file} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug_file"}) 0 32 32
174 {
175 0 ▶ if( open( my $fh, ">$self->{debug_file}" ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, qq[>$self->{"debug_file"}]) 0 0 0
176 {
177 0 binmode( $fh, ':utf8' );
178 0 print( $fh $_ );
179 0 close( $fh );
180 }
181 }
182 32 return( $line );
183 }
184  
185 sub implement
186 2 ▶{
Subroutine implement: called CC=14 SCAR=32.4
Pod documented
187 2 my $self = shift( @_ );
188 2 my $code = shift( @_ );
189 2 ▶ return( $code ) if( !CORE::defined( $code ) || !CORE::length( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code and length $code 0 2 2
Condition33%1/3
defined $code and length $code
!ll&&!rl&&r
002
MC/DC0%0/2
defined $code and length $code
defined $code length $code
Truth table33%1/3
A and B
A= defined $codeB= length $code
ABresult
0X0
100
111
190 2 ▶ unless( ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 2 0 2
191 {
192 2 ▶ my $opts = ( !@_ || !defined( $_[0] ) )
Branch: 3 branches
BranchTrueFalseTotal
!(@_ && defined $_[0]) ? : 2 0 2
ref $_[0] eq 'HASH' ? : 0 0 0
!(@_ % 2) ? : 0 0 0
Condition33%1/3
@_ && defined $_[0]
!ll&&!rl&&r
200
MC/DC0%0/2
@_ && defined $_[0]
@_ defined $_[0]
Truth table33%1/3
A && B
A= @_B= defined $_[0]
ABresult
0X0
100
111
193 ? {}
194 : ref( $_[0] ) eq 'HASH'
195 ? shift( @_ )
196 : !( @_ % 2 )
197 ? { @_ }
198 : {};
199 2 for( qw( debug no_context no_filter debug_code debug_dump debug_file dont_want is_tied is_overloaded ) )
200 {
201 18 ▶ $opts->{ $_ } //= 0;
Condition50%1/2
$opts->{$_} //= 0
l!l
018
MC/DC0%0/1
$opts->{$_} //= 0
$opts->{$_}
Truth table50%1/2
A
A= $opts->{$_}
Aresult
11
00
202 }
203 2 $self = bless( $opts => $self );
204 }
205 # 2021-06-05 (Jacques): fixes the issue No. 3 <https://gitlab.com/jackdeguest/Nice-Try/issues/3>
206 # Make sure there is at least a space at the beginning
207 2 $code = ' ' . $code;
208 2 ▶ $self->_message( 4, "Processing ", CORE::length( $code ), " bytes of code." ) if( $self->{debug} >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 4 0 2 2
209 2 ▶ my $doc = PPI::Document->new( \$code, readonly => 1 ) || die( "Unable to parse: ", PPI::Document->errstr, "\n$code\n" );
Condition50%1/2
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
l!l
20
MC/DC0%0/1
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
'PPI::Document'->new(\$code, 'readonly', 1)
Truth table50%1/2
A
A= 'PPI::Document'->new(\$code, 'readonly', 1)
Aresult
11
00
210 2 ▶ $self->_browse( $doc ) if( $self->{debug_dump} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug_dump"} 0 2 2
211 2 ▶ if( $doc = $self->_parse( $doc ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($doc = $self->_parse($doc)) 2 0 2
212 {
213 2 $code = $doc->serialize;
214 }
215 2 return( $code );
216 }
217  
218 sub _browse
219 0 ▶{
Subroutine _browse: not called CC=12 SCAR=50.5
220 0 my $self = shift( @_ );
221 0 my $elem = shift( @_ );
222 0 ▶ my $level = shift( @_ ) || 0;
Condition0%0/2
shift @_ || 0
l!l
00
MC/DC0%0/1
shift @_ || 0
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
223 0 ▶ if( $self->{debug} >= 4 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"} >= 4) 0 0 0
224 {
225 0 ▶ $self->_message( 4, "Checking code: ", $self->_serialize( $elem ) ) if( $self->{debug} >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 4 0 0 0
226 0 ▶ $self->_messagef( 4, "PPI element of class %s has children property '%s'.", $elem->class, $elem->{children} ) if( $self->{debug} >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 4 0 0 0
227 }
228 0 ▶ return if( !$elem->children );
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->children 0 0 0
229 0 foreach my $e ( $elem->elements )
230 {
231 0 ▶ printf( STDERR "%sElement: [%d] class %s, value %s\n", ( '.' x $level ), ( $e->line_number // 'undef' ), ( $e->class // 'undef' ), ( $e->content // 'undef' ) );
Condition0%0/6
$e->line_number // "undef"
l!l
00
$e->class // "undef"
l!l
00
$e->content // "undef"
l!l
00
MC/DC0%0/1
$e->line_number // "undef"
$e->line_number
MC/DC0%0/1
$e->class // "undef"
$e->class
MC/DC0%0/1
$e->content // "undef"
$e->content
Truth table0%0/2
A
A= $e->line_number
Aresult
11
00
Truth table0%0/2
A
A= $e->class
Aresult
11
00
Truth table0%0/2
A
A= $e->content
Aresult
11
00
232 0 ▶ if( $e->can('children') && $e->children )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->can("children") and $e->children) 0 0 0
Condition0%0/3
$e->can("children") and $e->children
!ll&&!rl&&r
000
MC/DC0%0/2
$e->can("children") and $e->children
$e->can("children") $e->children
Truth table0%0/3
A and B
A= $e->can("children")B= $e->children
ABresult
0X0
100
111
233 {
234 0 $self->_browse( $e, $level + 1 );
235 }
236 }
237 }
238  
239 sub _error
240 0 ▶{
Subroutine _error: not called CC=4 SCAR=30.0
241 0 my $self = shift( @_ );
242 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
243 {
244 0 ▶ my $txt = join( '', map( ref( $_ ) eq 'CODE' ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
245 0 $txt =~ s/[\015\012]+$//g;
246 0 $ERROR = $txt;
247 0 ▶ CORE::warn( "$txt\n" ) if( warnings::enabled );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
248 0 return;
249 }
250 0 return( $ERROR );
251 }
252  
253 sub _message
254 78 ▶{
Subroutine _message: called CC=4 SCAR=23.1
255 78 my $self = shift( @_ );
256 78 ▶ my $level = $_[0] =~ /^\d+$/ ? shift( @_ ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ ? : 78 0 78
257 78 ▶ return if( $self->{debug} < $level );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} < $level 78 0 78
258 0 my @data = @_;
259 0 my $stackFrame = 0;
260 0 my( $pkg, $file, $line, @otherInfo ) = CORE::caller( $stackFrame );
261 0 my $sub = ( CORE::caller( $stackFrame + 1 ) )[3];
262 0 my $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
263 0 ▶ my $txt = "${pkg}::${sub2}( $self ) [$line]: " . join( '', map( ref( $_ ) eq 'CODE' ? $_->() : $_, @data ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
264 0 $txt =~ s/\n$//gs;
265 0 $txt = '## ' . join( "\n## ", split( /\n/, $txt ) );
266 0 CORE::print( STDERR $txt, "\n" );
267 }
268  
269 sub _messagef
270 0 ▶{
Subroutine _messagef: not called CC=6 SCAR=37.4
271 0 my $self = shift( @_ );
272 0 ▶ my $level = $_[0] =~ /^\d+$/ ? shift( @_ ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ ? : 0 0 0
273 0 ▶ return if( $self->{debug} < $level );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} < $level 0 0 0
274 0 my @data = @_;
275 0 my $stackFrame = 0;
276 0 my $fmt = shift( @data );
277 0 my( $pkg, $file, $line, @otherInfo ) = CORE::caller( $stackFrame );
278 0 my $sub = ( CORE::caller( $stackFrame + 1 ) )[3];
279 0 my $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
280 0 for( @data )
281 {
282 0 ▶ next if( ref( $_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 0 0 0
283 0 s/\b\%/\x{025}/g;
284 }
285 0 ▶ my $txt = "${pkg}::${sub2}( $self ) [$line]: " . sprintf( $fmt, map( ref( $_ ) eq 'CODE' ? $_->() : $_, @data ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
286 0 $txt =~ s/\n$//gs;
287 0 $txt = '## ' . join( "\n## ", split( /\n/, $txt ) );
288 0 CORE::print( STDERR $txt, "\n" );
289 }
290  
291 sub _parse
292 300 ▶{
Subroutine _parse: called CC=126 SCAR=55.8
293 300 my $self = shift( @_ );
294 300 my $elem = shift( @_ );
295 300 my $opts = shift( @_ );
296 31 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
297 300 ▶ if( !Scalar::Util::blessed( $elem ) || !$elem->isa( 'PPI::Node' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($elem) and $elem->isa("PPI::Node")) 0 300 300
Condition33%1/3
builtin::blessed($elem) and $elem->isa("PPI::Node")
!ll&&!rl&&r
00300
MC/DC0%0/2
builtin::blessed($elem) and $elem->isa("PPI::Node")
builtin::blessed($elem) $elem->isa("PPI::Node")
Truth table33%1/3
A and B
A= builtin::blessed($elem)B= $elem->isa("PPI::Node")
ABresult
0X0
100
111
298 {
299 0 return( $self->_error( "Element provided to parse is not a PPI::Node object" ) );
300 }
301  
302 300 my $check_consecutive_blocks;
303 $check_consecutive_blocks = sub
304 304 ▶ {
Subroutine __ANON__: called CC=74 SCAR=54.5
305 304 my $top_elem = shift( @_ );
306 304 my $level = shift( @_ );
307 my $ref = $top_elem->find(sub
308 28993 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
309 28993 my( $top, $this ) = @_;
310 28993 ▶ return( $this->class eq 'PPI::Statement' && substr( $this->content, 0, 3 ) eq 'try' ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$this->class eq 'PPI::Statement' && substr($this->content, 0, 3) eq 'try' ? : 132 28861 28993
Condition100%3/3
$this->class eq "PPI::Statement" and substr($this->content, 0, 3) eq "try"
!ll&&!rl&&r
277311130132
MC/DC100%2/2
$this->class eq "PPI::Statement" and substr($this->content, 0, 3) eq "try"
$this->class eq "PPI::Statement" substr($this->content, 0, 3) eq "try"
Truth table100%3/3
A and B
A= $this->class eq "PPI::Statement"B= substr($this->content, 0, 3) eq "try"
ABresult
0X0
100
111
311 304 });
312 304 ▶ return( $self->_error( "Failed to find any try-catch clause: $@" ) ) if( !defined( $ref ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref 0 304 304
313 304 ▶ $self->_messagef( 4, "[blocks check level ${level}] Found %d match(es) for try statement", scalar( @$ref ) ) if( $ref && ref( $ref ) && $self->{debug} >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $ref and ref $ref and $self->{"debug"} >= 4 0 304 304
Condition66%4/6
$ref and ref $ref and $self->{"debug"} >= 4
!ll&&!rl&&r
270340
$ref and ref $ref
!ll&&!rl&&r
270034
MC/DC0%0/3
$ref and ref $ref and $self->{"debug"} >= 4
$ref ref $ref $self->{"debug"} >= 4
Truth table50%2/4
A and B and C
A= $refB= ref $refC= $self->{"debug"} >= 4
ABCresult
0XX0
10X0
1100
1111
314 304 ▶ return if( !$ref || !scalar( @$ref ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $ref and scalar @$ref 270 34 304
Condition66%2/3
$ref and scalar @$ref
!ll&&!rl&&r
270034
MC/DC50%1/2
$ref and scalar @$ref
$ref scalar @$ref
Truth table66%2/3
A and B
A= $refB= scalar @$ref
ABresult
0X0
100
111
315 # We will store the additional blocks here, and we will dig deeper into them recursively.
316 34 my $has_additional_blocks = 0;
317
318 # NOTE: Checking for consecutive try-catch block statements
319 # 2020-09-13: PPI will return 2 or more consecutive try-catch block as 1 statement
320 # It does not tell them apart, so we need to post process the result to effectively search within for possible for other try-catch blocks and update the @$ref array consequently
321 # Array to contain the new version of the $ref array.
322 34 my $alt_ref = [];
323 34 ▶ $self->_message( 3, "[blocks check level ${level}] Checking for consecutive try-catch blocks in ", scalar( @$ref ), " results found by PPI" ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 34 34
324 34 foreach my $this ( @$ref )
325 {
326 132 ▶ $self->_message( 3, "[blocks check level ${level}] Getting children from object '", overload::StrVal( $this ), "'" ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 132 132
327 132 ▶ $self->_message( 3, "[blocks check level ${level}] Checking if following code has children" ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 132 132
328 # my( @block_children ) = ( exists( $this->{children} ) && ref( $this->{children} // '' ) eq 'ARRAY' ) ? $this->children : ();
329 # Stringifying forces PPI to set the object children somehow
330 132 my $ct = "$this";
331 132 my( @block_children ) = $this->children;
332 132 ▶ next if( !scalar( @block_children ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @block_children 0 132 132
333 132 my $tmp_ref = [];
334 ## to contain all the nodes to move
335 132 my $tmp_nodes = [];
336 132 my $prev_sib = $block_children[0];
337 132 push( @$tmp_nodes, $prev_sib );
338 132 my $sib;
339 132 ▶ while( $sib = $prev_sib->next_sibling )
Branch: 1 branch
BranchTrueFalseTotal
if ($sib = $prev_sib->next_sibling) 1715 132 1847
340 {
341 # We found a try-catch block. Move the buffer to $alt_ref
342 1715 ▶ if( $sib->class eq 'PPI::Token::Word' && $sib->content eq 'try' )
Branch: 1 branch
BranchTrueFalseTotal
if ($sib->class eq "PPI::Token::Word" and $sib->content eq "try") 2 1713 1715
Condition100%3/3
$sib->class eq "PPI::Token::Word" and $sib->content eq "try"
!ll&&!rl&&r
15042092
MC/DC100%2/2
$sib->class eq "PPI::Token::Word" and $sib->content eq "try"
$sib->class eq "PPI::Token::Word" $sib->content eq "try"
Truth table100%3/3
A and B
A= $sib->class eq "PPI::Token::Word"B= $sib->content eq "try"
ABresult
0X0
100
111
343 {
344 # Look ahead for a block...
345 2 my $next = $sib->snext_sibling;
346 2 ▶ if( $next && $next->class eq 'PPI::Structure::Block' )
Branch: 1 branch
BranchTrueFalseTotal
if ($next and $next->class eq "PPI::Structure::Block") 2 0 2
Condition33%1/3
$next and $next->class eq "PPI::Structure::Block"
!ll&&!rl&&r
002
MC/DC0%0/2
$next and $next->class eq "PPI::Structure::Block"
$next $next->class eq "PPI::Structure::Block"
Truth table33%1/3
A and B
A= $nextB= $next->class eq "PPI::Structure::Block"
ABresult
0X0
100
111
347 {
348 2 $has_additional_blocks++;
349 2 ▶ $self->_messagef( 3, "[blocks check level ${level}] Found consecutive try-block at line %d.", $sib->line_number ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 2 2
350 # Push the previous statement $st to the stack $alt_ref
351 2 ▶ $self->_messagef( 3, "[blocks check level ${level}] Saving previous %d nodes collected.", scalar( @$tmp_nodes ) ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 2 2
352 2 push( @$tmp_ref, $tmp_nodes );
353 2 $tmp_nodes = [];
354 }
355 }
356 1715 push( @$tmp_nodes, $sib );
357 1715 $prev_sib = $sib;
358 }
359 132 ▶ $self->_messagef( 3, "[blocks check level ${level}] Saving last %d nodes collected.", scalar( @$tmp_nodes ) ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 132 132
360 132 push( @$tmp_ref, $tmp_nodes );
361 132 ▶ $self->_messagef( 3, "[blocks check level ${level}] Found %d try-catch block(s) in initial PPI result.", scalar( @$tmp_ref ) ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 132 132
362 # If we did find consecutive try-catch blocks, we add each of them after the nominal one and remove the nominal one after. The nominal one should be empty by then
363 132 ▶ if( scalar( @$tmp_ref ) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tmp_ref > 1) { } 2 130 132
364 {
365 2 my $last_obj = $this;
366 2 my $spaces = [];
367 2 foreach my $arr ( @$tmp_ref )
368 {
369 4 ▶ $self->_message( 3, "[blocks check level ${level}] Adding statement block with ", scalar( @$arr ), " children after one at line ", $last_obj->line_number, ": '", substr( $last_obj, 0, 255 ), "'" ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 4 4
370 # 2021-06-05 (Jacques): Fixing issue No. 2: <https://gitlab.com/jackdeguest/Nice-Try/issues/2>
371 # Find the last block that belongs to us
372 4 ▶ $self->_message( 4, "[blocks check level ${level}] Checking first level objects collected." ) if( $self->{debug} >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 4 0 4 4
373 4 my $last_control = '';
374 4 my $last_block;
375 4 my $last = {};
376 4 foreach my $o ( @$arr )
377 {
378 57 ▶ if( $o->class eq 'PPI::Structure::Block' && $last_control )
Branch: 2 branches
BranchTrueFalseTotal
if ($o->class eq 'PPI::Structure::Block' and $last_control) { } 8 49 57
elsif ($o->class eq 'PPI::Token::Word') { } 11 38 49
Condition100%3/3
$o->class eq "PPI::Structure::Block" and $last_control
!ll&&!rl&&r
4818
MC/DC100%2/2
$o->class eq "PPI::Structure::Block" and $last_control
$o->class eq "PPI::Structure::Block" $last_control
Truth table100%3/3
A and B
A= $o->class eq "PPI::Structure::Block"B= $last_control
ABresult
0X0
100
111
379 {
380 8 $last->{block} = $o;
381 8 $last->{control} = $last_control;
382 8 $last_control = '';
383 }
384 elsif( $o->class eq 'PPI::Token::Word' )
385 {
386 11 my $ct = $o->content;
387 11 ▶ if( $ct eq 'try' || $ct eq 'catch' || $ct eq 'finally' )
Branch: 1 branch
BranchTrueFalseTotal
if ($ct eq "try" or $ct eq "catch" or $ct eq "finally") 8 3 11
Condition83%5/6
$ct eq "try" or $ct eq "catch" or $ct eq "finally"
l!l&&r!l&&!r
803
$ct eq "try" or $ct eq "catch"
l!l&&r!l&&!r
443
MC/DC66%2/3
$ct eq "try" or $ct eq "catch" or $ct eq "finally"
$ct eq "try" $ct eq "catch" $ct eq "finally"
Truth table75%3/4
A or B or C
A= $ct eq "try"B= $ct eq "catch"C= $ct eq "finally"
ABCresult
1XX1
01X1
0011
0000
388 {
389 8 $last_control = $o;
390 }
391 }
392 }
393
394 # Get the trailing insignificant elements at the end of the statement and move them out of the statement
395 4 my $insignificants = [];
396 4 ▶ while( scalar( @$arr ) > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arr > 0) 25 0 25
397 {
398 25 my $o = $arr->[-1];
399 # 2021-06-05 (Jacques): We don't just look for the last block, because
400 # that was making a bad assumption that the last trailing block would be our
401 # try-catch block.
402 # Following issue No. 2 reported with a trailing anonymous subroutine,
403 # We remove everything up until our known last block that belongs to us.
404 25 ▶ last if( $o->class eq 'PPI::Structure::Block' && Scalar::Util::refaddr( $o ) eq Scalar::Util::refaddr( $last->{block} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $o->class eq "PPI::Structure::Block" and builtin::refaddr($o) eq builtin::refaddr($last->{"block"}) 4 21 25
Condition100%3/3
$o->class eq "PPI::Structure::Block" and builtin::refaddr($o) eq builtin::refaddr($last->{"block"})
!ll&&!rl&&r
2014
MC/DC100%2/2
$o->class eq "PPI::Structure::Block" and builtin::refaddr($o) eq builtin::refaddr($last->{"block"})
$o->class eq "PPI::Structure::Block" builtin::refaddr($o) eq builtin::refaddr($last->{"block"})
Truth table100%3/3
A and B
A= $o->class eq "PPI::Structure::Block"B= builtin::refaddr($o) eq builtin::refaddr($last->{"block"})
ABresult
0X0
100
111
405 21 unshift( @$insignificants, pop( @$arr )->remove );
406 }
407 4 ▶ $self->_messagef( 3, "[blocks check level ${level}] %d insignificant objects found.", scalar( @$insignificants ) ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 4 4
408
409 4 my $new_code = join( '', map( "$_", @$arr ) );
410 4 ▶ $self->_message( 3, "[blocks check level ${level}] Parsing new code to extract statement:\n${new_code}" ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 4 4
411 # 2021-06-05 (Jacques): It is unfortunately difficult to simply add a new PPI::Statement object
412 # Instead, we have PPI parse our new code and we grab what we need.
413 4 my $new_block = PPI::Document->new( \$new_code, readonly => 1 );
414 # my $st = $new_block->{children}->[0]->remove;
415 4 my $st;
416 4 ▶ for( my $i = 0; $i < scalar( @{$new_block->{children}} ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$new_block->{"children"};}) 4 0 4
417 {
418 4 ▶ if( Scalar::Util::blessed( $new_block->{children}->[$i] ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($new_block->{"children"}[$i]) and $new_block->{"children"}[$i]->isa("PPI::Statement")) 4 0 4
Condition33%1/3
builtin::blessed($new_block->{"children"}[$i]) and $new_block->{"children"}[$i]->isa("PPI::Statement")
!ll&&!rl&&r
004
MC/DC0%0/2
builtin::blessed($new_block->{"children"}[$i]) and $new_block->{"children"}[$i]->isa("PPI::Statement")
builtin::blessed($new_block->{"children"}[$i]) $new_block->{"children"}[$i]->isa("PPI::Statement")
Truth table33%1/3
A and B
A= builtin::blessed($new_block->{"children"}[$i])B= $new_block->{"children"}[$i]->isa("PPI::Statement")
ABresult
0X0
100
111
419 $new_block->{children}->[$i]->isa( 'PPI::Statement' ) )
420 {
421 4 $st = $new_block->{children}->[$i]->remove;
422 4 last;
423 }
424 }
425
426 4 foreach my $o ( @$arr )
427 {
428 # We remove the object from its parent, now that it has become useless
429 36 ▶ my $old = $o->remove || die( "Unable to remove element '$o'\n" );
Condition50%1/2
$o->remove || die("Unable to remove element '${o}'\n")
l!l
360
MC/DC0%0/1
$o->remove || die("Unable to remove element '${o}'\n")
$o->remove
Truth table50%1/2
A
A= $o->remove
Aresult
11
00
430 }
431 4 my $err = '';
432 4 ▶ $self->_messagef( 3, "[blocks check level ${level}] Adding the statement object after last object '%s' of class '%s' with parent with class '%s'.", Scalar::Util::refaddr( $last_obj ), ( defined( $last_obj ) ? $last_obj->class : 'undefined class' ), ( defined( $last_obj ) ? $last_obj->parent->class : 'undefined parent class' ) ) if( $self->{debug} >= 3 );
Branch: 3 branches
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 4 4
defined $last_obj ? : 0 0 0
defined $last_obj ? : 0 0 0
433 # my $rc = $last_obj->insert_after( $st );
434 4 my $rc;
435 4 ▶ if( $last_obj->class eq 'PPI::Token::Whitespace' )
Branch: 2 branches
BranchTrueFalseTotal
if ($last_obj->class eq 'PPI::Token::Whitespace') { } 2 2 4
elsif ($last_obj->class eq 'PPI::Token::Comment') { } 0 2 2
436 {
437 2 $rc = $last_obj->__insert_after( $st );
438 }
439 elsif( $last_obj->class eq 'PPI::Token::Comment' )
440 {
441 # $rc = $last_obj->parent->__insert_after_child( $last_obj, $st );
442 0 $rc = $last_obj->__insert_after( $st );
443 }
444 else
445 {
446 2 $rc = $last_obj->insert_after( $st );
447 }
448
449 4 ▶ if( !defined( $rc ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $rc) { } 0 4 4
elsif (not $rc) { } 0 4 4
450 {
451 0 $err = sprintf( 'Object to be added after last try-block statement must be a PPI::Element. Class provided is \"%s\".', $st->class );
452 }
453 elsif( !$rc )
454 {
455 0 my $requires;
456 0 ▶ if( $last_obj->isa( 'PPI::Structure' ) ||
Branch: 2 branches
BranchTrueFalseTotal
if ($last_obj->isa('PPI::Structure') or $last_obj->isa('PPI::Token')) { } 0 0 0
elsif ($last_obj->isa('PPI::Statement')) { } 0 0 0
Condition0%0/3
$last_obj->isa("PPI::Structure") or $last_obj->isa("PPI::Token")
l!l&&r!l&&!r
000
MC/DC0%0/2
$last_obj->isa("PPI::Structure") or $last_obj->isa("PPI::Token")
$last_obj->isa("PPI::Structure") $last_obj->isa("PPI::Token")
Truth table0%0/3
A or B
A= $last_obj->isa("PPI::Structure")B= $last_obj->isa("PPI::Token")
ABresult
1X1
011
000
457 $last_obj->isa( 'PPI::Token' ) )
458 {
459 0 $requires = 'PPI::Structure or PPI::Token';
460 }
461 elsif( $last_obj->isa( 'PPI::Statement' ) )
462 {
463 0 $requires = 'PPI::Statement or PPI::Token';
464 }
465 0 $err = sprintf( "Object of class \"%s\" could not be added after object with address '%s' and of class '%s' with parent '%s' with class '%s': '$last_obj'. The object of class '%s' must be a ${requires} object.", $st->class, Scalar::Util::refaddr( $last_obj ), $last_obj->class, Scalar::Util::refaddr( $last_obj->parent ), $last_obj->parent->class, $st->class );
466 }
467 else
468 {
469 4 $last_obj = $st;
470 4 ▶ if( scalar( @$insignificants ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$insignificants) 4 0 4
471 {
472 4 ▶ $self->_messagef( 4, "[blocks check level ${level}] Adding %d trailing insignificant objects after last element of class '%s'", scalar( @$insignificants ), $last_obj->class ) if( $self->{debug} >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 4 0 4 4
473 4 foreach my $o ( @$insignificants )
474 {
475 21 ▶ $self->_messagef( 4, "[blocks check level ${level}] Adding trailing insignificant object of class '%s' after last element of class '%s'", $o->class, $last_obj->class ) if( $self->{debug} >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 4 0 21 21
476 # printf( STDERR "Inserting object '%s' (%s) of type '%s' after object '%s' (%s) of type %s who has parent '%s' of type '%s'\n", overload::StrVal( $o ), Scalar::Util::refaddr( $o ), ref( $o ), overload::StrVal( $last_obj), Scalar::Util::refaddr( $last_obj ), ref( $last_obj ), overload::StrVal( $last_obj->parent ), ref( $last_obj->parent ) );
477 CORE::eval
478 21 {
479 $rc = $last_obj->insert_after( $o ) ||
480 do
481 21 ▶ {
Condition33%1/3
$last_obj->insert_after($o) || do { warn q[Failed to insert object of class '], $o->class, q[' before last object of class '], $st->class, "'\n" if $self->{'debug'} }
l!l&&r!l&&!r
2100
MC/DC0%0/2
$last_obj->insert_after($o) || do { warn q[Failed to insert object of class '], $o->class, q[' before last object of class '], $st->class, "'\n" if $self->{'debug'} }
$last_obj->insert_after($o) do { warn q[Failed to insert object of class '], $o->class, q[' before last object of class '], $st->class, "'\n" if $self->{'debug'} }
Truth table33%1/3
A || B
A= $last_obj->insert_after($o)B= do { warn q[Failed to insert object of class '], $o->class, q[' before last object of class '], $st->class, "'\n" if $self->{'debug'} }
ABresult
1X1
011
000
482 0 ▶ warn( "Failed to insert object of class '", $o->class, "' before last object of class '", $st->class, "'\n" ) if( $self->{debug} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
483 };
484 };
485 21 ▶ if( $@ )
Branch: 3 branches
BranchTrueFalseTotal
if ($@) { } 0 21 21
elsif (not defined $rc) { } 0 21 21
elsif (not $rc) { } 0 21 21
486 {
487 0 ▶ if( ref( $o ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $o) { } 0 0 0
488 {
489 0 ▶ warn( "Failed to insert object of class '", $o->class, "' before last object of class '", $st->class, "': $@\n" ) if( $self->{debug} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
490 }
491 else
492 {
493 0 ▶ warn( "Was expecting an object to insert before last object of class '", $st->class, "', but instead got '$o': $@\n" ) if( $self->{debug} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
494 }
495 }
496 elsif( !defined( $rc ) )
497 {
498 0 ▶ warn( sprintf( 'Object to be added after last try-block statement must be a PPI::Element. Class provided is \"%s\".', $o->class ) ) if( $self->{debug} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
499 }
500 elsif( !$rc )
501 {
502 0 ▶ warn( sprintf( "Object of class \"%s\" could not be added after object of class '%s': '$last_obj'.", $o->class, $last_obj->class ) ) if( $self->{debug} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
503 }
504 # printf( STDERR "Object inserted '%s' (%s) of class '%s' now has parent '%s' (%s) of class '%s'\n", overload::StrVal( $o ), Scalar::Util::refaddr( $o ), ref( $o ), overload::StrVal( $o->parent ), Scalar::Util::refaddr( $o->parent ), ref( $o->parent ) );
505 21 ▶ $o->parent( $last_obj->parent ) if( !$o->parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $o->parent 0 21 21
506 21 $last_obj = $o;
507 }
508 }
509 }
510 4 ▶ die( $err ) if( length( $err ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $err 0 4 4
511 4 push( @$alt_ref, $st );
512 }
513 2 my $parent = $this->parent;
514 # Completely destroy it; it is now replaced by our updated code
515 2 $this->delete;
516 }
517 else
518 {
519 130 push( @$alt_ref, $this );
520 }
521 }
522 34 ▶ $self->_messagef( 3, "[blocks check level ${level}] Results found increased from %d to %d results.", scalar( @$ref ), scalar( @$alt_ref ) ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 34 34
523  
524 34 ▶ if( $has_additional_blocks )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_additional_blocks) { } 1 33 34
525 {
526 1 ▶ $self->_message( 3, "[blocks check level ${level}] Consecutive block search now found ", scalar( @$alt_ref ), " try blocks." ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 1 1
527 1 my $more = [];
528 1 foreach my $el ( @$alt_ref )
529 {
530 4 push( @$more, $el );
531 4 my $rv = $check_consecutive_blocks->( $el, ( $level + 1 ) );
532 4 ▶ if( ref( $rv ) && scalar( @$rv ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rv and scalar @$rv) 0 4 4
Condition50%1/2
ref $rv and scalar @$rv
!ll
40
MC/DC0%0/1
ref $rv and scalar @$rv
ref $rv
Truth table50%1/2
A
A= ref $rv
Aresult
00
11
533 {
534 0 push( @$more, @$rv );
535 }
536 }
537 1 return( $more );
538 }
539 else
540 {
541 33 return( $ref );
542 }
543 300 };
544 300 my $ref = $check_consecutive_blocks->( $elem => 0 );
545 300 ▶ return if( !$ref || !scalar( @$ref ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $ref and scalar @$ref 266 34 300
Condition66%2/3
$ref and scalar @$ref
!ll&&!rl&&r
266034
MC/DC50%1/2
$ref and scalar @$ref
$ref scalar @$ref
Truth table66%2/3
A and B
A= $refB= scalar @$ref
ABresult
0X0
100
111
546
547 34 ▶ $self->_messagef( 3, "Implementing try-catch for %d try-catch blocks.", scalar( @$ref ) ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 34 34
548 # NOTE: processing implementation of our try-catch
549 34 foreach my $this ( @$ref )
550 {
551 134 ▶ $self->_browse( $this ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 134 134
552 134 my $element_before_try = $this->previous_sibling;
553 134 my $try_block_ref = [];
554 # Contains the finally block reference
555 134 my $fin_block_ref = [];
556 134 my $nodes_to_replace = [];
557 134 my $catch_def = [];
558 # Replacement data
559 134 my $repl = [];
560 134 my $catch_repl = [];
561
562 # There is a weird bug in PPI that I have searched but could not find
563 # If I don't attempt to stringify, I may end up with a PPI::Statement object that has no children as an array reference
564 134 my $ct = "$this";
565 134 my( @block_children ) = $this->children;
566 134 ▶ next if( !scalar( @block_children ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @block_children 5 129 134
567 129 my $prev_sib = $block_children[0];
568 129 push( @$nodes_to_replace, $prev_sib );
569 129 my( $inside_catch, $inside_finally );
570 129 my $temp = {};
571 # Buffer of nodes found in between blocks
572 129 my $buff = [];
573 # Temporary new line counter between try-catch block so we can reproduce it and ensure proper reporting of error line
574 129 my $nl_counter = 0;
575 129 my $sib;
576 129 ▶ while( $sib = $prev_sib->next_sibling )
Branch: 1 branch
BranchTrueFalseTotal
if ($sib = $prev_sib->next_sibling) 1632 129 1761
577 {
578 1632 ▶ if( !scalar( @$try_block_ref ) )
Branch: 6 branches
BranchTrueFalseTotal
if (not scalar @$try_block_ref) { } 335 1297 1632
elsif ($sib->class eq 'PPI::Token::Word' and $sib->content eq 'catch') { } 143 1154 1297
elsif ($inside_catch) { } 501 653 1154
elsif ($sib->class eq 'PPI::Token::Word' and $sib->content eq 'finally') { } 13 640 653
elsif ($inside_finally) { } 27 613 640
elsif ($sib->class eq 'PPI::Token::Whitespace' and $sib->content =~ /[\015\012]+/) { } 211 402 613
579 {
580 335 ▶ if( $sib->class eq 'PPI::Structure::Block' &&
Branch: 2 branches
BranchTrueFalseTotal
if ($sib->class eq 'PPI::Structure::Block' and substr("$sib", 0, 1) eq '{' and substr("$sib", -1, 1) eq '}') { } 127 208 335
elsif ($sib->class eq 'PPI::Token::Whitespace' and $sib->content =~ /[\015\012]+/) { } 79 129 208
Condition66%4/6
$sib->class eq "PPI::Structure::Block" and substr("$sib", 0, 1) eq "{" and substr("$sib", -1, 1) eq "}"
!ll&&!rl&&r
2080127
$sib->class eq "PPI::Structure::Block" and substr("$sib", 0, 1) eq "{"
!ll&&!rl&&r
2080127
MC/DC33%1/3
$sib->class eq "PPI::Structure::Block" and substr("$sib", 0, 1) eq "{" and substr("$sib", -1, 1) eq "}"
$sib->class eq "PPI::Structure::Block" substr("$sib", 0, 1) eq "{" substr("$sib", -1, 1) eq "}"
Truth table50%2/4
A and B and C
A= $sib->class eq "PPI::Structure::Block"B= substr("$sib", 0, 1) eq "{"C= substr("$sib", -1, 1) eq "}"
ABCresult
0XX0
10X0
1100
1111
581 substr( "$sib", 0, 1 ) eq "\{" &&
582 substr( "$sib", -1, 1 ) eq "\}" )
583 {
584 127 $temp->{block} = $sib;
585 127 push( @$try_block_ref, $temp );
586 127 $temp = {};
587 127 ▶ if( scalar( @$buff ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$buff) 127 0 127
588 {
589 127 push( @$nodes_to_replace, @$buff );
590 127 $buff = [];
591 }
592 127 push( @$nodes_to_replace, $sib );
593 }
594 ▶ elsif( $sib->class eq 'PPI::Token::Whitespace' && $sib->content =~ /[\015\012]+/ )
Condition100%3/3
$sib->class eq "PPI::Token::Whitespace" and $sib->content =~ /[\015\012]+/
!ll&&!rl&&r
212779
MC/DC100%2/2
$sib->class eq "PPI::Token::Whitespace" and $sib->content =~ /[\015\012]+/
$sib->class eq "PPI::Token::Whitespace" $sib->content =~ /[\015\012]+/
Truth table100%3/3
A and B
A= $sib->class eq "PPI::Token::Whitespace"B= $sib->content =~ /[\015\012]+/
ABresult
0X0
100
111
595 {
596 79 $temp->{open_curly_nl}++;
597 79 push( @$buff, $sib );
598 }
599 # We skip anything else until we find that try block
600 else
601 {
602 129 push( @$buff, $sib );
603 129 $prev_sib = $sib;
604 129 next;
605 }
606 }
607 ▶ elsif( $sib->class eq 'PPI::Token::Word' && $sib->content eq 'catch' )
Condition100%3/3
$sib->class eq "PPI::Token::Word" and $sib->content eq "catch"
!ll&&!rl&&r
109856143
MC/DC100%2/2
$sib->class eq "PPI::Token::Word" and $sib->content eq "catch"
$sib->class eq "PPI::Token::Word" $sib->content eq "catch"
Truth table100%3/3
A and B
A= $sib->class eq "PPI::Token::Word"B= $sib->content eq "catch"
ABresult
0X0
100
111
608 {
609 143 $inside_catch++;
610 143 ▶ if( scalar( @$buff ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$buff) 139 4 143
611 {
612 139 push( @$nodes_to_replace, @$buff );
613 139 $buff = [];
614 }
615 143 push( @$nodes_to_replace, $sib );
616 }
617 elsif( $inside_catch )
618 {
619 # This is the catch list as in catch( $e ) or catch( Exception $e )
620 501 ▶ if( $sib->class eq 'PPI::Structure::List' )
Branch: 3 branches
BranchTrueFalseTotal
if ($sib->class eq 'PPI::Structure::List') { } 109 392 501
elsif ($sib->class eq 'PPI::Structure::Block') { } 143 249 392
elsif ($sib->class eq 'PPI::Token::Whitespace' and $sib->content =~ /[\015\012]+/) { } 98 151 249
621 {
622 109 $temp->{var} = $sib;
623 109 push( @$nodes_to_replace, $sib );
624 }
625 elsif( $sib->class eq 'PPI::Structure::Block' )
626 {
627 143 $temp->{block} = $sib;
628 143 ▶ if( scalar( @$catch_def ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$catch_def) { } 24 119 143
629 {
630 24 $catch_def->[-1]->{close_curly_nl} = $nl_counter;
631 }
632 else
633 {
634 119 $try_block_ref->[-1]->{close_curly_nl} = $nl_counter;
635 }
636 143 $nl_counter = 0;
637 143 push( @$catch_def, $temp );
638 143 $temp = {};
639 143 $inside_catch = 0;
640 143 push( @$nodes_to_replace, $sib );
641 }
642 ▶ elsif( $sib->class eq 'PPI::Token::Whitespace' && $sib->content =~ /[\015\012]+/ )
Condition66%2/3
$sib->class eq "PPI::Token::Whitespace" and $sib->content =~ /[\015\012]+/
!ll&&!rl&&r
015198
MC/DC50%1/2
$sib->class eq "PPI::Token::Whitespace" and $sib->content =~ /[\015\012]+/
$sib->class eq "PPI::Token::Whitespace" $sib->content =~ /[\015\012]+/
Truth table66%2/3
A and B
A= $sib->class eq "PPI::Token::Whitespace"B= $sib->content =~ /[\015\012]+/
ABresult
0X0
100
111
643 {
644 98 $temp->{open_curly_nl}++;
645 98 push( @$nodes_to_replace, $sib );
646 }
647 else
648 {
649 151 push( @$nodes_to_replace, $sib );
650 }
651 }
652 ▶ elsif( $sib->class eq 'PPI::Token::Word' && $sib->content eq 'finally' )
Condition100%3/3
$sib->class eq "PPI::Token::Word" and $sib->content eq "finally"
!ll&&!rl&&r
5974313
MC/DC100%2/2
$sib->class eq "PPI::Token::Word" and $sib->content eq "finally"
$sib->class eq "PPI::Token::Word" $sib->content eq "finally"
Truth table100%3/3
A and B
A= $sib->class eq "PPI::Token::Word"B= $sib->content eq "finally"
ABresult
0X0
100
111
653 {
654 13 $inside_finally++;
655 13 ▶ if( scalar( @$buff ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$buff) 13 0 13
656 {
657 13 push( @$nodes_to_replace, @$buff );
658 13 $buff = [];
659 }
660 13 push( @$nodes_to_replace, $sib );
661 }
662 elsif( $inside_finally )
663 {
664 # We could ignore it, but it is best to let the developer know in case he/she counts on it somehow
665 27 ▶ if( $sib->class eq 'PPI::Structure::List' )
Branch: 3 branches
BranchTrueFalseTotal
if ($sib->class eq 'PPI::Structure::List') { } 0 27 27
elsif ($sib->class eq 'PPI::Structure::Block') { } 13 14 27
elsif ($sib->class eq 'PPI::Token::Whitespace' and $sib->content =~ /[\015\012]+/) { } 1 13 14
666 {
667 0 die( sprintf( "the finally block does not accept any list parameters at line %d\n", $sib->line_number ) );
668 }
669 elsif( $sib->class eq 'PPI::Structure::Block' )
670 {
671 13 $temp->{block} = $sib;
672 13 ▶ if( scalar( @$fin_block_ref ) )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$fin_block_ref) { } 0 13 13
elsif (scalar @$catch_def) { } 7 6 13
673 {
674 0 die( sprintf( "There can only be one finally block at line %d\n", $sib->line_number ) );
675 }
676 elsif( scalar( @$catch_def ) )
677 {
678 7 $catch_def->[-1]->{close_curly_nl} = $nl_counter;
679 }
680 else
681 {
682 6 $try_block_ref->[-1]->{close_curly_nl} = $nl_counter;
683 }
684 13 $nl_counter = 0;
685 13 push( @$fin_block_ref, $temp );
686 13 $temp = {};
687 13 $inside_finally = 0;
688 13 push( @$nodes_to_replace, $sib );
689 }
690 ▶ elsif( $sib->class eq 'PPI::Token::Whitespace' && $sib->content =~ /[\015\012]+/ )
Condition66%2/3
$sib->class eq "PPI::Token::Whitespace" and $sib->content =~ /[\015\012]+/
!ll&&!rl&&r
0131
MC/DC50%1/2
$sib->class eq "PPI::Token::Whitespace" and $sib->content =~ /[\015\012]+/
$sib->class eq "PPI::Token::Whitespace" $sib->content =~ /[\015\012]+/
Truth table66%2/3
A and B
A= $sib->class eq "PPI::Token::Whitespace"B= $sib->content =~ /[\015\012]+/
ABresult
0X0
100
111
691 {
692 1 $temp->{open_curly_nl}++;
693 1 push( @$nodes_to_replace, $sib );
694 }
695 else
696 {
697 13 push( @$nodes_to_replace, $sib );
698 }
699 }
700 # Check for new lines after closing blocks. The ones before, we can account for them in each section above
701 # We could have } catch {
702 # or
703 # }
704 # catch {
705 # etc.
706 # This could also be new lines following the last catch block
707 ▶ elsif( $sib->class eq 'PPI::Token::Whitespace' && $sib->content =~ /[\015\012]+/ )
Condition100%3/3
$sib->class eq "PPI::Token::Whitespace" and $sib->content =~ /[\015\012]+/
!ll&&!rl&&r
187215211
MC/DC100%2/2
$sib->class eq "PPI::Token::Whitespace" and $sib->content =~ /[\015\012]+/
$sib->class eq "PPI::Token::Whitespace" $sib->content =~ /[\015\012]+/
Truth table100%3/3
A and B
A= $sib->class eq "PPI::Token::Whitespace"B= $sib->content =~ /[\015\012]+/
ABresult
0X0
100
111
708 {
709 211 $nl_counter++;
710 211 push( @$buff, $sib );
711 }
712 else
713 {
714 402 push( @$buff, $sib );
715 }
716 1503 $prev_sib = $sib;
717 }
718
719 129 ▶ my $has_catch_clause = scalar( @$catch_def ) > 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @$catch_def > 0 ? : 119 10 129
720
721 # NOTE: processing finally block
722 # Prepare the finally block, if any, and add it below at the appropriate place
723 129 my $fin_block = '';
724 129 ▶ if( scalar( @$fin_block_ref ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$fin_block_ref) 13 116 129
725 {
726 13 my $fin_def = $fin_block_ref->[0];
727 13 $self->_process_sub_token( $fin_def->{block} );
728 13 $self->_process_caller( finally => $fin_def->{block} );
729 ## my $finally_block = $fin_def->{block}->content;
730 13 my $finally_block = $self->_serialize( $fin_def->{block} );
731 13 $finally_block =~ s/^\{[[:blank:]]*|[[:blank:]]*\}$//gs;
732 13 $fin_block = <<EOT;
733 CORE::local \$Nice::Try::FINALLY = Nice\::Try\::ScopeGuard->_new(sub __FINALLY_OPEN_NL__{ __BLOCK_PLACEHOLDER__ __FINALLY__CLOSE_NL__}, [\@_], \$Nice::Try::CATCH_DIED);
734 EOT
735 13 ▶ $fin_block =~ s/\n/ /gs unless( $self->{debug_code} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug_code"} 13 0 13
736 13 $fin_block =~ s/__BLOCK_PLACEHOLDER__/$finally_block/gs;
737 13 ▶ if( $fin_def->{open_curly_nl} )
Branch: 1 branch
BranchTrueFalseTotal
if ($fin_def->{'open_curly_nl'}) { } 1 12 13
738 {
739 1 $fin_block =~ s/__FINALLY_OPEN_NL__/"\n" x $fin_def->{open_curly_nl}/gex;
740 }
741 else
742 {
743 12 $fin_block =~ s/__FINALLY_OPEN_NL__//gs;
744 }
745 13 ▶ if( $fin_def->{close_curly_nl} )
Branch: 1 branch
BranchTrueFalseTotal
if ($fin_def->{'close_curly_nl'}) { } 0 13 13
746 {
747 0 $fin_block =~ s/__FINALLY__CLOSE_NL__/"\n" x $fin_def->{close_curly_nl}/gex;
748 }
749 else
750 {
751 13 $fin_block =~ s/__FINALLY__CLOSE_NL__//gs;
752 }
753 }
754  
755 # NOTE: processing try blocks
756 # Found any try block at all?
757 129 ▶ if( scalar( @$try_block_ref ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$try_block_ref) { } 127 2 129
758 {
759 127 my $try_def = $try_block_ref->[0];
760
761 # Checking for embedded try-catch
762 127 ▶ if( my $emb = $self->_parse( $try_def->{block} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $emb = $self->_parse($try_def->{"block"})) 3 124 127
763 {
764 3 $try_def->{block} = $emb;
765 }
766
767 127 $self->_process_loop_breaks( $try_def->{block} );
768 # NOTE: process, in try block, __SUB__ which reference current sub since perl v5.16
769 127 $self->_process_sub_token( $try_def->{block} );
770 127 $self->_process_caller( try => $try_def->{block} );
771
772 # my $try_block = $try_def->{block}->content;
773 127 my $try_block = $self->_serialize( $try_def->{block} );
774 127 $try_block =~ s/^\{[[:blank:]]*|[[:blank:]]*\}$//gs;
775
776 127 my $try_sub = <<EOT;
777 CORE::local \$Nice::Try::THREADED;
778 if( \$INC{'threads.pm'} && !CORE::exists( \$INC{'forks.pm'} ) )
779 {
780 \$Nice::Try::THREADED = threads->tid;
781 }
782 CORE::local \$Nice::Try::WANT;
783 CORE::local ( \$Nice::Try::EXCEPTION, \$Nice::Try::DIED, \$Nice::Try::CATCH_DIED, \@Nice::Try::RETVAL, \@Nice::Try::VOID, \$Nice::Try::RETURN );
784 CORE::local \$Nice::Try::WANTARRAY = CORE::wantarray;
785 CORE::local \$Nice::Try::RETURN = sub
786 {
787 \$Nice::Try::NEED_TO_RETURN++;
788 return( wantarray() ? \@_ : \$_[0] );
789 };
790 EOT
791 127 ▶ if( !$self->{is_tied} && !$self->{dont_want} && !$self->{is_overloaded} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"is_tied"} or $self->{"dont_want"} or $self->{"is_overloaded"}) 127 0 127
Condition33%2/6
$self->{"is_tied"} or $self->{"dont_want"} or $self->{"is_overloaded"}
l!l&&r!l&&!r
00127
$self->{"is_tied"} or $self->{"dont_want"}
l!l&&r!l&&!r
00127
MC/DC0%0/3
$self->{"is_tied"} or $self->{"dont_want"} or $self->{"is_overloaded"}
$self->{"is_tied"} $self->{"dont_want"} $self->{"is_overloaded"}
Truth table25%1/4
A or B or C
A= $self->{"is_tied"}B= $self->{"dont_want"}C= $self->{"is_overloaded"}
ABCresult
1XX1
01X1
0011
0000
792 {
793 127 $try_sub .= <<EOT;
794 CORE::local \$Nice::Try::NOOP = sub
795 {
796 my \$ref = CORE::shift( \@_ );
797 CORE::return(sub{ CORE::return( \$ref ) });
798 };
799 if( CORE::defined( \$Nice::Try::WANTARRAY ) && !\$Nice::Try::THREADED && !( !CORE::length( [CORE::caller]->[1] ) && [CORE::caller(1)]->[3] eq '(eval)' ) )
800 {
801 CORE::eval "\\\$Nice::Try::WANT = Wanted::want( 'LIST' )
802 ? 'LIST'
803 : Wanted::want( 'HASH' )
804 ? 'HASH'
805 : Wanted::want( 'ARRAY' )
806 ? 'ARRAY'
807 : Wanted::want( 'OBJECT' )
808 ? 'OBJECT'
809 : Wanted::want( 'CODE' )
810 ? 'CODE'
811 : Wanted::want( 'REFSCALAR' )
812 ? 'REFSCALAR'
813 : Wanted::want( 'BOOL' )
814 ? 'BOOLEAN'
815 : Wanted::want( 'GLOB' )
816 ? 'GLOB'
817 : Wanted::want( 'SCALAR' )
818 ? 'SCALAR'
819 : Wanted::want( 'VOID' )
820 ? 'VOID'
821 : '';";
822 undef( \$Nice::Try::WANT ) if( \$\@ );
823 }
824 EOT
825 }
826 127 $try_sub .= <<EOT;
827 CORE::local \$Nice::Try::TRY = CORE::sub
828 {
829 \@Nice::Try::LAST_VAL = CORE::do __TRY_OPEN_NL__{ __BLOCK_PLACEHOLDER__ };__TRY__CLOSE_NL__
830 CORE::return( \@Nice::Try::LAST_VAL ) if( !CORE::defined( \$Nice::Try::WANTARRAY ) && CORE::scalar( \@Nice::Try::LAST_VAL ) );
831 \$Nice::Try::VOID[0] = \$Nice::Try::SENTINEL;
832 if( CORE::defined( \$Nice::Try::WANT ) && CORE::length( \$Nice::Try::WANT ) )
833 {
834 if( \$Nice::Try::WANT eq 'OBJECT' )
835 {
836 CORE::return( Nice::Try::ObjectContext->new( sub{ \$Nice::Try::VOID[0] } )->callback() );
837 }
838 elsif( \$Nice::Try::WANT eq 'CODE' )
839 {
840 CORE::return( sub{ \$Nice::Try::VOID[0] } );
841 }
842 elsif( \$Nice::Try::WANT eq 'HASH' )
843 {
844 CORE::return( { dummy => \$Nice::Try::VOID[0] } );
845 }
846 elsif( \$Nice::Try::WANT eq 'ARRAY' )
847 {
848 CORE::return( [ \$Nice::Try::VOID[0] ] );
849 }
850 elsif( \$Nice::Try::WANT eq 'REFSCALAR' )
851 {
852 CORE::return( \\\$Nice::Try::VOID[0] );
853 }
854 elsif( \$Nice::Try::WANT eq 'GLOB' )
855 {
856 CORE::return( \*{ \$Nice::Try::VOID[0] } );
857 }
858 elsif( \$Nice::Try::WANT eq 'LIST' )
859 {
860 CORE::return( \$Nice::Try::VOID[0] );
861 }
862 elsif( \$Nice::Try::WANT eq 'BOOLEAN' )
863 {
864 CORE::return( \$Nice::Try::VOID[0] );
865 }
866 elsif( \$Nice::Try::WANT eq 'VOID' )
867 {
868 CORE::return( \$Nice::Try::VOID[0] );
869 }
870 elsif( \$Nice::Try::WANT eq 'SCALAR' )
871 {
872 CORE::return( \$Nice::Try::VOID[0] );
873 }
874 }
875 else
876 {
877 if( \$Nice::Try::WANTARRAY )
878 {
879 CORE::return( \$Nice::Try::VOID[0] );
880 }
881 elsif( defined( \$Nice::Try::WANTARRAY ) )
882 {
883 CORE::return( \$Nice::Try::VOID[0] );
884 }
885 else
886 {
887 CORE::return( \$Nice::Try::VOID[0] );
888 }
889 }
890 };
891 __FINALLY_BLOCK__ CORE::local \$Nice::Try::HAS_CATCH = $has_catch_clause;
892 EOT
893 127 $try_sub .= <<EOT;
894 {
895 CORE::local \$\@;
896 CORE::eval
897 {
898 EOT
899 127 ▶ if( $] >= 5.036000 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.036") 127 0 127
900 {
901 127 $try_sub .= <<EOT;
902 no warnings 'experimental::args_array_with_signatures';
903 EOT
904 }
905  
906 127 $try_sub .= <<EOT;
907 if( CORE::defined( \$Nice::Try::WANT ) && CORE::length( \$Nice::Try::WANT ) )
908 {
909 if( \$Nice::Try::WANT eq 'OBJECT' )
910 {
911 \$Nice::Try::RETVAL[0] = Nice::Try::ObjectContext->new( &\$Nice::Try::TRY )->callback();
912 }
913 elsif( \$Nice::Try::WANT eq 'CODE' )
914 {
915 \$Nice::Try::RETVAL[0] = \$Nice::Try::NOOP->( &\$Nice::Try::TRY )->();
916 }
917 elsif( \$Nice::Try::WANT eq 'HASH' )
918 {
919 \@Nice::Try::RETVAL = \%{ &\$Nice::Try::TRY };
920 }
921 elsif( \$Nice::Try::WANT eq 'ARRAY' )
922 {
923 \@Nice::Try::RETVAL = \@{ &\$Nice::Try::TRY };
924 }
925 elsif( \$Nice::Try::WANT eq 'REFSCALAR' )
926 {
927 \$Nice::Try::RETVAL[0] = \${&\$Nice::Try::TRY};
928 }
929 elsif( \$Nice::Try::WANT eq 'GLOB' )
930 {
931 \$Nice::Try::RETVAL[0] = \*{ &\$Nice::Try::TRY };
932 }
933 elsif( \$Nice::Try::WANT eq 'LIST' )
934 {
935 \@Nice::Try::RETVAL = &\$Nice::Try::TRY;
936 }
937 elsif( \$Nice::Try::WANT eq 'BOOLEAN' )
938 {
939 \$Nice::Try::RETVAL[0] = &\$Nice::Try::TRY ? 1 : 0;
940 \$Nice::Try::RETVAL[0] = \$Nice::Try::VOID[0] if( scalar( \@Nice::Try::VOID ) );
941 }
942 elsif( \$Nice::Try::WANT eq 'VOID' )
943 {
944 \@Nice::Try::VOID = &\$Nice::Try::TRY;
945 }
946 elsif( \$Nice::Try::WANT eq 'SCALAR' )
947 {
948 \$Nice::Try::RETVAL[0] = &\$Nice::Try::TRY;
949 }
950 }
951 else
952 {
953 if( \$Nice::Try::WANTARRAY )
954 {
955 \@Nice::Try::RETVAL = &\$Nice::Try::TRY;
956 }
957 elsif( defined( \$Nice::Try::WANTARRAY ) )
958 {
959 \$Nice::Try::RETVAL[0] = &\$Nice::Try::TRY;
960 }
961 else
962 {
963 &\$Nice::Try::TRY;
964 \$Nice::Try::RETVAL[0] = \$Nice::Try::LAST_VAL if( CORE::defined( \$Nice::Try::LAST_VAL ) );
965 }
966 }
967 };
968 \$Nice::Try::DIED = CORE::length( \$\@ ) ? 1 : 0;
969 \$\@ =~ s/[\\015\\012]+\$//g unless( Scalar::Util::blessed( \$\@ ) );
970 \$Nice::Try::EXCEPTION = \$\@;
971 };
972  
973 EOT
974 127 ▶ $try_sub =~ s/\n/ /gs unless( $self->{debug_code} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug_code"} 127 0 127
975 127 $try_sub =~ s/__BLOCK_PLACEHOLDER__/$try_block/gs;
976 127 ▶ if( $try_def->{open_curly_nl} )
Branch: 1 branch
BranchTrueFalseTotal
if ($try_def->{'open_curly_nl'}) { } 79 48 127
977 {
978 79 $try_sub =~ s/__TRY_OPEN_NL__/"\n" x $try_def->{open_curly_nl}/gex;
979 }
980 else
981 {
982 48 $try_sub =~ s/__TRY_OPEN_NL__//gs;
983 }
984 127 ▶ if( $try_def->{close_curly_nl} )
Branch: 1 branch
BranchTrueFalseTotal
if ($try_def->{'close_curly_nl'}) { } 115 12 127
985 {
986 115 $try_sub =~ s/__TRY__CLOSE_NL__/"\n" x $try_def->{close_curly_nl}/gex;
987 }
988 else
989 {
990 12 $try_sub =~ s/__TRY__CLOSE_NL__//gs;
991 }
992
993 # Add the final block if there is no catch block, otherwise the final block comes at the end below
994 127 ▶ if( !$has_catch_clause )
Branch: 1 branch
BranchTrueFalseTotal
if (not $has_catch_clause) { } 8 119 127
995 {
996 8 $try_sub =~ s/__FINALLY_BLOCK__/$fin_block/gs;
997 }
998 # If it should not be here, remove the placeholder
999 else
1000 {
1001 119 $try_sub =~ s/__FINALLY_BLOCK__//gs;
1002 }
1003 127 push( @$repl, $try_sub );
1004 }
1005 else
1006 {
1007 2 next;
1008 }
1009
1010 # NOTE: processing catch block
1011 127 my $if_start = <<EOT;
1012 if( \$Nice::Try::DIED )
1013 {
1014 if( \$Nice::Try::HAS_CATCH )
1015 {
1016 EOT
1017 127 ▶ if( $] >= 5.036000 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.036") 127 0 127
1018 {
1019 127 $if_start .= <<EOT;
1020 no warnings 'experimental::args_array_with_signatures';
1021 EOT
1022 }
1023 127 ▶ $if_start =~ s/\n/ /gs unless( $self->{debug_code} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug_code"} 127 0 127
1024 127 push( @$catch_repl, $if_start );
1025 127 ▶ if( scalar( @$catch_def ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$catch_def) { } 119 8 127
1026 {
1027 119 my $total_catch = scalar( @$catch_def );
1028 # To count how many times we have else's – obviously we should not have more than 1
1029 119 my $else = 0;
1030 119 ▶ for( my $i = 0; $i < $total_catch; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $total_catch) 143 119 262
1031 {
1032 143 my $cdef = $catch_def->[$i];
1033 # Checking for embedded try-catch
1034 143 ▶ if( my $emb = $self->_parse( $cdef->{block} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $emb = $self->_parse($cdef->{"block"})) 1 142 143
1035 {
1036 1 $cdef->{block} = $emb;
1037 }
1038 # NOTE: process, in catch block, __SUB__ which reference current sub since perl v5.16
1039 143 $self->_process_sub_token( $cdef->{block} );
1040
1041 143 ▶ if( $cdef->{var} )
Branch: 1 branch
BranchTrueFalseTotal
if ($cdef->{'var'}) { } 109 34 143
1042 {
1043 109 $cdef->{var}->prune( 'PPI::Token::Comment' );
1044 109 $cdef->{var}->prune( 'PPI::Token::Pod' );
1045 109 ▶ $self->_messagef( 3, "Catch assignment is: '%s'", $cdef->{var}->content ) if( $self->{debug} >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 109 109
1046 # my $str = $cdef->{var}->content;
1047 109 my $str = $self->_serialize( $cdef->{var} );
1048 109 $str =~ s/^\([[:blank:]\h\v]*|[[:blank:]]*\)$//g;
1049 # My::Exception $e
1050 109 ▶ if( $str =~ /^(\S+)[[:blank:]\h\v]+(\$\S+)$/ )
Branch: 5 branches
BranchTrueFalseTotal
if ($str =~ /^(\S+)[[:blank:]\h\v]+(\$\S+)$/) { } 15 94 109
elsif ($str =~ /^(\S+)[[:blank:]\h\v]+(\$\S+)[[:blank:]\h\v]+where[[:blank:]\h\v]+\{(.*?)\}$/) { } 4 90 94
elsif ($str =~ /^(\$\S+)[[:blank:]\h\v]+where[[:blank:]\h\v]+\{(.*?)\}$/) { } 1 89 90
elsif ($str =~ /^(\$\S+)[[:blank:]\h\v]+isa[[:blank:]\h\v]+(\S+)(?:[[:blank:]\h\v]+where[[:blank:]\h\v]+\{(.*?)\})?$/) { } 9 80 89
elsif ($str =~ /^(?<var>\$\S+)[[:blank:]\h\v]+isa[[:blank:]\h\v]*\([[:blank:]\h\v]*(?<quote>["'])?(?<class>[^[:blank:]\h\v\'\"\)]+)\k{quote}[[:blank:]\h\v]*\)(?:[[:blank:]\h\v]+where[[:blank:]\h\v]+\{(?<where>.*?)\})?$/) { } 2 78 80
1051 {
1052 15 @$cdef{qw( class var )} = ( $1, $2 );
1053 }
1054 elsif( $str =~ /^(\S+)[[:blank:]\h\v]+(\$\S+)[[:blank:]\h\v]+where[[:blank:]\h\v]+\{(.*?)\}$/ )
1055 {
1056 4 @$cdef{qw( class var where )} = ( $1, $2, $3 );
1057 }
1058 elsif( $str =~ /^(\$\S+)[[:blank:]\h\v]+where[[:blank:]\h\v]+\{(.*?)\}$/ )
1059 {
1060 1 @$cdef{qw( var where )} = ( $1, $2 );
1061 }
1062 elsif( $str =~ /^(\$\S+)[[:blank:]\h\v]+isa[[:blank:]\h\v]+(\S+)(?:[[:blank:]\h\v]+where[[:blank:]\h\v]+\{(.*?)\})?$/ )
1063 {
1064 9 @$cdef{qw( var class where )} = ( $1, $2, $3 );
1065 }
1066 elsif( $str =~ /^(?<var>\$\S+)[[:blank:]\h\v]+isa[[:blank:]\h\v]*\([[:blank:]\h\v]*(?<quote>["'])?(?<class>[^[:blank:]\h\v\'\"\)]+)\k{quote}[[:blank:]\h\v]*\)(?:[[:blank:]\h\v]+where[[:blank:]\h\v]+\{(?<where>.*?)\})?$/ )
1067 {
1068 2 @$cdef{qw( var class where )} = ( $+{var}, $+{class}, $+{where} );
1069 }
1070 else
1071 {
1072 78 $cdef->{var} = $str;
1073 }
1074 }
1075 else
1076 {
1077 # $self->_message( 3, "No Catch assignment found" ) if( $self->{debug} >= 3 );
1078 }
1079
1080 143 ▶ if( $cdef->{block} )
Branch: 1 branch
BranchTrueFalseTotal
if ($cdef->{'block'}) { } 143 0 143
1081 {
1082 # $self->_messagef( 3, "Catch block is:\n%s", $cdef->{block}->content ) if( $self->{debug} >= 3 );
1083 }
1084 else
1085 {
1086 # $self->_message( 3, "No catch block found!" ) if( $self->{debug} >= 3 );
1087 0 next;
1088 }
1089 143 my $cond;
1090 143 ▶ if( $i == 0 )
Branch: 2 branches
BranchTrueFalseTotal
if ($i == 0) { } 119 24 143
elsif ($i == $total_catch - 1) { } 11 13 24
1091 {
1092 119 $cond = 'if';
1093 }
1094 elsif( $i == ( $total_catch - 1 ) )
1095 {
1096 $cond = $total_catch == 1
1097 ? 'if'
1098 : $cdef->{class}
1099 11 ▶ ? 'elsif'
Branch: 2 branches
BranchTrueFalseTotal
$total_catch == 1 ? : 0 11 11
$cdef->{'class'} ? : 2 9 11
1100 : 'else';
1101 }
1102 else
1103 {
1104 13 $cond = 'elsif';
1105 }
1106 # my $block = $cdef->{block}->content;
1107 143 $self->_process_loop_breaks( $cdef->{block} );
1108 143 $self->_process_sub_token( $cdef->{block} );
1109 143 $self->_process_caller( catch => $cdef->{block} );
1110 143 my $block = $self->_serialize( $cdef->{block} );
1111 143 $block =~ s/^\{[[:blank:]]*|[[:blank:]]*\}$//gs;
1112 143 my $catch_section = '';
1113 143 my $catch_code = <<EOT;
1114 CORE::local \$Nice::Try::CATCH = CORE::sub
1115 {
1116 \@Nice::Try::LAST_VAL = CORE::do __CATCH_OPEN_NL__{ __BLOCK_PLACEHOLDER__ }; __CATCH__CLOSE_NL__
1117 CORE::return( \@Nice::Try::LAST_VAL ) if( !CORE::defined( \$Nice::Try::WANTARRAY ) && CORE::scalar( \@Nice::Try::LAST_VAL ) );
1118 CORE::return \$Nice::Try::SENTINEL;
1119 };
1120
1121 eval
1122 {
1123 local \$\@ = \$Nice::Try::EXCEPTION;
1124 if( CORE::defined( \$Nice::Try::WANT ) && CORE::length( \$Nice::Try::WANT ) )
1125 {
1126 if( \$Nice::Try::WANT eq 'OBJECT' )
1127 {
1128 \$Nice::Try::RETVAL[0] = Nice::Try::ObjectContext->new( \&\$Nice::Try::CATCH )->callback();
1129 }
1130 elsif( \$Nice::Try::WANT eq 'CODE' )
1131 {
1132 \$Nice::Try::RETVAL[0] = \$Nice::Try::NOOP->( \&\$Nice::Try::CATCH )->();
1133 }
1134 elsif( \$Nice::Try::WANT eq 'HASH' )
1135 {
1136 \@Nice::Try::RETVAL = \%{ \&\$Nice::Try::CATCH };
1137 }
1138 elsif( \$Nice::Try::WANT eq 'ARRAY' )
1139 {
1140 \@Nice::Try::RETVAL = \@{ \&\$Nice::Try::CATCH };
1141 }
1142 elsif( \$Nice::Try::WANT eq 'REFSCALAR' )
1143 {
1144 \$Nice::Try::RETVAL[0] = \${\&\$Nice::Try::CATCH};
1145 }
1146 elsif( \$Nice::Try::WANT eq 'GLOB' )
1147 {
1148 \$Nice::Try::RETVAL[0] = \*{ \&\$Nice::Try::CATCH };
1149 }
1150 elsif( \$Nice::Try::WANT eq 'LIST' )
1151 {
1152 \@Nice::Try::RETVAL = \&\$Nice::Try::CATCH;
1153 }
1154 elsif( \$Nice::Try::WANT eq 'BOOLEAN' )
1155 {
1156 my \$this = \&\$Nice::Try::CATCH ? 1 : 0;
1157 \$Nice::Try::RETVAL[0] = \$Nice::Try::VOID[0] if( scalar( \@Nice::Try::VOID ) );
1158 }
1159 elsif( \$Nice::Try::WANT eq 'VOID' )
1160 {
1161 \@Nice::Try::VOID = \&\$Nice::Try::CATCH;
1162 }
1163 elsif( \$Nice::Try::WANT eq 'SCALAR' )
1164 {
1165 \$Nice::Try::RETVAL[0] = \&\$Nice::Try::CATCH;
1166 }
1167 }
1168 else
1169 {
1170 if( \$Nice::Try::WANTARRAY )
1171 {
1172 \@Nice::Try::RETVAL = \&\$Nice::Try::CATCH;
1173 }
1174 elsif( defined( \$Nice::Try::WANTARRAY ) )
1175 {
1176 \$Nice::Try::RETVAL[0] = \&\$Nice::Try::CATCH;
1177 }
1178 else
1179 {
1180 \&\$Nice::Try::CATCH;
1181 }
1182 }
1183 };
1184 \$Nice::Try::CATCH_DIED = \$\@ if( \$\@ );
1185 EOT
1186 143 ▶ if( $cdef->{var} )
Branch: 1 branch
BranchTrueFalseTotal
if ($cdef->{'var'}) { } 109 34 143
1187 {
1188 109 my $ex_var = $cdef->{var};
1189 109 ▶ if( $cdef->{class} && $cdef->{where} )
Branch: 3 branches
BranchTrueFalseTotal
if ($cdef->{'class'} and $cdef->{'where'}) { } 12 97 109
elsif ($cdef->{'class'}) { } 18 79 97
elsif ($cdef->{'where'}) { } 1 78 79
Condition100%3/3
$cdef->{"class"} and $cdef->{"where"}
!ll&&!rl&&r
791812
MC/DC100%2/2
$cdef->{"class"} and $cdef->{"where"}
$cdef->{"class"} $cdef->{"where"}
Truth table100%3/3
A and B
A= $cdef->{"class"}B= $cdef->{"where"}
ABresult
0X0
100
111
1190 {
1191 12 my $ex_class = $cdef->{class};
1192 12 my $eval = "q{CORE::local \$_ = \$Nice::Try::EXCEPTION; my $ex_var = \$Nice::Try::EXCEPTION; CORE::local \$\@ = \$Nice::Try::EXCEPTION; $cdef->{where}}";
1193 12 $catch_section = <<EOT;
1194 ${cond}( Scalar::Util::blessed( \$Nice::Try::EXCEPTION ) && \$Nice::Try::EXCEPTION->isa( '$ex_class' ) && CORE::eval( $eval ) )
1195 {
1196 CORE::local \$\@ = \$Nice::Try::EXCEPTION;
1197 my $ex_var = \$Nice::Try::EXCEPTION;
1198 $catch_code
1199 }
1200 EOT
1201 }
1202 elsif( $cdef->{class} )
1203 {
1204 18 my $ex_class = $cdef->{class};
1205 # Tilmann Haeberle (TH) 2021-03-25: Fix: properly test for exception class inheritance via ->isa
1206 18 $catch_section = <<EOT;
1207 ${cond}( Scalar::Util::blessed( \$Nice::Try::EXCEPTION ) && \$Nice::Try::EXCEPTION->isa( '$ex_class' ) )
1208 {
1209 CORE::local \$\@ = \$Nice::Try::EXCEPTION;
1210 my $ex_var = \$Nice::Try::EXCEPTION;
1211 $catch_code
1212 }
1213 EOT
1214 }
1215 elsif( $cdef->{where} )
1216 {
1217 1 my $eval = "q{CORE::local \$_ = \$Nice::Try::EXCEPTION; my $ex_var = \$Nice::Try::EXCEPTION; CORE::local \$\@ = \$Nice::Try::EXCEPTION; $cdef->{where}}";
1218 1 $catch_section = <<EOT;
1219 ${cond}( CORE::eval( $eval ) )
1220 {
1221 CORE::local \$\@ = \$Nice::Try::EXCEPTION;
1222 my $ex_var = \$Nice::Try::EXCEPTION;
1223 $catch_code
1224 }
1225 EOT
1226 }
1227 # No class, just variable assignment like $e or something
1228 else
1229 {
1230 78 ▶ if( ++$else > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (++$else > 1) 0 78 78
1231 {
1232 # CORE::warn( "Cannot have more than one falllback catch clause for block: ", $cdef->{block}->content, "\n" ) if( warnings::enabled );
1233 0 ▶ CORE::warn( "Cannot have more than one falllback catch clause for block: ", $self->_serialize( $cdef->{block} ), "\n" ) if( warnings::enabled );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1234 # Skip, not die. Not fatal, just ignored
1235 0 next;
1236 }
1237 78 ▶ $cond = "${cond}( 1 )" if( $cond eq 'if' || $cond eq 'elsif' );
Branch: 1 branch
BranchTrueFalseTotal
if $cond eq "if" or $cond eq "elsif" 69 9 78
Condition66%2/3
$cond eq "if" or $cond eq "elsif"
l!l&&r!l&&!r
6909
MC/DC50%1/2
$cond eq "if" or $cond eq "elsif"
$cond eq "if" $cond eq "elsif"
Truth table66%2/3
A or B
A= $cond eq "if"B= $cond eq "elsif"
ABresult
1X1
011
000
1238 78 $catch_section = <<EOT;
1239 ${cond}
1240 {
1241 CORE::local \$\@ = \$Nice::Try::EXCEPTION;
1242 my $ex_var = \$Nice::Try::EXCEPTION;
1243 $catch_code
1244 }
1245 EOT
1246 }
1247 }
1248 # No variable assignment like $e
1249 else
1250 {
1251 34 ▶ $cond = "${cond}( 1 )" if( $cond eq 'if' || $cond eq 'elsif' );
Branch: 1 branch
BranchTrueFalseTotal
if $cond eq "if" or $cond eq "elsif" 34 0 34
Condition33%1/3
$cond eq "if" or $cond eq "elsif"
l!l&&r!l&&!r
3400
MC/DC0%0/2
$cond eq "if" or $cond eq "elsif"
$cond eq "if" $cond eq "elsif"
Truth table33%1/3
A or B
A= $cond eq "if"B= $cond eq "elsif"
ABresult
1X1
011
000
1252 34 $catch_section = <<EOT;
1253 ${cond}
1254 {
1255 CORE::local \$\@ = \$Nice::Try::EXCEPTION;
1256 $catch_code
1257 }
1258 EOT
1259 }
1260 143 ▶ $catch_section =~ s/\n/ /gs unless( $self->{debug_code} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug_code"} 143 0 143
1261 143 $catch_section =~ s/__BLOCK_PLACEHOLDER__/$block/gs;
1262 143 ▶ if( $cdef->{open_curly_nl} )
Branch: 1 branch
BranchTrueFalseTotal
if ($cdef->{'open_curly_nl'}) { } 98 45 143
1263 {
1264 98 $catch_section =~ s/__CATCH_OPEN_NL__/"\n" x $cdef->{open_curly_nl}/gex;
1265 }
1266 else
1267 {
1268 45 $catch_section =~ s/__CATCH_OPEN_NL__//gs;
1269 }
1270 143 ▶ if( $cdef->{close_curly_nl} )
Branch: 1 branch
BranchTrueFalseTotal
if ($cdef->{'close_curly_nl'}) { } 27 116 143
1271 {
1272 27 $catch_section =~ s/__CATCH__CLOSE_NL__/"\n" x $cdef->{close_curly_nl}/gex;
1273 }
1274 else
1275 {
1276 116 $catch_section =~ s/__CATCH__CLOSE_NL__//gs;
1277 }
1278 143 push( @$catch_repl, $catch_section );
1279 }
1280 # End catch loop
1281 # Tilmann Haeberle (TH) 2021-03-25: Fix: put an else at the end to avoid 'fall_through' issue unless an else exists already
1282 119 my $if_end;
1283 119 ▶ if( $else )
Branch: 1 branch
BranchTrueFalseTotal
if ($else) { } 78 41 119
1284 {
1285 78 $if_end = <<EOT;
1286 }
1287 EOT
1288 }
1289 else
1290 {
1291 41 $if_end = <<EOT;
1292 else
1293 {
1294 die( \$Nice::Try::EXCEPTION );
1295 }
1296 }
1297 EOT
1298 }
1299 119 ▶ $if_end =~ s/\n/ /g unless( $self->{debug_code} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug_code"} 119 0 119
1300 119 push( @$catch_repl, $if_end );
1301 }
1302 # No catch clause
1303 else
1304 {
1305 # If the try-catch block is called inside an eval, propagate the exception
1306 # Otherwise, we just make the $@ available
1307 8 my $catch_else = <<EOT;
1308 }
1309 else
1310 {
1311 if( CORE::defined( (CORE::caller(0))[3] ) && (CORE::caller(0))[3] eq '(eval)' )
1312 {
1313 CORE::die( \$Nice::Try::EXCEPTION );
1314 }
1315 else
1316 {
1317 \$\@ = \$Nice::Try::EXCEPTION;
1318 }
1319 }
1320 EOT
1321 8 ▶ $catch_else =~ s/\n/ /g unless( $self->{debug_code} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug_code"} 8 0 8
1322 8 push( @$catch_repl, $catch_else );
1323 }
1324
1325 # Add
1326 127 ▶ my $catch_res = scalar( @$catch_repl ) ? join( '', @$catch_repl ) : '';
Branch: 1 branch
BranchTrueFalseTotal
scalar @$catch_repl ? : 127 0 127
1327 127 ▶ push( @$repl, $catch_res ) if( $catch_res );
Branch: 1 branch
BranchTrueFalseTotal
if $catch_res 127 0 127
1328 # Closing the If DIED condition
1329 127 push( @$repl, "\};" );
1330  
1331 # If there is a catch clause, we put the final block here, if any
1332 127 ▶ if( $has_catch_clause && CORE::length( $fin_block ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_catch_clause and length $fin_block) 7 120 127
Condition100%3/3
$has_catch_clause and length $fin_block
!ll&&!rl&&r
81127
MC/DC100%2/2
$has_catch_clause and length $fin_block
$has_catch_clause length $fin_block
Truth table100%3/3
A and B
A= $has_catch_clauseB= length $fin_block
ABresult
0X0
100
111
1333 {
1334 7 push( @$repl, $fin_block );
1335 }
1336
1337 # After the finally block has been registered, we will die if catch had a fatal error
1338 127 my $catch_dies = <<EOT;
1339 if( defined( \$Nice::Try::CATCH_DIED ) )
1340 {
1341 die( \$Nice::Try::CATCH_DIED );
1342 }
1343 EOT
1344 127 ▶ $catch_dies =~ s/\n/ /gs unless( $self->{debug_code} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug_code"} 127 0 127
1345 127 push( @$repl, $catch_dies );
1346
1347 127 my $last_return_block = <<EOT;
1348 if( ( CORE::defined( \$Nice::Try::WANTARRAY ) || ( defined( \$Nice::Try::BREAK ) && \$Nice::Try::BREAK eq 'return' ) ) and
1349 (
1350 !Scalar::Util::blessed( \$Nice::Try::RETVAL[0] ) or
1351 ( Scalar::Util::blessed( \$Nice::Try::RETVAL[0] ) && !\$Nice::Try::RETVAL[0]->isa( 'Nice::Try::SENTINEL' ) )
1352 ) )
1353 {
1354 \$Nice::Try::NEED_TO_RETURN++ if( defined( \$Nice::Try::BREAK ) && \$Nice::Try::BREAK eq 'return' );
1355 no warnings 'void';
1356 EOT
1357 127 ▶ if( CORE::scalar( CORE::keys( %warnings:: ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %main::warnings:: and exists $warnings::Bits{"args_array_with_signatures"}) 0 127 127
Condition33%1/3
scalar keys %main::warnings:: and exists $warnings::Bits{"args_array_with_signatures"}
!ll&&!rl&&r
01270
MC/DC0%0/2
scalar keys %main::warnings:: and exists $warnings::Bits{"args_array_with_signatures"}
scalar keys %main::warnings:: exists $warnings::Bits{"args_array_with_signatures"}
Truth table33%1/3
A and B
A= scalar keys %main::warnings::B= exists $warnings::Bits{"args_array_with_signatures"}
ABresult
0X0
100
111
1358 CORE::exists( $warnings::Bits{args_array_with_signatures} ) )
1359 {
1360 0 $last_return_block .= <<EOT;
1361 no warnings 'experimental::args_array_with_signatures';
1362 EOT
1363 }
1364 127 $last_return_block .= <<EOT;
1365 if( !CORE::defined( \$Nice::Try::BREAK ) || \$Nice::Try::BREAK eq 'return' )
1366 {
1367 if( CORE::defined( \$Nice::Try::WANT ) && CORE::length( \$Nice::Try::WANT ) )
1368 {
1369 if( \$Nice::Try::WANT eq 'LIST' )
1370 {
1371 \$Nice::Try::NEED_TO_RETURN ? CORE::return( \@Nice::Try::RETVAL ) : \@Nice::Try::RETVAL;
1372 }
1373 elsif( \$Nice::Try::WANT eq 'VOID' )
1374 {
1375 if( CORE::defined( \$Nice::Try::RETVAL[0] ) && \$Nice::Try::RETVAL[0] eq '__NEXT__' )
1376 {
1377 \$Nice::Try::BREAK = 'next';
1378 }
1379 elsif( CORE::defined( \$Nice::Try::RETVAL[0] ) && \$Nice::Try::RETVAL[0] eq '__LAST__' )
1380 {
1381 \$Nice::Try::BREAK = 'last';
1382 }
1383 elsif( CORE::defined( \$Nice::Try::RETVAL[0] ) && \$Nice::Try::RETVAL[0] eq '__REDO__' )
1384 {
1385 \$Nice::Try::BREAK = 'redo';
1386 }
1387 elsif( defined( \$Nice::Try::BREAK ) && \$Nice::Try::BREAK eq 'return' )
1388 {
1389 \$Nice::Try::NEED_TO_RETURN ? CORE::return( \$Nice::Try::RETVAL[0] ) : \$Nice::Try::RETVAL[0];
1390 }
1391 }
1392 elsif( \$Nice::Try::WANT eq 'OBJECT' )
1393 {
1394 \$Nice::Try::NEED_TO_RETURN ? CORE::return( \$Nice::Try::RETVAL[0] ) : \$Nice::Try::RETVAL[0];
1395 }
1396 elsif( \$Nice::Try::WANT eq 'REFSCALAR' )
1397 {
1398 \$Nice::Try::NEED_TO_RETURN ? CORE::return( \\\$Nice::Try::RETVAL[0] ) : \\\$Nice::Try::RETVAL[0];
1399 }
1400 elsif( \$Nice::Try::WANT eq 'SCALAR' )
1401 {
1402 \$Nice::Try::NEED_TO_RETURN ? CORE::return( \$Nice::Try::RETVAL[0] ) : \$Nice::Try::RETVAL[0];
1403 }
1404 elsif( \$Nice::Try::WANT eq 'BOOLEAN' )
1405 {
1406 \$Nice::Try::NEED_TO_RETURN ? CORE::return( \$Nice::Try::RETVAL[0] ) : \$Nice::Try::RETVAL[0];
1407 }
1408 elsif( \$Nice::Try::WANT eq 'CODE' )
1409 {
1410 \$Nice::Try::NEED_TO_RETURN ? CORE::return( \$Nice::Try::RETVAL[0] ) : \$Nice::Try::RETVAL[0];
1411 }
1412 elsif( \$Nice::Try::WANT eq 'HASH' )
1413 {
1414 \$Nice::Try::NEED_TO_RETURN ? CORE::return( { \@Nice::Try::RETVAL } ) : { \@Nice::Try::RETVAL };
1415 }
1416 elsif( \$Nice::Try::WANT eq 'ARRAY' )
1417 {
1418 \$Nice::Try::NEED_TO_RETURN ? CORE::return( \\\@Nice::Try::RETVAL ) : \\\@Nice::Try::RETVAL;
1419 }
1420 elsif( \$Nice::Try::WANT eq 'GLOB' )
1421 {
1422 \$Nice::Try::NEED_TO_RETURN ? CORE::return( \$Nice::Try::RETVAL[0] ) : \$Nice::Try::RETVAL[0];
1423 }
1424 }
1425 else
1426 {
1427 \$Nice::Try::NEED_TO_RETURN ? CORE::return( \$Nice::Try::WANTARRAY ? \@Nice::Try::RETVAL : \$Nice::Try::RETVAL[0] ) : \$Nice::Try::WANTARRAY ? \@Nice::Try::RETVAL : \$Nice::Try::RETVAL[0];
1428 }
1429 }
1430 }
1431 elsif( scalar( \@Nice::Try::VOID ) && ( !Scalar::Util::blessed( \$Nice::Try::VOID[0] ) || ( Scalar::Util::blessed( \$Nice::Try::VOID[0] ) && !\$Nice::Try::VOID[0]->isa( 'Nice::Try::SENTINEL' ) ) ) )
1432 {
1433 no warnings 'void';
1434 scalar( \@Nice::Try::VOID ) > 1 ? \@Nice::Try::VOID : \$Nice::Try::VOID[0];
1435 }
1436 EOT
1437 127 ▶ $last_return_block =~ s/\n/ /gs unless( $self->{debug_code} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug_code"} 127 0 127
1438 127 push( @$repl, $last_return_block );
1439 127 my $try_catch_code = join( '', @$repl );
1440 # my $token = PPI::Token->new( "; \{ $try_catch_code \}" ) || die( "Unable to create token" );
1441 # NOTE: 2021-05-11 (Jacques): Need to remove blocks so that next or last statements can be effective.
1442 127 my $envelop = <<EOT;
1443 ; CORE::local( \$Nice::Try::BREAK, \@Nice::Try::LAST_VAL ); local \$Nice::Try::NEED_TO_RETURN = 0 unless( defined( \$Nice::Try::NEED_TO_RETURN ) );
1444 \{
1445 __TRY_CATCH_CODE__
1446 \}
1447 if( CORE::defined( \$Nice::Try::BREAK ) )
1448 {
1449 if( \$Nice::Try::BREAK eq 'next' )
1450 {
1451 CORE::next;
1452 }
1453 elsif( \$Nice::Try::BREAK eq 'last' )
1454 {
1455 CORE::last;
1456 }
1457 elsif( \$Nice::Try::BREAK eq 'redo' )
1458 {
1459 CORE::redo;
1460 }
1461 }
1462 no warnings 'void';
1463 CORE::scalar( \@Nice::Try::LAST_VAL ) > 1 ? \@Nice::Try::LAST_VAL : \$Nice::Try::LAST_VAL[0];
1464 EOT
1465 127 ▶ $envelop =~ s/\n/ /gs unless( $self->{debug_code} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug_code"} 127 0 127
1466 127 $envelop =~ s/__TRY_CATCH_CODE__/$try_catch_code/;
1467 127 ▶ my $token = PPI::Token->new( $envelop ) || die( "Unable to create token" );
Condition50%1/2
'PPI::Token'->new($envelop) || die('Unable to create token')
l!l
1270
MC/DC0%0/1
'PPI::Token'->new($envelop) || die('Unable to create token')
'PPI::Token'->new($envelop)
Truth table50%1/2
A
A= 'PPI::Token'->new($envelop)
Aresult
11
00
1468 127 $token->set_class( 'Structure' );
1469 127 ▶ my $struct = PPI::Structure->new( $token ) || die( "Unable to create PPI::Structure element" );
Condition50%1/2
'PPI::Structure'->new($token) || die('Unable to create PPI::Structure element')
l!l
1270
MC/DC0%0/1
'PPI::Structure'->new($token) || die('Unable to create PPI::Structure element')
'PPI::Structure'->new($token)
Truth table50%1/2
A
A= 'PPI::Structure'->new($token)
Aresult
11
00
1470 127 my $orig_try_catch_block = join( '', @$nodes_to_replace );
1471 127 my $rc;
1472 127 ▶ if( !( $rc = $element_before_try->insert_after( $token ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($rc = $element_before_try->insert_after($token)) 0 127 127
1473 {
1474 0 $self->_error( "Failed to add replacement code of class '", $token->class, "' after '$element_before_try'" );
1475 0 next;
1476 }
1477 127 ▶ $self->_message( 3, "Return code is defined? ", defined( $rc ) ? "yes" : "no" ) if( $self->{debug} >= 3 );
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"debug"} >= 3 0 127 127
defined $rc ? : 0 0 0
1478
1479 127 ▶ for( my $k = 0; $k < scalar( @$nodes_to_replace ); $k++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($k < scalar @$nodes_to_replace) 1438 127 1565
1480 {
1481 1438 my $e = $nodes_to_replace->[$k];
1482 1438 ▶ $e->delete || warn( "Could not remove node No $k: '$e'\n" );
Branch: 1 branch
BranchTrueFalseTotal
$e->delete or warn "Could not remove node No ${k}: '${e}'\n" 1438 0 1438
1483 }
1484 }
1485 # End foreach catch found
1486  
1487 # NOTE: Do we have a __DATA__ or __END__ token ?
1488 34 ▶ if( $opts->{has_data} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"has_data"}) 13 21 34
1489 {
1490 my $ref = $elem->find(sub
1491 7720 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
1492 7720 my( $top, $this ) = @_;
1493 7720 ▶ return( ( $this->class eq 'PPI::Statement::Data' || $this->class eq 'PPI::Statement::End' ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$this->class eq 'PPI::Statement::Data' || $this->class eq 'PPI::Statement::End' ? : 13 7707 7720
Condition100%3/3
$this->class eq "PPI::Statement::Data" or $this->class eq "PPI::Statement::End"
l!l&&r!l&&!r
2117707
MC/DC100%2/2
$this->class eq "PPI::Statement::Data" or $this->class eq "PPI::Statement::End"
$this->class eq "PPI::Statement::Data" $this->class eq "PPI::Statement::End"
Truth table100%3/3
A or B
A= $this->class eq "PPI::Statement::Data"B= $this->class eq "PPI::Statement::End"
ABresult
1X1
011
000
1494 13 });
1495 13 ▶ warn( "Warning only: Failed to find any __DATA__ or __END__ token." ) if( !defined( $ref ) && warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ref and warnings::enabled() 0 13 13
Condition33%1/3
not defined $ref and warnings::enabled()
!ll&&!rl&&r
1300
MC/DC0%0/2
not defined $ref and warnings::enabled()
not defined $ref warnings::enabled()
Truth table33%1/3
not(A) and B
A= not defined $refB= warnings::enabled()
ABresult
0X0
100
111
1496 13 my $class = $self->{class};
1497 13 my $name = 'DATA';
1498 13 $self->_message( 4, "Found ", scalar( @$ref ), " DATA tokens." );
1499 # There must be only one: either __DATA__ or __END__, so we process it, and exit the loop.
1500 13 foreach my $this ( @$ref )
1501 {
1502 13 $self->_message( 4, "DATA or END token found." );
1503 13 ▶ $self->_browse( $this ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 13 13
1504 my $tokens = $this->find(sub
1505 39 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
1506 39 my( $top, $this ) = @_;
1507 # PPI::Token::End
1508 39 ▶ return( ( $this->class eq 'PPI::Token::Data' || $this->class eq 'PPI::Token::End' ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$this->class eq 'PPI::Token::Data' || $this->class eq 'PPI::Token::End' ? : 12 27 39
Condition100%3/3
$this->class eq "PPI::Token::Data" or $this->class eq "PPI::Token::End"
l!l&&r!l&&!r
21027
MC/DC100%2/2
$this->class eq "PPI::Token::Data" or $this->class eq "PPI::Token::End"
$this->class eq "PPI::Token::Data" $this->class eq "PPI::Token::End"
Truth table100%3/3
A or B
A= $this->class eq "PPI::Token::Data"B= $this->class eq "PPI::Token::End"
ABresult
1X1
011
000
1509 13 });
1510 13 ▶ next if( !$tokens || ( defined( $tokens ) && ref( $tokens ) && !scalar( @$tokens ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if not $tokens or defined $tokens and ref $tokens and not scalar @$tokens 1 12 13
Condition44%4/9
not $tokens or defined $tokens and ref $tokens and not scalar @$tokens
l!l&&r!l&&!r
1012
defined $tokens and ref $tokens and not scalar @$tokens
!ll&&!rl&&r
0120
defined $tokens and ref $tokens
!ll&&!rl&&r
0012
MC/DC25%1/4
not $tokens or defined $tokens and ref $tokens and not scalar @$tokens
not $tokens defined $tokens ref $tokens not scalar @$tokens
Truth table40%2/5
not(A) or B and C and not(D)
A= not $tokensB= defined $tokensC= ref $tokensD= not scalar @$tokens
ABCDresult
1XXX1
01111
00XX0
010X0
01100
1511 12 my $token = $tokens->[0];
1512 12 my $token_name_ref = $this->find( 'PPI::Token::Separator' );
1513 12 my $token_name;
1514 12 ▶ if( $token_name_ref && ref( $token_name_ref ) eq 'ARRAY' && scalar( @$token_name_ref ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($token_name_ref and ref $token_name_ref eq 'ARRAY' and scalar @$token_name_ref) { } 12 0 12
Condition40%2/5
$token_name_ref and ref $token_name_ref eq "ARRAY" and scalar @$token_name_ref
!ll
012
$token_name_ref and ref $token_name_ref eq "ARRAY"
!ll&&!rl&&r
0012
MC/DC0%0/2
$token_name_ref and ref $token_name_ref eq "ARRAY" and scalar @$token_name_ref
$token_name_ref ref $token_name_ref eq "ARRAY"
Truth table33%1/3
A and B
A= $token_name_refB= ref $token_name_ref eq "ARRAY"
ABresult
0X0
100
111
1515 {
1516 12 $token_name = $token_name_ref->[0]->content;
1517 }
1518 else
1519 {
1520 0 ▶ warn( "Could not find the __END__ or __DATA__ separator." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1521 0 last;
1522 }
1523
1524 # my $io = $token->handle;
1525 12 my $raw_data_str = $token->content;
1526 12 $self->_message( 5, "Found DATA to be:\n${raw_data_str}" );
1527  
1528 # Create a new string that holds only non-POD data
1529 12 my $filtered_data_str = '';
1530  
1531 12 ▶ if( $raw_data_str =~ /\S+/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($raw_data_str =~ /\S+/) 4 8 12
1532 {
1533 # Parse the data as a PPI document to filter POD content
1534 4 $self->_message( 5, "Parsing the DATA, and check for POD to skip." );
1535 # Force it to be __END__ so PPI can handle properly the POD data
1536 # FYI, PPI only handles POD data when the token is __END__, and not when it is __DATA__
1537 4 ▶ if( $token_name eq '__DATA__' )
Branch: 1 branch
BranchTrueFalseTotal
if ($token_name eq '__DATA__') { } 2 2 4
1538 {
1539 2 my $data_str = "__END__\n" . $raw_data_str;
1540 2 require PPI::Tokenizer;
1541 2 my $tokenizer = PPI::Tokenizer->new( \$data_str );
1542 2 my $tokens = $tokenizer->all_tokens;
1543 2 foreach my $token ( @$tokens )
1544 {
1545 7 ▶ $filtered_data_str .= "${token}" if( $token->class eq 'PPI::Token::End' );
Branch: 1 branch
BranchTrueFalseTotal
if $token->class eq "PPI::Token::End" 2 5 7
1546 }
1547 }
1548 else
1549 {
1550 2 $filtered_data_str = $raw_data_str;
1551 }
1552 }
1553
1554 # Now $filtered_data_str holds only the non-POD data content
1555 12 $self->_message( 5, "Creating BEGIN block to set DATA with value:\n${filtered_data_str}" );
1556
1557 # Define the BEGIN block code with the filtered data
1558 12 my $begin_block_code = <<"END_CODE";
1559 {
1560 no warnings;
1561 CHECK
1562 {
1563 my \$nice_try_data_block_str = <<'END_OF_DATA';
1564 ${filtered_data_str}
1565 END_OF_DATA
1566  
1567 require Symbol;
1568 my \$fh = Symbol::geniosym();
1569 open( \$fh, '<:scalar', \\\$nice_try_data_block_str ) || die( \$! );
1570 no strict 'refs';
1571 no warnings 'redefine';
1572 *{ __PACKAGE__ . '::DATA' } = \$fh;
1573 };
1574 }
1575  
1576 END_CODE
1577 12 ▶ if( $this->class eq 'PPI::Statement::End' )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->class eq "PPI::Statement::End") 10 2 12
1578 {
1579 10 $begin_block_code .= "1;\n";
1580 }
1581 12 $self->_message( 5, "BEGIN block is:\n${begin_block_code}" );
1582 12 ▶ my $begin_block = PPI::Token->new( $begin_block_code ) || die( "Unable to create token" );
Condition50%1/2
'PPI::Token'->new($begin_block_code) || die('Unable to create token')
l!l
120
MC/DC0%0/1
'PPI::Token'->new($begin_block_code) || die('Unable to create token')
'PPI::Token'->new($begin_block_code)
Truth table50%1/2
A
A= 'PPI::Token'->new($begin_block_code)
Aresult
11
00
1583 12 $self->_message( 5, "Inserting BEGIN element object '", overload::StrVal( $begin_block ), "', before '", overload::StrVal( $this ), "'" );
1584 12 my $rv = $this->__insert_before( $begin_block );
1585 12 ▶ if( !defined( $rv ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $rv) { } 0 12 12
elsif (not $rv) { } 0 12 12
1586 {
1587 0 ▶ warn( "BEGIN block object (", overload::StrVal( $begin_block ), ") to be inserted before the DATA token is not a valid object." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1588 0 last;
1589 }
1590 elsif( !$rv )
1591 {
1592 0 ▶ warn( "Somehow, the BEGIN block object (", overload::StrVal( $begin_block ), ") could not be inserted before the DATA token." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1593 0 last;
1594 }
1595 # $self->_message( 5, "BEGIN block object (", overload::StrVal( $begin_block ), ") was successfully inserted." );
1596 # We end here, because there can be only one __DATA__ or __END__ token
1597 12 last;
1598 }
1599 }
1600  
1601 # $self->_message( 5, "Code now is: $elem" );
1602 34 return( $elem );
1603 }
1604  
1605 # .Element: [11] class PPI::Token::Word, value caller
1606 # .Element: [11] class PPI::Structure::List, value (1)
1607 #
1608 # ..Element: [12] class PPI::Token::Word, value caller
1609 # ..Element: [12] class PPI::Token::Structure, value ;
1610  
1611 sub _process_caller
1612 1569 ▶{
Subroutine _process_caller: called CC=9 SCAR=22.0
1613 1569 my $self = shift( @_ );
1614 1569 my $where = shift( @_ );
1615 1569 ▶ my $elem = shift( @_ ) || return( '' );
Condition50%1/2
shift @_ || (return '')
l!l
15690
MC/DC0%0/1
shift @_ || (return '')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1616 31 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1617 1569 ▶ return( $elem ) if( !$elem->children );
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->children 11 1558 1569
1618 1558 foreach my $e ( $elem->elements )
1619 {
1620 7744 ▶ my $content = $e->content // '';
Condition50%1/2
$e->content // ""
l!l
77440
MC/DC0%0/1
$e->content // ""
$e->content
Truth table50%1/2
A
A= $e->content
Aresult
11
00
1621 7744 my $class = $e->class;
1622 7744 ▶ if( $class eq 'PPI::Token::Word' && $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?caller$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "PPI::Token::Word" and $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?caller$/) 5 7739 7744
Condition100%3/3
$class eq "PPI::Token::Word" and $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?caller$/
!ll&&!rl&&r
72644755
MC/DC100%2/2
$class eq "PPI::Token::Word" and $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?caller$/
$class eq "PPI::Token::Word" $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?caller$/
Truth table100%3/3
A and B
A= $class eq "PPI::Token::Word"B= $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?caller$/
ABresult
0X0
100
111
1623 {
1624 5 $e->set_content( 'Nice::Try::caller_' . $where );
1625 }
1626
1627 7744 ▶ if( $e->can('elements') && $e->elements )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->can("elements") and $e->elements) 1286 6458 7744
Condition100%3/3
$e->can("elements") and $e->elements
!ll&&!rl&&r
645711286
MC/DC100%2/2
$e->can("elements") and $e->elements
$e->can("elements") $e->elements
Truth table100%3/3
A and B
A= $e->can("elements")B= $e->elements
ABresult
0X0
100
111
1628 {
1629 1286 $self->_process_caller( $where => $e );
1630 }
1631 }
1632 1558 return( $elem );
1633 }
1634  
1635 sub _process_loop_breaks
1636 456 ▶{
Subroutine _process_loop_breaks: called CC=63 SCAR=54.3
1637 456 my $self = shift( @_ );
1638 456 ▶ my $elem = shift( @_ ) || return( '' );
Condition50%1/2
shift @_ || (return '')
l!l
4560
MC/DC0%0/1
shift @_ || (return '')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1639 31 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1640 456 ▶ return( $elem ) if( !$elem->children );
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->children 6 450 456
1641 450 my $ct = "$elem";
1642 # There is nothing to do
1643 450 ▶ if( index( $ct, 'last' ) == -1 &&
Branch: 1 branch
BranchTrueFalseTotal
if (index($ct, "last") == -1 and index($ct, "next") == -1 and index($ct, "redo") == -1 and index($ct, "goto") == -1 and index($ct, "return") == -1) 321 129 450
Condition100%12/12
index($ct, "last") == -1 and index($ct, "next") == -1 and index($ct, "redo") == -1 and index($ct, "goto") == -1 and index($ct, "return") == -1
!ll&&!rl&&r
7752321
index($ct, "last") == -1 and index($ct, "next") == -1 and index($ct, "redo") == -1 and index($ct, "goto") == -1
!ll&&!rl&&r
761373
index($ct, "last") == -1 and index($ct, "next") == -1 and index($ct, "redo") == -1
!ll&&!rl&&r
5422374
index($ct, "last") == -1 and index($ct, "next") == -1
!ll&&!rl&&r
3024396
MC/DC100%5/5
index($ct, "last") == -1 and index($ct, "next") == -1 and index($ct, "redo") == -1 and index($ct, "goto") == -1 and index($ct, "return") == -1
index($ct, "last") == -1 index($ct, "next") == -1 index($ct, "redo") == -1 index($ct, "goto") == -1 index($ct, "return") == -1
Truth table100%6/6
A and B and C and D and E
A= index($ct, "last") == -1B= index($ct, "next") == -1C= index($ct, "redo") == -1D= index($ct, "goto") == -1E= index($ct, "return") == -1
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1644 index( $ct, 'next' ) == -1 &&
1645 index( $ct, 'redo' ) == -1 &&
1646 index( $ct, 'goto' ) == -1 &&
1647 index( $ct, 'return' ) == -1 )
1648 {
1649 321 ▶ $self->_message( 4, "There is nothing to be done. Key words last, next, redo or goto are not found." ) if( $self->{debug} >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 4 0 321 321
1650 321 return( '' );
1651 }
1652 129 ▶ $self->_message( 5, "Checking loop breaks in ", scalar( $elem->elements ), " elements for '$elem'" ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 129 129
1653 129 foreach my $e ( $elem->elements )
1654 {
1655 1270 ▶ my $content = $e->content // '';
Condition50%1/2
$e->content // ""
l!l
12700
MC/DC0%0/1
$e->content // ""
$e->content
Truth table50%1/2
A
A= $e->content
Aresult
11
00
1656 1270 ▶ $self->_messagef( 6, "Checking element: [%d] class %s with %d children and value '%s'\n", $e->line_number, $e->class, ( $e->can('elements') ? scalar( $e->elements ) : 0 ), $content ) if( $self->{debug} >= 6 );
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"debug"} >= 6 0 1270 1270
$e->can('elements') ? : 0 0 0
1657 1270 my $class = $e->class;
1658 # We found a for, foreach or while loops and we skip, because if there are any break words (next, last, redo) inside, it is not our problem.
1659 1270 ▶ if( $class eq 'PPI::Structure::For' ||
Branch: 4 branches
BranchTrueFalseTotal
if ($class eq 'PPI::Structure::For' or $class eq 'PPI::Statement::Compound' and defined $e->first_element->content and $e->first_element->content =~ /^(for|foreach|while)$/) { } 0 1270 1270
elsif ($class eq 'PPI::Token::Word' and $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?(next|last|redo)$/) { } 0 1270 1270
elsif ($class eq 'PPI::Statement::Break') { } 86 1184 1270
elsif ($class eq 'PPI::Token::Word' and ($e->content // '') eq 'return' and $e->sprevious_sibling and $e->sprevious_sibling->class eq 'PPI::Token::Operator') { } 3 2362 2365
Condition55%5/9
$class eq "PPI::Structure::For" or $class eq "PPI::Statement::Compound" and defined $e->first_element->content and $e->first_element->content =~ /^(for|foreach|while)$/
l!l&&r!l&&!r
001270
$class eq "PPI::Statement::Compound" and defined $e->first_element->content and $e->first_element->content =~ /^(for|foreach|while)$/
!ll&&!rl&&r
1253170
$class eq "PPI::Statement::Compound" and defined $e->first_element->content
!ll&&!rl&&r
1253017
MC/DC0%0/4
$class eq "PPI::Structure::For" or $class eq "PPI::Statement::Compound" and defined $e->first_element->content and $e->first_element->content =~ /^(for|foreach|while)$/
$class eq "PPI::Structure::For" $class eq "PPI::Statement::Compound" defined $e->first_element->content $e->first_element->content =~ /^(for|foreach|while)$/
Truth table40%2/5
A or B and C and D
A= $class eq "PPI::Structure::For"B= $class eq "PPI::Statement::Compound"C= defined $e->first_element->contentD= $e->first_element->content =~ /^(for|foreach|while)$/
ABCDresult
1XXX1
01111
00XX0
010X0
01100
1660 ( $class eq 'PPI::Statement::Compound' &&
1661 CORE::defined( $e->first_element->content ) &&
1662 $e->first_element->content =~ /^(for|foreach|while)$/ ) )
1663 {
1664 0 next;
1665 }
1666 ▶ elsif( $class eq 'PPI::Token::Word' && $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?(next|last|redo)$/ )
Condition66%2/3
$class eq "PPI::Token::Word" and $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?(next|last|redo)$/
!ll&&!rl&&r
1230400
MC/DC0%0/2
$class eq "PPI::Token::Word" and $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?(next|last|redo)$/
$class eq "PPI::Token::Word" $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?(next|last|redo)$/
Truth table66%2/3
A and B
A= $class eq "PPI::Token::Word"B= $content =~ /^(?:CORE\::)?(?:GLOBAL\::)?(next|last|redo)$/
ABresult
0X0
100
111
1667 {
1668 0 ▶ $self->_message( 5, "Found loop keyword '$content'." ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 0 0
1669 # $e->set_content( qq{CORE::return( '__} . uc( $1 ) . qq{__' )} );
1670 # $e->set_content( q{$Nice::Try::BREAK='__} . uc( $1 ) . qq{__' ); return;} );
1671 0 my $break_code = q{$Nice::Try::BREAK='} . $1 . qq{', return;};
1672 0 my $break_doc = PPI::Document->new( \$break_code, readonly => 1 );
1673 0 my $new_elem = $break_doc->first_element;
1674 0 $new_elem->remove;
1675 0 ▶ $self->_message( 5, "New element is object '", sub{ overload::StrVal( $new_elem ) }, "' -> $new_elem" ) if( $self->{debug} >= 5 );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 0 0
1676 # Not yet implemented as of 2021-05-11 dixit PPI, so we use a hack to make it available anyhow
1677 0 $e->replace( $new_elem );
1678 0 ▶ $self->_message( 5, "Loop keyword now replaced with '$e'." ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 0 0
1679 }
1680 elsif( $class eq 'PPI::Statement::Break' )
1681 {
1682 86 my $words = $e->find( 'PPI::Token::Word' );
1683 86 ▶ $self->_messagef( 5, "Found %d word elements inside break element.", scalar( @$words ) ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 86 86
1684 86 ▶ my $word1 = ( scalar( @$words ) ? $words->[0]->content // '' : '' );
Branch: 1 branch
BranchTrueFalseTotal
scalar @$words ? : 86 0 86
Condition50%1/2
$words->[0]->content // ""
l!l
860
MC/DC0%0/1
$words->[0]->content // ""
$words->[0]->content
Truth table50%1/2
A
A= $words->[0]->content
Aresult
11
00
1685 86 ▶ my $word2 = ( scalar( @$words ) > 1 ? $words->[1]->content // '' : '' );
Branch: 1 branch
BranchTrueFalseTotal
scalar @$words > 1 ? : 22 64 86
Condition50%1/2
$words->[1]->content // ""
l!l
220
MC/DC0%0/1
$words->[1]->content // ""
$words->[1]->content
Truth table50%1/2
A
A= $words->[1]->content
Aresult
11
00
1686 86 ▶ $self->_message( 5, "Word 1 -> ", $word1 ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 86 86
1687 86 ▶ $self->_message( 5, "Word 2 -> ", $word2 ) if( $self->{debug} >= 5 && scalar( @$words ) > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 and scalar @$words > 1 0 86 86
Condition33%1/3
$self->{"debug"} >= 5 and scalar @$words > 1
!ll&&!rl&&r
8600
MC/DC0%0/2
$self->{"debug"} >= 5 and scalar @$words > 1
$self->{"debug"} >= 5 scalar @$words > 1
Truth table33%1/3
A and B
A= $self->{"debug"} >= 5B= scalar @$words > 1
ABresult
0X0
100
111
1688 # If we found a break word without a label, i.e. next, last, redo,
1689 # we replace it with a special return statement
1690 86 ▶ if( (
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$words == 1 || scalar @$words > 1 && $word2 =~ /^(for|foreach|given|if|unless|until|while)$/ || $word1 eq "return" and $word1 eq "next" || $word1 eq "last" || $word1 eq "redo" || $word1 eq "return") 74 12 86
Condition85%18/21
scalar @$words == 1 || scalar @$words > 1 && $word2 =~ /^(for|foreach|given|if|unless|until|while)$/ || $word1 eq "return" and $word1 eq "next" || $word1 eq "last" || $word1 eq "redo" || $word1 eq "return"
!ll&&!rl&&r
12074
scalar @$words == 1 or scalar @$words > 1 and $word2 =~ /^(for|foreach|given|if|unless|until|while)$/ or $word1 eq "return"
l!l&&r!l&&!r
67712
scalar @$words == 1 or scalar @$words > 1 and $word2 =~ /^(for|foreach|given|if|unless|until|while)$/
l!l&&r!l&&!r
64319
scalar @$words > 1 and $word2 =~ /^(for|foreach|given|if|unless|until|while)$/
!ll&&!rl&&r
0193
$word1 eq "next" or $word1 eq "last" or $word1 eq "redo" or $word1 eq "return"
l!l&&r!l&&!r
33410
$word1 eq "next" or $word1 eq "last" or $word1 eq "redo"
l!l&&r!l&&!r
231041
$word1 eq "next" or $word1 eq "last"
l!l&&r!l&&!r
121151
MC/DC37%3/8
scalar @$words == 1 || scalar @$words > 1 && $word2 =~ /^(for|foreach|given|if|unless|until|while)$/ || $word1 eq "return" and $word1 eq "next" || $word1 eq "last" || $word1 eq "redo" || $word1 eq "return"
scalar @$words == 1 scalar @$words > 1 $word2 =~ /^(for|foreach|given|if|unless|until|while)$/ $word1 eq "return" $word1 eq "next" $word1 eq "last" $word1 eq "redo" $word1 eq "return"
Truth table40%9/22
A or B and C or D and E or F or G or H
A= scalar @$words == 1B= scalar @$words > 1C= $word2 =~ /^(for|foreach|given|if|unless|until|while)$/D= $word1 eq "return"E= $word1 eq "next"F= $word1 eq "last"G= $word1 eq "redo"H= $word1 eq "return"
ABCDEFGHresult
00X0XXXX0
0100XXXX0
1XXX00000
011X00000
00X100000
010100000
1XXX1XXX1
1XXX01XX1
1XXX001X1
1XXX00011
011X1XXX1
011X01XX1
011X001X1
011X00011
00X11XXX1
00X101XX1
00X1001X1
00X100011
01011XXX1
010101XX1
0101001X1
010100011
1691 scalar( @$words ) == 1 ||
1692 ( scalar( @$words ) > 1 && $word2 =~ /^(for|foreach|given|if|unless|until|while)$/ ) ||
1693 $word1 eq 'return'
1694 ) &&
1695 (
1696 $word1 eq 'next' ||
1697 $word1 eq 'last' ||
1698 $word1 eq 'redo' ||
1699 $word1 eq 'return'
1700 ) )
1701 {
1702 # We add our special return value. Notice that we use 'return' and not
1703 # 'CORE::return'. See below why.
1704 # my $break_code = qq{return( '__} . uc( $word1 ) . qq{__' )};
1705 74 ▶ my $break_code = q{$Nice::Try::BREAK='} . $word1 . ( $word1 eq 'return' ? "', $e" : qq{', return} );
Branch: 1 branch
BranchTrueFalseTotal
$word1 eq 'return' ? : 41 33 74
1706 # e.g. next if( $i == 2 );
1707 # next and if are both treated as 'word' by PPI
1708 74 ▶ if( scalar( @$words ) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$words > 1) { } 10 64 74
1709 {
1710 10 ( my $ct = $e->content ) =~ s/^(next|last|redo)//;
1711 10 $break_code .= $ct;
1712 }
1713 else
1714 {
1715 64 $break_code .= ';'
1716 }
1717 74 ▶ $self->_message( 5, "Replacing this node with: $break_code" ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 74 74
1718
1719 74 my $break_doc = PPI::Document->new( \$break_code, readonly => 1 );
1720 74 my $new_elem = $break_doc->first_element;
1721 74 $new_elem->remove;
1722 0 ▶ $self->_message( 5, "New element is object '", sub{ overload::StrVal( $new_elem ) }, "' -> $new_elem" ) if( $self->{debug} >= 5 );
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 74 74
1723 # Not yet implemented as of 2021-05-11 dixit PPI, so we use a hack to make it available anyhow
1724 74 ▶ $self->_message( 5, "Updated element now is '$e' for class '", $e->class, "' and parent class '", $e->parent->class, "'." ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 74 74
1725 74 $e->replace( $new_elem );
1726 # 2021-05-12 (Jacques): I have to do this workaround, because weirdly enough
1727 # PPI (at least with PPI::Node version 1.270) will refuse to add our element
1728 # if the 'return' word is 'CORE::return' so, we add it without and change it after
1729 # $new_elem->first_element->set_content( 'CORE::return' );
1730 }
1731 86 next;
1732 }
1733 ▶ elsif( $class eq 'PPI::Token::Word' &&
Condition72%8/11
$class eq "PPI::Token::Word" and ($e->content // "") eq "return" and $e->sprevious_sibling and $e->sprevious_sibling->class eq "PPI::Token::Operator"
!ll&&!rl&&r
118103
$class eq "PPI::Token::Word" and ($e->content // "") eq "return" and $e->sprevious_sibling
!ll&&!rl&&r
118103
$class eq "PPI::Token::Word" and ($e->content // "") eq "return"
!ll&&!rl&&r
1144373
$e->content // ""
l!l
400
MC/DC25%1/4
$class eq "PPI::Token::Word" and ($e->content // "") eq "return" and $e->sprevious_sibling and $e->sprevious_sibling->class eq "PPI::Token::Operator"
$class eq "PPI::Token::Word" $e->content $e->sprevious_sibling $e->sprevious_sibling->class eq "PPI::Token::Operator"
Truth table40%2/5
A and B and C and D
A= $class eq "PPI::Token::Word"B= $e->contentC= $e->sprevious_siblingD= $e->sprevious_sibling->class eq "PPI::Token::Operator"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1734 ( $e->content // '' ) eq 'return' &&
1735 $e->sprevious_sibling &&
1736 # Should be enough
1737 $e->sprevious_sibling->class eq 'PPI::Token::Operator' )
1738 # $e->sprevious_sibling->class eq 'PPI::Token::Operator' &&
1739 # ( $e->sprevious_sibling->content // '' ) =~ /^$/ )
1740 {
1741 3 my $break_code;
1742 my @to_remove;
1743 # return( # something );
1744 3 ▶ if( $e->snext_sibling &&
Branch: 3 branches
BranchTrueFalseTotal
if ($e->snext_sibling and $e->snext_sibling->class eq 'PPI::Structure::List') { } 2 1 3
elsif ($e->snext_sibling and $e->snext_sibling->isa('PPI::Token::Quote')) { } 1 0 1
elsif ($e->snext_sibling and $e->snext_sibling->class eq 'PPI::Token::Structure' and $e->snext_sibling->content eq ';') { } 0 0 0
Condition66%2/3
$e->snext_sibling and $e->snext_sibling->class eq "PPI::Structure::List"
!ll&&!rl&&r
012
MC/DC50%1/2
$e->snext_sibling and $e->snext_sibling->class eq "PPI::Structure::List"
$e->snext_sibling $e->snext_sibling->class eq "PPI::Structure::List"
Truth table66%2/3
A and B
A= $e->snext_siblingB= $e->snext_sibling->class eq "PPI::Structure::List"
ABresult
0X0
100
111
1745 $e->snext_sibling->class eq 'PPI::Structure::List' )
1746 {
1747 2 my $list = $e->snext_sibling;
1748 2 push( @to_remove, $list );
1749 2 $break_code = "return( \$Nice::Try::RETURN->${list} )";
1750 }
1751 # return( "" ) or return( '' )
1752 ▶ elsif( $e->snext_sibling &&
Condition33%1/3
$e->snext_sibling and $e->snext_sibling->isa("PPI::Token::Quote")
!ll&&!rl&&r
001
MC/DC0%0/2
$e->snext_sibling and $e->snext_sibling->isa("PPI::Token::Quote")
$e->snext_sibling $e->snext_sibling->isa("PPI::Token::Quote")
Truth table33%1/3
A and B
A= $e->snext_siblingB= $e->snext_sibling->isa("PPI::Token::Quote")
ABresult
0X0
100
111
1753 $e->snext_sibling->isa( 'PPI::Token::Quote' ) )
1754 {
1755 1 my $list = $e->snext_sibling;
1756 1 push( @to_remove, $list );
1757 1 $break_code = "return( \$Nice::Try::RETURN->(${list}) );";
1758 }
1759 # return;
1760 ▶ elsif( $e->snext_sibling &&
Condition0%0/6
$e->snext_sibling and $e->snext_sibling->class eq "PPI::Token::Structure" and $e->snext_sibling->content eq ";"
!ll&&!rl&&r
000
$e->snext_sibling and $e->snext_sibling->class eq "PPI::Token::Structure"
!ll&&!rl&&r
000
MC/DC0%0/3
$e->snext_sibling and $e->snext_sibling->class eq "PPI::Token::Structure" and $e->snext_sibling->content eq ";"
$e->snext_sibling $e->snext_sibling->class eq "PPI::Token::Structure" $e->snext_sibling->content eq ";"
Truth table0%0/4
A and B and C
A= $e->snext_siblingB= $e->snext_sibling->class eq "PPI::Token::Structure"C= $e->snext_sibling->content eq ";"
ABCresult
0XX0
10X0
1100
1111
1761 $e->snext_sibling->class eq 'PPI::Token::Structure' &&
1762 $e->snext_sibling->content eq ';' )
1763 {
1764 0 $break_code = "return( \$Nice::Try::RETURN->() );";
1765 }
1766 else
1767 {
1768 0 my $list = '';
1769 0 my $next_elem;
1770 0 my $prev_elem = $e;
1771 0 ▶ while( $next_elem = $prev_elem->snext_sibling )
Branch: 1 branch
BranchTrueFalseTotal
if ($next_elem = $prev_elem->snext_sibling) 0 0 0
1772 {
1773 0 ▶ last if( $next_elem->content eq ';' );
Branch: 1 branch
BranchTrueFalseTotal
if $next_elem->content eq ";" 0 0 0
1774 0 $list .= $next_elem->content;
1775 0 push( @to_remove, $next_elem );
1776 0 $prev_elem = $next_elem;
1777 }
1778 0 $break_code = "return( \$Nice::Try::RETURN->(${list}) );";
1779 }
1780 3 my $break_doc = PPI::Document->new( \$break_code, readonly => 1 );
1781 3 my $new_elem = $break_doc->first_element;
1782 3 $new_elem->remove;
1783 0 ▶ $self->_message( 5, "New element is object '", sub{ overload::StrVal( $new_elem ) }, "' -> $new_elem" ) if( $self->{debug} >= 5 );
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 3 3
1784 # Not yet implemented as of 2021-05-11 dixit PPI, so we use a hack to make it available anyhow
1785 3 $e->replace( $new_elem );
1786 3 $_->remove for( @to_remove );
1787 }
1788
1789 1184 ▶ if( $e->can('elements') && $e->elements )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->can("elements") and $e->elements) 186 998 1184
Condition100%3/3
$e->can("elements") and $e->elements
!ll&&!rl&&r
9971186
MC/DC100%2/2
$e->can("elements") and $e->elements
$e->can("elements") $e->elements
Truth table100%3/3
A and B
A= $e->can("elements")B= $e->elements
ABresult
0X0
100
111
1790 {
1791 186 $self->_process_loop_breaks( $e );
1792 }
1793 }
1794 129 return( $elem );
1795 }
1796  
1797 sub _process_sub_token
1798 426 ▶{
Subroutine _process_sub_token: called CC=24 SCAR=36.6
1799 426 my $self = shift( @_ );
1800 426 ▶ my $elem = shift( @_ ) || return( '' );
Condition50%1/2
shift @_ || (return '')
l!l
4260
MC/DC0%0/1
shift @_ || (return '')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1801 # token __SUB__ is only available since perl v5.16
1802 426 ▶ return( '' ) unless( $] >= 5.016000 );
Branch: 1 branch
BranchTrueFalseTotal
unless $] >= "5.016" 0 426 426
1803 426 ▶ if( index( "$elem", '__SUB__' ) == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index("$elem", "__SUB__") == -1) 424 2 426
1804 {
1805 424 ▶ $self->_message( 5, "No __SUB__ token found in ", scalar( $elem->elements ), " elements for '$elem'" ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 424 424
1806 424 return( '' );
1807 }
1808 31 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1809 2 ▶ return( $elem ) if( !$elem->children );
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->children 0 2 2
1810 2 ▶ $self->_message( 5, "Checking __SUB__ token in ", scalar( $elem->elements ), " elements for '$elem'" ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 2 2
1811 # Look for parent, and if we can find a sub, or an anonymous sub
1812 # my $sub = sub{} -> PPI::Token::Word 'sub', PPI::Structure::Block '{'
1813 # sub mysub {} -> PPI::Statement::Sub -> PPI::Token::Word 'sub', PPI::Token::Word 'mysub', PPI::Structure::Block '{'
1814 2 my $find_closest_sub;
1815 $find_closest_sub = sub
1816 2 ▶ {
Subroutine __ANON__: called CC=11 SCAR=25.7
1817 2 my $e = shift( @_ );
1818 2 ▶ return if( !defined( $e ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e 0 2 2
1819 2 my $parent = $e->parent;
1820 2 ▶ return if( !$parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 2 2
1821 # Keep going up until we find a block
1822 2 ▶ while( $parent )
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) 4 0 4
1823 {
1824 4 ▶ $self->_message( 5, "Checking parent element of class ", $parent->class, " and value $parent" ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 4 4
1825 4 ▶ if( $parent->class eq 'PPI::Structure::Block' )
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->class eq "PPI::Structure::Block") 2 2 4
1826 {
1827 2 my $sub_name;
1828 2 my $prev = $parent->sprevious_sibling;
1829 2 ▶ while( $prev )
Branch: 1 branch
BranchTrueFalseTotal
if ($prev) 6 0 6
1830 {
1831 6 ▶ if( $prev->content eq 'sub' )
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->content eq "sub") 2 4 6
1832 {
1833 2 return({ element => $parent, name => $sub_name });
1834 }
1835
1836 4 ▶ if( $prev->class eq 'PPI::Token::Word' )
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->class eq "PPI::Token::Word") 1 3 4
1837 {
1838 1 ▶ if( CORE::defined( $sub_name ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sub_name) 0 1 1
1839 {
1840 0 ▶ warn( "Found some redefinition of a subroutine's name at line ", $prev->line_number, " for subroutine '${sub_name}'\n" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1841 }
1842 1 $sub_name = $prev->content;
1843 }
1844 4 $prev = $prev->sprevious_sibling;
1845 }
1846 }
1847 2 $parent = $parent->parent;
1848 }
1849 0 return;
1850 2 };
1851 2 my $def = $find_closest_sub->( $elem );
1852 2 ▶ if( $def )
Branch: 1 branch
BranchTrueFalseTotal
if ($def) { } 2 0 2
1853 {
1854 2 my $block = $def->{element};
1855 2 ▶ $self->_message( 5, "Found a sub block at line ", $block->line_number, " of class ", $block->class, " with name '", ( $def->{name} // 'anonymous' ), "'" ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 2 2
Condition0%0/2
$def->{"name"} // "anonymous"
l!l
00
MC/DC0%0/1
$def->{"name"} // "anonymous"
$def->{"name"}
Truth table0%0/2
A
A= $def->{"name"}
Aresult
11
00
1856 2 my $sub_token_code = <<'PERL';
1857 CORE::local $Nice::Try::SUB_TOKEN;
1858 {
1859 use feature 'current_sub';
1860 no warnings 'experimental';
1861 $Nice::Try::SUB_TOKEN = __SUB__;
1862 }
1863 PERL
1864 2 $sub_token_code =~ s/\n//gs;
1865 # $sub_token_code .= $block;
1866 2 my $sub_token_doc = PPI::Document->new( \$sub_token_code, readonly => 1 );
1867 2 my @new_elems = $sub_token_doc->elements;
1868 # my $new_elem = $sub_token_doc;
1869 # $new_elem->remove;
1870 2 $_->remove for( @new_elems );
1871 0 ▶ $self->_message( 5, "New elements is object '", sub{ join( ', ', map( overload::StrVal( $_ ), @new_elems ) ) }, "' -> $_" ) if( $self->{debug} >= 5 );
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 2 2
1872 # $block->replace( $new_elem );
1873 # Not yet implemented as of 2021-05-11 dixit PPI, so we use a hack to make it available anyhow
1874 2 my $rv;
1875 2 my @children = $block->children;
1876 2 ▶ if( scalar( @children ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @children) { } 2 0 2
1877 {
1878 2 my $last = $children[0];
1879 2 for( reverse( @new_elems ) )
1880 {
1881 4 $rv = $last->__insert_before( $_ );
1882 4 ▶ $self->_message( 5, "Element successfully inserted? ", ( defined( $rv ) ? ( $rv ? 'yes' : 'no' ) : 'no. element provided was not an PPI::Element.' ) ) if( $self->{debug} >= 5 );
Branch: 3 branches
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 4 4
defined $rv ? : 0 0 0
$rv ? : 0 0 0
1883 4 $last = $_;
1884 }
1885 }
1886 else
1887 {
1888 0 for( @new_elems )
1889 {
1890 0 $rv = $block->add_element( $_ );
1891 0 ▶ $self->_message( 5, "Element successfully inserted? ", ( defined( $rv ) ? ( ref( $rv ) eq 'PPI::Element' ? 'ok' : 'returned value is not an PPI::Element (' . ref( $rv ) . ')' ) : 'no' ) ) if( $self->{debug} >= 5 );
Branch: 3 branches
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 0 0
defined $rv ? : 0 0 0
ref $rv eq 'PPI::Element' ? : 0 0 0
1892 }
1893 }
1894 2 ▶ $self->_message( 5, "Updated block now is '$block' for class '", $block->class, "'." ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 2 2
1895 }
1896 else
1897 {
1898 0 ▶ $self->_message( 5, "No subroutine found! This is a try-catch block outside of a subroutine." ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 0 0
1899 }
1900
1901 2 my $crawl;
1902 $crawl = sub
1903 10 ▶ {
Subroutine __ANON__: called CC=8 SCAR=20.8
1904 10 my $this = shift( @_ );
1905 10 foreach my $e ( $this->elements )
1906 {
1907 67 ▶ $self->_message( 5, "Checking element ", overload::StrVal( $e ), " of class ", $e->class, " for token __SUB__" ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 67 67
1908 67 ▶ if( $e->content eq '__SUB__' )
Branch: 2 branches
BranchTrueFalseTotal
if ($e->content eq '__SUB__') { } 4 63 67
elsif ($e->can('elements') and scalar $e->elements and index("$e", '__SUB__') != -1) { } 8 103 111
1909 {
1910 4 ▶ $self->_message( 5, "Found token __SUB__" ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 4 4
1911 4 my $new_ct = '$Nice::Try::SUB_TOKEN';
1912 4 my $new_ct_doc = PPI::Document->new( \$new_ct, readonly => 1 );
1913 4 my $new_token = $new_ct_doc->first_element;
1914 4 $new_token->remove;
1915 4 $e->replace( $new_token );
1916 }
1917 ▶ elsif( $e->can( 'elements' ) &&
Condition100%5/5
$e->can("elements") and scalar $e->elements and index("$e", "__SUB__") != -1
!ll&&!rl&&r
4878
$e->can("elements") and scalar $e->elements
!ll
4815
MC/DC100%2/2
$e->can("elements") and scalar $e->elements and index("$e", "__SUB__") != -1
$e->can("elements") index("$e", "__SUB__") != -1
Truth table100%3/3
A and B
A= $e->can("elements")B= index("$e", "__SUB__") != -1
ABresult
0X0
100
111
1918 scalar( $e->elements ) &&
1919 index( "$e", '__SUB__' ) != -1 )
1920 {
1921 8 $crawl->( $e );
1922 }
1923 }
1924 2 };
1925 2 $crawl->( $elem );
1926 2 ▶ $self->_message( 5, "After processing __SUB__ tokens, try-catch block is now:\n$elem" ) if( $self->{debug} >= 5 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} >= 5 0 2 2
1927 2 return( $elem );
1928 }
1929  
1930 # Taken from PPI::Document
1931 sub _serialize
1932 392 ▶{
Subroutine _serialize: called CC=19 SCAR=51.9
1933 392 my $self = shift( @_ );
1934 392 ▶ my $ppi = shift( @_ ) || return( '' );
Condition50%1/2
shift @_ || (return '')
l!l
3920
MC/DC0%0/1
shift @_ || (return '')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1935 31 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1936 392 my @tokens = $ppi->tokens;
1937  
1938 # The here-doc content buffer
1939 392 my $heredoc = '';
1940  
1941 # Start the main loop
1942 392 my $output = '';
1943 392 foreach my $i ( 0 .. $#tokens ) {
1944 7386 my $Token = $tokens[$i];
1945  
1946 # Handle normal tokens
1947 7386 ▶ unless ( $Token->isa('PPI::Token::HereDoc') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Token->isa("PPI::Token::HereDoc")) 7386 0 7386
1948 7386 my $content = $Token->content;
1949  
1950 # Handle the trivial cases
1951 7386 ▶ unless ( $heredoc ne '' and $content =~ /\n/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($heredoc ne "" and $content =~ /\n/) 7386 0 7386
Condition33%1/3
$heredoc ne "" and $content =~ /\n/
!ll&&!rl&&r
738600
MC/DC0%0/2
$heredoc ne "" and $content =~ /\n/
$heredoc ne "" $content =~ /\n/
Truth table33%1/3
A and B
A= $heredoc ne ""B= $content =~ /\n/
ABresult
0X0
100
111
1952 7386 $output .= $content;
1953 7386 next;
1954 }
1955  
1956 # We have pending here-doc content that needs to be
1957 # inserted just after the first newline in the content.
1958 0 ▶ if ( $content eq "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content eq "\n") { } 0 0 0
1959 # Shortcut the most common case for speed
1960 0 $output .= $content . $heredoc;
1961 } else {
1962 # Slower and more general version
1963 0 $content =~ s/\n/\n$heredoc/;
1964 0 $output .= $content;
1965 }
1966  
1967 0 $heredoc = '';
1968 0 next;
1969 }
1970  
1971 # This token is a HereDoc.
1972 # First, add the token content as normal, which in this
1973 # case will definitely not contain a newline.
1974 0 $output .= $Token->content;
1975  
1976 # Now add all of the here-doc content to the heredoc buffer.
1977 0 foreach my $line ( $Token->heredoc ) {
1978 0 $heredoc .= $line;
1979 }
1980  
1981 0 ▶ if ( $Token->{_damaged} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->{"_damaged"}) 0 0 0
1982 # Special Case:
1983 # There are a couple of warning/bug situations
1984 # that can occur when a HereDoc content was read in
1985 # from the end of a file that we silently allow.
1986 #
1987 # When writing back out to the file we have to
1988 # auto-repair these problems if we aren't going back
1989 # on to the end of the file.
1990  
1991 # When calculating $last_line, ignore the final token if
1992 # and only if it has a single newline at the end.
1993 0 my $last_index = $#tokens;
1994 0 ▶ if ( $tokens[$last_index]->{content} =~ /^[^\n]*\n$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[$last_index]{"content"} =~ /^[^\n]*\n$/) 0 0 0
1995 0 $last_index--;
1996 }
1997  
1998 # This is a two part test.
1999 # First, are we on the last line of the
2000 # content part of the file
2001 0 ▶ my $last_line = List::Util::none {
Subroutine __ANON__: not called CC=2 SCAR=17.9
2002 0 ▶ $tokens[$_] and $tokens[$_]->{content} =~ /\n/
Branch: 1 branch
BranchTrueFalseTotal
$tokens[$_] and $tokens[$_]{"content"} =~ /\n/ 0 0 0
2003 0 } (($i + 1) .. $last_index);
2004 0 ▶ if ( ! defined $last_line ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $last_line) 0 0 0
2005 # Handles the null list case
2006 0 $last_line = 1;
2007 }
2008  
2009 # Secondly, are their any more here-docs after us,
2010 # (with content or a terminator)
2011 0 ▶ my $any_after = List::Util::any {
Subroutine __ANON__: not called CC=3 SCAR=24.8
2012 $tokens[$_]->isa('PPI::Token::HereDoc')
2013 and (
2014 0 scalar(@{$tokens[$_]->{_heredoc}})
2015 or
2016 defined $tokens[$_]->{_terminator_line}
2017 )
2018 0 ▶ } (($i + 1) .. $#tokens);
Branch: 1 branch
BranchTrueFalseTotal
$tokens[$_]->isa("PPI::Token::HereDoc") and scalar @{$tokens[$_]{"_heredoc"};} || defined $tokens[$_]{"_terminator_line"} 0 0 0
Condition0%0/6
$tokens[$_]->isa('PPI::Token::HereDoc') && (scalar @{$tokens[$_]{'_heredoc'};} || defined $tokens[$_]{'_terminator_line'})
!ll&&!rl&&r
000
scalar @{$tokens[$_]{"_heredoc"};} or defined $tokens[$_]{"_terminator_line"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$tokens[$_]->isa('PPI::Token::HereDoc') && (scalar @{$tokens[$_]{'_heredoc'};} || defined $tokens[$_]{'_terminator_line'})
$tokens[$_]->isa('PPI::Token::HereDoc') scalar @{$tokens[$_]{"_heredoc"};} defined $tokens[$_]{"_terminator_line"}
Truth table0%0/4
A && B or C
A= $tokens[$_]->isa('PPI::Token::HereDoc')B= scalar @{$tokens[$_]{"_heredoc"};}C= defined $tokens[$_]{"_terminator_line"}
ABCresult
0XX0
1000
11X1
1011
2019 0 ▶ if ( ! defined $any_after ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $any_after) 0 0 0
2020 # Handles the null list case
2021 0 $any_after = '';
2022 }
2023  
2024 # We don't need to repair the last here-doc on the
2025 # last line. But we do need to repair anything else.
2026 0 ▶ unless ( $last_line and ! $any_after ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($last_line and not $any_after) 0 0 0
Condition0%0/3
$last_line and not $any_after
!ll&&!rl&&r
000
MC/DC0%0/2
$last_line and not $any_after
$last_line not $any_after
Truth table0%0/3
A and not(B)
A= $last_lineB= not $any_after
ABresult
0X0
100
111
2027 # Add a terminating string if it didn't have one
2028 0 ▶ unless ( defined $Token->{_terminator_line} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Token->{"_terminator_line"}) 0 0 0
2029 0 $Token->{_terminator_line} = $Token->{_terminator};
2030 }
2031  
2032 # Add a trailing newline to the terminating
2033 # string if it didn't have one.
2034 0 ▶ unless ( $Token->{_terminator_line} =~ /\n$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Token->{"_terminator_line"} =~ /\n$/) 0 0 0
2035 0 $Token->{_terminator_line} .= "\n";
2036 }
2037 }
2038 }
2039  
2040 # Now add the termination line to the heredoc buffer
2041 0 ▶ if ( defined $Token->{_terminator_line} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Token->{"_terminator_line"}) 0 0 0
2042 0 $heredoc .= $Token->{_terminator_line};
2043 }
2044 }
2045  
2046 # End of tokens
2047  
2048 392 ▶ if ( $heredoc ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($heredoc ne "") 0 392 392
2049 # If the file doesn't end in a newline, we need to add one
2050 # so that the here-doc content starts on the next line.
2051 0 ▶ unless ( $output =~ /\n$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($output =~ /\n$/) 0 0 0
2052 0 $output .= "\n";
2053 }
2054  
2055 # Now we add the remaining here-doc content
2056 # to the end of the file.
2057 0 $output .= $heredoc;
2058 }
2059  
2060 392 $output;
2061 }
2062  
2063  
2064 {
2065 # NOTE: Nice::Try::ScopeGuard class
2066 package # hide from PAUSE
2067 Nice::Try::ScopeGuard;
2068  
2069 # older versions of perl have an issue with $@ during global destruction
2070 31 ▶ use constant UNSTABLE_DOLLARAT => ("$]" < '5.013002') ? 1 : 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
"$]" < 5.013002 ? : 0 31 31
2071  
2072 sub _new
2073 14 ▶ {
Subroutine _new: called CC=2 SCAR=8.1
2074 14 my $this = shift( @_ );
2075 14 ▶ return( bless( [ @_ ] => ( ref( $this ) || $this ) ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0140
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
2076 }
2077  
2078 sub DESTROY
2079 14 ▶ {
Subroutine DESTROY: called CC=5 SCAR=16.3
2080 14 my( $code, $args, $catch_err ) = @{ $_[0] };
2081 # save the current exception to make it available in the finally sub,
2082 # and to restore it after the eval
2083 14 ▶ my $err = defined( $catch_err ) ? $catch_err : $@;
Branch: 1 branch
BranchTrueFalseTotal
defined $catch_err ? : 0 14 14
2084 14 local $@ if( UNSTABLE_DOLLARAT );
2085 14 ▶ $@ = $catch_err if( defined( $catch_err ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $catch_err 0 14 14
2086 CORE::eval
2087 {
2088 14 $@ = $err;
2089 14 $code->( @$args );
2090 13 1;
2091 }
2092 or do
2093 14 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $@ = $err; &$code(@$args); 1 } } or do { warn "Execution of finally() block $code resulted in an exception, which " . '*CAN NOT BE PROPAGATED* due to fundamental limitations of Perl. ' . "Your program will continue as if this event never took place. " . "Original exception text follows:\n\n" . (defined $@ ? $@ : "\$\@ left undefined...") . "\n" } 13 1 14
2094 1 ▶ CORE::warn
Branch: 1 branch
BranchTrueFalseTotal
defined $@ ? : 1 0 1
2095 "Execution of finally() block $code resulted in an exception, which "
2096 . '*CAN NOT BE PROPAGATED* due to fundamental limitations of Perl. '
2097 . 'Your program will continue as if this event never took place. '
2098 . "Original exception text follows:\n\n"
2099 . (defined $@ ? $@ : '$@ left undefined...')
2100 . "\n"
2101 ;
2102 };
2103 # maybe unnecessary?
2104 14 $@ = $err;
2105 }
2106 }
2107  
2108 {
2109 # NOTE: Nice::Try::ObjectContext
2110 31 package
2111 Nice::Try::ObjectContext;
2112  
2113 sub new
2114 2 ▶ {
Subroutine new: called CC=2 SCAR=8.1
2115 2 my $that = shift( @_ );
2116 2 ▶ return( bless( { val => [@_] } => ( ref( $that ) || $that ) ) );
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
2117 }
2118  
2119 sub callback
2120 2 ▶ {
Subroutine callback: called CC=1 SCAR=0.0
2121 2 my $self = shift( @_ );
2122 2 return( $self->{val}->[0] );
2123 }
2124 }
2125  
2126 {
2127 # NOTE: PPI::Element
2128 31 package
2129 PPI::Element;
2130
2131 31 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
2132 81 ▶ sub replace {
Subroutine replace: called CC=2 SCAR=7.0
Pod documented
2133 81 ▶ my $self = ref $_[0] ? shift : return undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 81 0 81
2134 # If our object and the other are not of the same class, PPI refuses to replace
2135 # to avoid damages to perl code
2136 # my $other = _INSTANCE(shift, ref $self) or return undef;
2137 81 my $other = shift;
2138 # die "The ->replace method has not yet been implemented";
2139 81 $self->parent->__replace_child( $self, $other );
2140 81 1;
2141 }
2142 }
2143  
2144 31 1;
2145  
2146 # NOTE POD
2147 __END__
↑ Summary