Policy/Reneeb/ProhibitBlockEval.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 100% 46 / 46 CC 3 SCAR 4.1
CC
3
Cov
100%
violates
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Policy/RegularExpressions/RequireExtendedFormattingExceptForSplit.pm ↑ Summary RENEEB.pm »
1 package Perl::Critic::Policy::Reneeb::ProhibitBlockEval;
2  
3 # ABSTRACT: Do not use the Block-eval. Use Try::Tiny instead
4  
5 5 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 our $VERSION = '2.05';
15  
16 #-----------------------------------------------------------------------------
17  
18 5 Readonly::Scalar my $DESC => q{Prohibit Block-eval};
19 5 Readonly::Scalar my $EXPL => [ 237 ];
20  
21 #-----------------------------------------------------------------------------
22  
23 10 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
24 1 ▶sub default_themes { return qw<reneeb> }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
25 3 ▶sub applies_to {
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
26 3 return qw<
27 PPI::Statement
28 >;
29 }
30  
31 #-----------------------------------------------------------------------------
32  
33 14 ▶sub violates {
Subroutine violates: called CC=3 SCAR=11.0
Pod documented
34 14 my ( $self, $elem, $doc ) = @_;
35  
36 # other statements than eval aren't catched
37 14 ▶ return if $elem->schild ne 'eval';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->schild ne "eval" 11 3 14
38  
39 # string eval isn't catched by this policy
40 3 ▶ return if !$elem->schild->snext_sibling->isa('PPI::Structure::Block');
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->schild->snext_sibling->isa("PPI::Structure::Block") 2 1 3
41  
42 # code uses block-eval
43 1 return $self->violation( $DESC, $EXPL, $elem );
44 }
45  
46 5 1;
47  
48 =pod
49  
50 =encoding UTF-8
51  
52 =head1 NAME
53  
54 Perl::Critic::Policy::Reneeb::ProhibitBlockEval - Do not use the Block-eval. Use Try::Tiny instead
55  
56 =head1 VERSION
57  
58 version 2.05
59  
60 =head1 DESCRIPTION
61  
62 L<Try::Tiny|https://metacpan.org/pod/Try::Tiny> adds some syntactic sugar to your Perl programs.
63 It avoids some quirks with exception handling that uses C<eval{...}>.
64  
65 =head1 AUTHOR
66  
67 Renee Baecker <reneeb@cpan.org>
68  
69 =head1 COPYRIGHT AND LICENSE
70  
71 This software is Copyright (c) 2015 by Renee Baecker.
72  
73 This is free software, licensed under:
74  
75 The Artistic License 2.0 (GPL Compatible)
76  
77 =cut
78  
79 __END__
« Policy/RegularExpressions/RequireExtendedFormattingExceptForSplit.pm ↑ Summary RENEEB.pm »