File Coverage

blib/lib/Perl/Critic/Policy/Dancer2/ProhibitDeprecatedKeywords.pm
Criterion Covered Total %
statement 31 32 96.8
branch 6 6 100.0
condition 5 6 83.3
subroutine 11 12 91.6
pod 4 4 100.0
total 57 60 95.0


line stmt bran cond sub pod time code
1              
2             our $VERSION = '0.4000'; # VERSION
3             our $AUTHORITY = 'cpan:GEEKRUTH'; # AUTHORITY
4             # ABSTRACT: Trigger perlcritic alerts on deprecated Dancer2 keywords
5             use 5.006001;
6 2     2   1630 use strict;
  2         7  
7 2     2   11 use warnings;
  2         5  
  2         50  
8 2     2   10 use Readonly;
  2         5  
  2         57  
9 2     2   11  
  2         4  
  2         111  
10             use Perl::Critic::Utils qw{
11 2         132 :booleans :characters :severities :classification :data_conversion
12             };
13 2     2   13 use Perl::Critic::Utils::PPI qw{ is_ppi_expression_or_generic_statement };
  2         8  
14 2     2   1065 use base 'Perl::Critic::Policy';
  2         5  
  2         83  
15 2     2   10  
  2         4  
  2         735  
16              
17 4     4 1 43 Readonly::Hash my %deprecated_words => (
18 0     0 1 0 context => 'app',
19 2     2 1 50190 header => 'response_header',
20             headers => 'request_headers',
21             push_header => 'push_response_header'
22             );
23             Readonly::Scalar my $EXPL =>
24             'You are using a Dancer2 keyword that is being or has been deprecated.';
25              
26             my ( $self, $elem, $doc ) = @_;
27              
28             my $included = $doc->find_any(
29             sub {
30             $_[1]->isa('PPI::Statement::Include')
31 26     26 1 912 and defined( $_[1]->module() )
32             and ( $_[1]->module() eq 'Dancer2' )
33             and $_[1]->type() eq 'use';
34             }
35 910 100 66 910   9304 );
      100        
36             return if !$included;
37             if ( defined $deprecated_words{$elem} ) {
38             my $alternative = $deprecated_words{$elem};
39             my $desc = qq{Use '$alternative' instead of deprecated Dancer2 keyword '$elem'};
40 26         135 return $self->violation( $desc, $EXPL, $elem );
41 26 100       1059 }
42 13 100       29 return;
43 4         47 }
44 4         44  
45 4         33 1;
46              
47 9         112  
48             =pod
49              
50             =encoding UTF-8
51              
52             =head1 NAME
53              
54             Perl::Critic::Policy::Dancer2::ProhibitDeprecatedKeywords - Trigger perlcritic alerts on deprecated Dancer2 keywords
55              
56             =head1 VERSION
57              
58             version 0.4000
59              
60             =head1 DESCRIPTION
61              
62             The L<Dancer2> team has a deprecation policy, detailed at
63             L<Dancer2::DeprecationPolicy>, that will, in time, cause certain
64             keywords to be removed from the Dancer2 codebase. You should not
65             use these keywords, to prevent breaking your application when
66             you update Dancer2 beyond that deprecation point.
67              
68             =cut
69              
70             =head1 AFFILIATION
71              
72             This policy is part of L<Perl::Critic::Dancer2>.
73              
74             =head1 CONFIGURATION
75              
76             This Policy is not configurable except for the standard options.
77              
78             =head1 AUTHOR
79              
80             D Ruth Holloway <ruth@hiruthie.me>
81              
82             =head1 COPYRIGHT AND LICENSE
83              
84             This software is copyright (c) 2022 by D Ruth Holloway.
85              
86             This is free software; you can redistribute it and/or modify it under
87             the same terms as the Perl 5 programming language system itself.
88              
89             =cut