| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
our $VERSION = '0.4100'; # VERSION |
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GEEKRUTH'; # AUTHORITY |
|
4
|
|
|
|
|
|
|
# ABSTRACT: Trigger perlcritic alerts on needless return statements |
|
5
|
|
|
|
|
|
|
use 5.006001; |
|
6
|
3
|
|
|
3
|
|
1053768
|
use strict; |
|
|
3
|
|
|
|
|
30
|
|
|
7
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
55
|
|
|
8
|
3
|
|
|
3
|
|
13
|
use Readonly; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
63
|
|
|
9
|
3
|
|
|
3
|
|
14
|
|
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
151
|
|
|
10
|
|
|
|
|
|
|
use Perl::Critic::Utils qw{ |
|
11
|
3
|
|
|
|
|
182
|
:booleans :characters :severities :classification :data_conversion |
|
12
|
|
|
|
|
|
|
}; |
|
13
|
3
|
|
|
3
|
|
29
|
use Perl::Critic::Utils::PPI qw{ is_ppi_expression_or_generic_statement }; |
|
|
3
|
|
|
|
|
5
|
|
|
14
|
3
|
|
|
3
|
|
1527
|
use base 'Perl::Critic::Policy'; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
134
|
|
|
15
|
3
|
|
|
3
|
|
18
|
|
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
1447
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
1
|
34
|
Readonly::Array my @implicit_returns => qw/ |
|
18
|
0
|
|
|
0
|
1
|
0
|
forward |
|
19
|
2
|
|
|
2
|
1
|
107441
|
halt |
|
20
|
|
|
|
|
|
|
pass |
|
21
|
|
|
|
|
|
|
redirect |
|
22
|
|
|
|
|
|
|
send_as |
|
23
|
|
|
|
|
|
|
send_error |
|
24
|
|
|
|
|
|
|
send_file/; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => |
|
27
|
|
|
|
|
|
|
'Certain keywords will immediately end a route, and do not need a return statement.'; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my ( $self, $elem, $doc ) = @_; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
return if is_hash_key($elem); |
|
32
|
|
|
|
|
|
|
return if is_method_call($elem); |
|
33
|
|
|
|
|
|
|
return if is_subroutine_name($elem); |
|
34
|
62
|
|
|
62
|
1
|
1902
|
return if is_included_module_name($elem); |
|
35
|
|
|
|
|
|
|
return if is_package_declaration($elem); |
|
36
|
62
|
100
|
|
|
|
138
|
|
|
37
|
50
|
50
|
|
|
|
3214
|
my $included = $doc->find_any( |
|
38
|
50
|
100
|
|
|
|
1184
|
sub { |
|
39
|
42
|
100
|
|
|
|
877
|
$_[1]->isa('PPI::Statement::Include') |
|
40
|
41
|
100
|
|
|
|
876
|
and defined( $_[1]->module() ) |
|
41
|
|
|
|
|
|
|
and ( $_[1]->module() eq 'Dancer2' ) |
|
42
|
|
|
|
|
|
|
and $_[1]->type() eq 'use'; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
4643
|
50
|
66
|
4643
|
|
42790
|
); |
|
|
|
|
66
|
|
|
|
|
|
45
|
|
|
|
|
|
|
return if !$included; |
|
46
|
|
|
|
|
|
|
if ( grep { $_ eq $elem} @implicit_returns ) { |
|
47
|
|
|
|
|
|
|
my $stmnt = $elem->statement(); |
|
48
|
|
|
|
|
|
|
if ($stmnt =~ /^return $elem/){ |
|
49
|
39
|
|
|
|
|
890
|
return $self->violation( "Don't need return before $elem", $EXPL, $elem ); |
|
50
|
39
|
100
|
|
|
|
1591
|
} |
|
51
|
20
|
100
|
|
|
|
64
|
} |
|
|
140
|
|
|
|
|
1635
|
|
|
52
|
2
|
|
|
|
|
29
|
return; |
|
53
|
2
|
100
|
|
|
|
31
|
} |
|
54
|
1
|
|
|
|
|
86
|
|
|
55
|
|
|
|
|
|
|
1; |
|
56
|
|
|
|
|
|
|
|
|
57
|
19
|
|
|
|
|
273
|
|
|
58
|
|
|
|
|
|
|
=pod |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=encoding UTF-8 |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 NAME |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Perl::Critic::Policy::Dancer2::ReturnNotNecessary - Trigger perlcritic alerts on needless return statements |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 VERSION |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
version 0.4100 |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Certain L<Dancer2> keywords immediately end execution of a route; specifically, using |
|
73
|
|
|
|
|
|
|
C<forward>, C<halt>, C<pass>, C<redirect>, C<send_as>, C<send_error>, or C<send_file>, |
|
74
|
|
|
|
|
|
|
do not require a C<return> before them, as they do so implicitly. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AFFILIATION |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This policy is part of L<Perl::Critic::Dancer2>. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
D Ruth Holloway <ruth@hiruthie.me> |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This software is copyright (c) 2022 by D Ruth Holloway. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
95
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |