| 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
Condition66%2/3
$words->[0]->content eq "sub" and not $words->[1]->content =~ /\b_\w+\b/msx
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 59 | 1 | $ok++; | |||||||||||||||||||||||||||
| 60 | 1 | last; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 3 | ▶ | if ($ok) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 1 | return; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||
| 68 | 2 | return $self->violation( $warning, $EXPL, $elem ); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 3 | 1; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||