blib/lib/Perl/Critic/Policy/logicLAB/RequireParamsValidate.pm

filter: Statementstmt 100% 52 / 52 Branchbran 100% 6 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 14 / 14 Podpod 100% 2 / 2 totaltotal 97.4% 77 / 79 CC 6 SCAR 6.7
CC
6
Cov
98%
_assert_params_validate
4.0
violates
3.0
BEGIN
1.0
CRAP 1.9
↑ Summary
1 package Perl::Critic::Policy::logicLAB::RequireParamsValidate;
2  
3 # $Id: ProhibitShellDispatch.pm 8114 2013-07-25 12:57:04Z jonasbn $
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Perl::Critic::Utils qw{ $SEVERITY_MEDIUM };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use List::MoreUtils qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 our $VERSION = '0.03';
15  
16 3 Readonly::Scalar my $EXPL => q{Use Params::Validate for public facing APIs};
17 3 Readonly::Scalar my $warning =>
18 q{Parameter validation not complying with required standard};
19  
20 3 ▶use constant supported_parameters => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use constant default_severity => $SEVERITY_MEDIUM;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use constant default_themes => qw(logiclab);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 ## no critic (RequireParamsValidate);
25  
26 1 ▶sub applies_to {
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
27 return (
28 1 qw(
29 PPI::Statement::Sub
30 )
31 );
32 }
33  
34 4 ▶sub violates {
Subroutine violates: called CC=3 SCAR=11.0
Pod documented
35 4 my ( $self, $elem ) = @_;
36  
37 #For debugging removing all whitespace
38 4 $elem->prune('PPI::Token::Whitespace');
39  
40 4 my $words = $elem->find('PPI::Token::Word');
41  
42 4 ▶ if ( $words->[0]->content eq 'sub'
Branch: 1 branch
BranchTrueFalseTotal
if ($words->[0]->content eq "sub" and not $words->[1]->content =~ /\b_\w+\b/msx) 3 1 4
Condition66%2/3
$words->[0]->content eq "sub" and not $words->[1]->content =~ /\b_\w+\b/msx
!ll&&!rl&&r
013
MC/DC50%1/2
$words->[0]->content eq "sub" and not $words->[1]->content =~ /\b_\w+\b/msx
$words->[0]->content eq "sub" not $words->[1]->content =~ /\b_\w+\b/msx
Truth table66%2/3
A and not(B)
A= $words->[0]->content eq "sub"B= not $words->[1]->content =~ /\b_\w+\b/msx
ABresult
0X0
100
111
43 and $words->[1]->content !~ m/\b_\w+\b/xsm )
44 {
45 3 return $self->_assert_params_validate( $elem, $words );
46 }
47  
48 1 return;
49 }
50  
51 3 ▶sub _assert_params_validate {
Subroutine _assert_params_validate: called CC=4 SCAR=13.9
52 3 my ( $self, $elem, $elements ) = @_;
53  
54 3 my @params_validate_keywords = qw(validate validate_pos validate_with);
55 3 my $ok;
56  
57 3 foreach my $word ( @{$elements} ) {
58 9 ▶ if ( any { $word->content eq $_ } @params_validate_keywords ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $word->content eq $_; } , @params_validate_keywords)) 1 8 9
59 1 $ok++;
60 1 last;
61 }
62 }
63  
64 3 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 1 2 3
65 1 return;
66 }
67 else {
68 2 return $self->violation( $warning, $EXPL, $elem );
69 }
70 }
71  
72 3 1;
73  
74 __END__
↑ Summary