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.4001'; # VERSION
3             our $AUTHORITY = 'cpan:GEEKRUTH'; # AUTHORITY
4             # ABSTRACT: Trigger perlcritic alerts on unrecommended Dancer2 keywords
5             use 5.006001;
6 2     2   761273 use strict;
  2         21  
7 2     2   10 use warnings;
  2         3  
  2         42  
8 2     2   8 use Readonly;
  2         4  
  2         50  
9 2     2   9  
  2         4  
  2         121  
10             use Perl::Critic::Utils qw{
11 2         139 :booleans :characters :severities :classification :data_conversion
12             };
13 2     2   13 use base 'Perl::Critic::Policy';
  2         4  
14 2     2   1055  
  2         4  
  2         1103  
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 91324 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 48     48 1 682 and ( $_[1]->module() eq 'Dancer2' )
27             and $_[1]->type() eq 'use';
28             }
29 4798 50 66 4798   44482 );
      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 48         171 my $desc = qq{Use '$alternative' instead of unrecommended Dancer2 keyword '$elem'};
35 48 100       1766 return $self->violation( $desc, $EXPL, $elem );
36 25 100       49 }
37 4 100       55 return;
38 1         85 }
39 1         13  
40 1         14 1;
41              
42 21         238  
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.4001
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