File Coverage

blib/lib/Perl/Critic/Policy/Reneeb/RequirePostderef.pm
Criterion Covered Total %
statement 30 30 100.0
branch 5 6 83.3
condition 3 3 100.0
subroutine 12 12 100.0
pod 4 4 100.0
total 54 55 98.1


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Reneeb::RequirePostderef;
2              
3             # ABSTRACT: Require Postdereferencing which became stable in Perl 5.24
4              
5 5     5   4034 use 5.006001;
  5         20  
6 5     5   28 use strict;
  5         31  
  5         163  
7 5     5   32 use warnings;
  5         17  
  5         166  
8 5     5   29 use Readonly;
  5         10  
  5         318  
9 5     5   49 use List::Util qw(first);
  5         10  
  5         561  
10              
11 5     5   37 use Perl::Critic::Utils qw{ :severities };
  5         11  
  5         297  
12              
13 5     5   760 use base 'Perl::Critic::Policy';
  5         11  
  5         1724  
14              
15             our $VERSION = '2.04';
16              
17             #-----------------------------------------------------------------------------
18              
19             Readonly::Scalar my $DESC => q{Use postderef (e.g. $ref->@*) instead of the "old" dereferencing (e.g. @{$ref})};
20             Readonly::Scalar my $EXPL => [ ];
21              
22             #-----------------------------------------------------------------------------
23              
24 22     22 1 2202 sub default_severity { return $SEVERITY_MEDIUM }
25 1     1 1 609 sub default_themes { return qw<reneeb> }
26             sub applies_to {
27 23     23 1 294462 return qw<
28             PPI::Token::Cast
29             >;
30             }
31              
32             #-----------------------------------------------------------------------------
33              
34             sub violates {
35 20     20 1 428 my ( $self, $elem, $doc ) = @_;
36              
37             # postderence syntax do also have a PPI::Token::Cast object,
38             # but that looks different
39 20 50   20   106 return if !first{ $elem->content ne $_ }qw($ @ * % &),'$#';
  20         66  
40              
41 20         172 my $sibling = $elem->snext_sibling;
42 20 100       516 return if !$sibling;
43              
44             # grep in boolean or void context isn't checked
45 17 100 100     96 return if !$sibling->isa('PPI::Structure::Block') && !$sibling->isa('PPI::Token::Symbol');
46              
47 13         45 return $self->violation( $DESC, $EXPL, $elem );
48             }
49              
50             1;
51              
52             =pod
53              
54             =encoding UTF-8
55              
56             =head1 NAME
57              
58             Perl::Critic::Policy::Reneeb::RequirePostderef - Require Postdereferencing which became stable in Perl 5.24
59              
60             =head1 VERSION
61              
62             version 2.04
63              
64             =head1 DESCRIPTION
65              
66             Use postderef (e.g. $ref->@*) instead of the "old" dereferencing (e.g. @{$ref})
67              
68             =head1 AUTHOR
69              
70             Renee Baecker <reneeb@cpan.org>
71              
72             =head1 COPYRIGHT AND LICENSE
73              
74             This software is Copyright (c) 2015 by Renee Baecker.
75              
76             This is free software, licensed under:
77              
78             The Artistic License 2.0 (GPL Compatible)
79              
80             =cut
81              
82             __END__
83              
84             #-----------------------------------------------------------------------------
85              
86