File Coverage

blib/lib/Perl/Critic/Policy/Dancer2/ProhibitUnrecommendedKeywords.pm
Criterion Covered Total %
statement 29 30 96.6
branch 7 8 87.5
condition 4 6 66.6
subroutine 10 11 90.9
pod 4 4 100.0
total 54 59 91.5


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 unrecommended Dancer2 keywords
5             use 5.006001;
6 3     3   2144 use strict;
  3         11  
7 3     3   15 use warnings;
  3         6  
  3         59  
8 3     3   13 use Readonly;
  3         7  
  3         77  
9 3     3   14  
  3         6  
  3         153  
10             use Perl::Critic::Utils qw{
11 3         232 :booleans :characters :severities :classification :data_conversion
12             };
13 3     3   16 use base 'Perl::Critic::Policy';
  3         7  
14 3     3   1531  
  3         7  
  3         964  
15              
16 1     1 1 15 Readonly::Hash my %unrecommended_words =>
17 0     0 1 0 ( { params => q{body_parameters', 'route_parameters', or 'query_parameters} }, );
18 2     2 1 102147 Readonly::Scalar my $EXPL =>
19             'You are using a Dancer2 keyword that is not recommended, and may be deprecated in the future.';
20              
21             my ( $self, $elem, $doc ) = @_;
22             my $included = $doc->find_any(
23             sub {
24             $_[1]->isa('PPI::Statement::Include')
25             and defined( $_[1]->module() )
26 62     62 1 736 and ( $_[1]->module() eq 'Dancer2' )
27             and $_[1]->type() eq 'use';
28             }
29 7334 50 66 7334   66955 );
      66        
30             return if !$included;
31             if ( defined $unrecommended_words{$elem} ) {
32             return if is_hash_key($elem);
33             my $alternative = $unrecommended_words{$elem};
34 62         238 my $desc = qq{Use '$alternative' instead of unrecommended Dancer2 keyword '$elem'};
35 62 100       2307 return $self->violation( $desc, $EXPL, $elem );
36 32 100       60 }
37 4 100       45 return;
38 1         61 }
39 1         18  
40 1         26 1;
41              
42 28         313  
43             =pod
44              
45             =encoding UTF-8
46              
47             =head1 NAME
48              
49             Perl::Critic::Policy::Dancer2::ProhibitUnrecommendedKeywords - Trigger perlcritic alerts on unrecommended Dancer2 keywords
50              
51             =head1 VERSION
52              
53             version 0.4100
54              
55             =head1 DESCRIPTION
56              
57             The L<Dancer2> team has a deprecation policy, detailed at
58             L<Dancer2::DeprecationPolicy>, that will, in time, cause certain
59             keywords to be removed from the Dancer2 codebase. The keywords
60             addressed in this policy have newer substitutes and/or have been
61             suggested for deprecation.
62              
63             =head1 AFFILIATION
64              
65             This policy is part of L<Perl::Critic::Dancer2>.
66              
67             =head1 CONFIGURATION
68              
69             This Policy is not configurable except for the standard options.
70              
71             =head1 AUTHOR
72              
73             D Ruth Holloway <ruth@hiruthie.me>
74              
75             =head1 COPYRIGHT AND LICENSE
76              
77             This software is copyright (c) 2022 by D Ruth Holloway.
78              
79             This is free software; you can redistribute it and/or modify it under
80             the same terms as the Perl 5 programming language system itself.
81              
82             =cut