| 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
|
5
|
|
|
5
|
|
3307
|
use 5.006001; |
|
|
5
|
|
|
|
|
19
|
|
|
6
|
5
|
|
|
5
|
|
28
|
use strict; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
96
|
|
|
7
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
108
|
|
|
8
|
5
|
|
|
5
|
|
27
|
use Readonly; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
277
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
65
|
use Perl::Critic::Utils qw{ :severities }; |
|
|
5
|
|
|
|
|
23
|
|
|
|
5
|
|
|
|
|
265
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
631
|
use base 'Perl::Critic::Policy'; |
|
|
5
|
|
|
|
|
358
|
|
|
|
5
|
|
|
|
|
1515
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '2.05'; |
|
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
|
5368
|
sub default_severity { return $SEVERITY_MEDIUM } |
|
24
|
1
|
|
|
1
|
1
|
694
|
sub default_themes { return qw<reneeb> } |
|
25
|
|
|
|
|
|
|
sub applies_to { |
|
26
|
3
|
|
|
3
|
1
|
240063
|
return qw< |
|
27
|
|
|
|
|
|
|
PPI::Statement |
|
28
|
|
|
|
|
|
|
>; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub violates { |
|
34
|
14
|
|
|
14
|
1
|
709
|
my ( $self, $elem, $doc ) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# other statements than eval aren't catched |
|
37
|
14
|
100
|
|
|
|
40
|
return if $elem->schild ne 'eval'; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# string eval isn't catched by this policy |
|
40
|
3
|
100
|
|
|
|
70
|
return if !$elem->schild->snext_sibling->isa('PPI::Structure::Block'); |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# code uses block-eval |
|
43
|
1
|
|
|
|
|
57
|
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.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__ |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|