blib/lib/Perl/Critic/Policy/TryTiny/RequireBlockTermination.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 90.0% 9 / 10 Conditioncond 76.1% 16 / 21 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 90.9% 10 / 11 Podpod 80.0% 4 / 5 totaltotal 84.7% 78 / 92 CC 13 SCAR 21.0
CC
13
Cov
89%
violates
13.5
default_themes
2.0
BEGIN
1.0
CRAP 8.1
↑ Summary
1 package Perl::Critic::Policy::TryTiny::RequireBlockTermination;
2 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '0.03';
6  
7 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Perl::Critic::Utils qw{ :severities :classification :ppi };
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 Readonly::Scalar my $DESC => q{A try/catch/finally not terminated};
13 1 Readonly::Scalar my $EXPL => q{Try::Tiny blocks must be terminated by either a semicolon or by residing at the end of a block};
14  
15 6 ▶sub supported_parameters { return() }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
16 3 ▶sub default_severity { return $SEVERITY_HIGH }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
17 0 ▶sub default_themes { return qw( bugs ) }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
18 6 ▶sub applies_to { return 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
19  
20 22 ▶sub violates {
Subroutine violates: called CC=13 SCAR=26.0
Pod documented
21 22 my ($self, $try) = @_;
22  
23 22 ▶ return unless $try->content() eq 'try';
Branch: 1 branch
BranchTrueFalseTotal
unless $try->content eq "try" 12 10 22
24  
25 10 my $try_block = $try->snext_sibling();
26 10 ▶ return unless $try_block and $try_block->isa('PPI::Structure::Block');
Branch: 1 branch
BranchTrueFalseTotal
unless $try_block and $try_block->isa("PPI::Structure::Block") 0 10 10
Condition33%1/3
$try_block and $try_block->isa("PPI::Structure::Block")
!ll&&!rl&&r
0010
MC/DC0%0/2
$try_block and $try_block->isa("PPI::Structure::Block")
$try_block $try_block->isa("PPI::Structure::Block")
Truth table33%1/3
A and B
A= $try_blockB= $try_block->isa("PPI::Structure::Block")
ABresult
0X0
100
111
27  
28 10 my $try_end = $try_block->snext_sibling();
29  
30 # Lets walk past any catch or finally blocks.
31 10 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($try_end and $try_end->isa("PPI::Token::Word") and $try_end->content eq "catch" || $try_end->content eq "finally" and $try_end->snext_sibling and $try_end->snext_sibling->isa("PPI::Structure::Block")) 8 10 18
Condition86%13/15
$try_end and $try_end->isa("PPI::Token::Word") and $try_end->content eq "catch" || $try_end->content eq "finally" and $try_end->snext_sibling and $try_end->snext_sibling->isa("PPI::Structure::Block")
!ll&&!rl&&r
1008
$try_end and $try_end->isa("PPI::Token::Word") and $try_end->content eq "catch" || $try_end->content eq "finally" and $try_end->snext_sibling
!ll&&!rl&&r
1008
$try_end and $try_end->isa("PPI::Token::Word") and $try_end->content eq "catch" || $try_end->content eq "finally"
!ll&&!rl&&r
738
$try_end and $try_end->isa("PPI::Token::Word")
!ll&&!rl&&r
4311
$try_end->content eq "catch" or $try_end->content eq "finally"
l!l&&r!l&&!r
623
MC/DC66%4/6
$try_end and $try_end->isa("PPI::Token::Word") and $try_end->content eq "catch" || $try_end->content eq "finally" and $try_end->snext_sibling and $try_end->snext_sibling->isa("PPI::Structure::Block")
$try_end $try_end->isa("PPI::Token::Word") $try_end->content eq "catch" $try_end->content eq "finally" $try_end->snext_sibling $try_end->snext_sibling->isa("PPI::Structure::Block")
Truth table55%5/9
A and B and C or D and E and F
A= $try_endB= $try_end->isa("PPI::Token::Word")C= $try_end->content eq "catch"D= $try_end->content eq "finally"E= $try_end->snext_siblingF= $try_end->snext_sibling->isa("PPI::Structure::Block")
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
111X0X0
11010X0
111X100
1101100
111X111
1101111
32 $try_end and
33 $try_end->isa('PPI::Token::Word') and
34 ($try_end->content() eq 'catch' or $try_end->content() eq 'finally') and
35 $try_end->snext_sibling() and
36 $try_end->snext_sibling()->isa('PPI::Structure::Block')
37 ) {
38 8 $try_end = $try_end->snext_sibling->snext_sibling();
39 }
40  
41 # The try/catch/finally is the last statement in the block.
42 10 ▶ return if !$try_end;
Branch: 1 branch
BranchTrueFalseTotal
unless $try_end 4 6 10
43  
44 # There was a semicolon at the end.
45 6 ▶ return if $try_end->isa('PPI::Token::Structure')
Branch: 1 branch
BranchTrueFalseTotal
if $try_end->isa("PPI::Token::Structure") and $try_end->content eq ";" 3 3 6
Condition66%2/3
$try_end->isa("PPI::Token::Structure") and $try_end->content eq ";"
!ll&&!rl&&r
303
MC/DC50%1/2
$try_end->isa("PPI::Token::Structure") and $try_end->content eq ";"
$try_end->isa("PPI::Token::Structure") $try_end->content eq ";"
Truth table66%2/3
A and B
A= $try_end->isa("PPI::Token::Structure")B= $try_end->content eq ";"
ABresult
0X0
100
111
46 and $try_end->content() eq ';';
47  
48 3 return $self->violation( $DESC, $EXPL, $try );
49 }
50  
51 1 1;
52 __END__
↑ Summary