File Coverage

blib/lib/Perl/Critic/Policy/Reneeb/ProhibitBlockEval.pm
Criterion Covered Total %
statement 24 24 100.0
branch 4 4 100.0
condition n/a
subroutine 10 10 100.0
pod 4 4 100.0
total 42 42 100.0


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Reneeb::ProhibitBlockEval;
2              
3             # ABSTRACT: Do not use the Block-eval. Use Try::Tiny instead
4              
5 4     4   2625 use 5.006001;
  4         15  
6 4     4   23 use strict;
  4         8  
  4         80  
7 4     4   19 use warnings;
  4         10  
  4         85  
8 4     4   20 use Readonly;
  4         11  
  4         179  
9              
10 4     4   24 use Perl::Critic::Utils qw{ :severities };
  4         16  
  4         260  
11              
12 4     4   606 use base 'Perl::Critic::Policy';
  4         10  
  4         1132  
13              
14             our $VERSION = '2.03';
15              
16             #-----------------------------------------------------------------------------
17              
18             Readonly::Scalar my $DESC => q{Prohibit Block-eval};
19             Readonly::Scalar my $EXPL => [ 237 ];
20              
21             #-----------------------------------------------------------------------------
22              
23 10     10 1 5223 sub default_severity { return $SEVERITY_MEDIUM }
24 1     1 1 646 sub default_themes { return qw<reneeb> }
25             sub applies_to {
26 3     3 1 236280 return qw<
27             PPI::Statement
28             >;
29             }
30              
31             #-----------------------------------------------------------------------------
32              
33             sub violates {
34 14     14 1 745 my ( $self, $elem, $doc ) = @_;
35              
36             # other statements than eval aren't catched
37 14 100       39 return if $elem->schild ne 'eval';
38              
39             # string eval isn't catched by this policy
40 3 100       115 return if !$elem->schild->snext_sibling->isa('PPI::Structure::Block');
41              
42             # code uses block-eval
43 1         98 return $self->violation( $DESC, $EXPL, $elem );
44             }
45              
46             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.03
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__
80              
81             #-----------------------------------------------------------------------------
82              
83