Policy/Reneeb/RequirePostderef.pm

filter: Statementstmt 100% 34 / 34 Branchbran 83.3% 5 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 12 / 12 Podpod 100% 4 / 4 totaltotal 98.3% 60 / 61 CC 5 SCAR 8.1
CC
5
Cov
98%
violates
5.0
__ANON__
1.0
BEGIN
1.0
CRAP 2.3
« Policy/Reneeb/Capitalization.pm ↑ Summary Policy/RegularExpressions/RequireExtendedFormattingExceptForSplit.pm »
1 package Perl::Critic::Policy::Reneeb::RequirePostderef;
2  
3 # ABSTRACT: Require Postdereferencing which became stable in Perl 5.24
4  
5 5 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 our $VERSION = '2.05';
16  
17 #-----------------------------------------------------------------------------
18  
19 5 Readonly::Scalar my $DESC => q{Use postderef (e.g. $ref->@*) instead of the "old" dereferencing (e.g. @{$ref})};
20 5 Readonly::Scalar my $EXPL => [ ];
21  
22 #-----------------------------------------------------------------------------
23  
24 22 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
25 1 ▶sub default_themes { return qw<reneeb> }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
26 23 ▶sub applies_to {
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
27 23 return qw<
28 PPI::Token::Cast
29 >;
30 }
31  
32 #-----------------------------------------------------------------------------
33  
34 20 ▶sub violates {
Subroutine violates: called CC=5 SCAR=16.1
Pod documented
35 20 my ( $self, $elem, $doc ) = @_;
36  
37 # postderence syntax do also have a PPI::Token::Cast object,
38 # but that looks different
39 20 ▶ return if !first{ $elem->content ne $_ }qw($ @ * % &),'$#';
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless &first(sub { $elem->content ne $_; } , ("\$", "\@", "*", "%", "&"), "\$#") 0 20 20
40  
41 20 my $sibling = $elem->snext_sibling;
42 20 ▶ return if !$sibling;
Branch: 1 branch
BranchTrueFalseTotal
unless $sibling 3 17 20
43  
44 # grep in boolean or void context isn't checked
45 17 ▶ return if !$sibling->isa('PPI::Structure::Block') && !$sibling->isa('PPI::Token::Symbol');
Branch: 1 branch
BranchTrueFalseTotal
unless $sibling->isa("PPI::Structure::Block") or $sibling->isa("PPI::Token::Symbol") 4 13 17
Condition100%3/3
$sibling->isa("PPI::Structure::Block") or $sibling->isa("PPI::Token::Symbol")
l!l&&r!l&&!r
944
MC/DC100%2/2
$sibling->isa("PPI::Structure::Block") or $sibling->isa("PPI::Token::Symbol")
$sibling->isa("PPI::Structure::Block") $sibling->isa("PPI::Token::Symbol")
Truth table100%3/3
A or B
A= $sibling->isa("PPI::Structure::Block")B= $sibling->isa("PPI::Token::Symbol")
ABresult
1X1
011
000
46  
47 13 return $self->violation( $DESC, $EXPL, $elem );
48 }
49  
50 5 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.05
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__
« Policy/Reneeb/Capitalization.pm ↑ Summary Policy/RegularExpressions/RequireExtendedFormattingExceptForSplit.pm »