| 1 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic-More/lib/Perl/Critic/Policy/ValuesAndExpressions/RestrictLongStrings.pm $ | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # $Date: 2013-10-29 09:39:11 -0700 (Tue, 29 Oct 2013) $ | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # $Author: thaljef $ | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # $Revision: 4222 $ | ||||||||||||||||||||||||||||||||||||||||||
| 6 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | package Perl::Critic::Policy::ValuesAndExpressions::RestrictLongStrings; | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use 5.006001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use Perl::Critic::Utils qw{ :severities }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | our $VERSION = '1.003'; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | #--------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | Readonly::Scalar my $DESC => 'Long string mixed with code'; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 7 | Readonly::Scalar my $EXPL => | |||||||||||||||||||||||||||||||||||||||||
| 27 | 'Put long strings in their own subroutine or split them'; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | #--------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 8 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | sub default_themes { return qw< more readability > } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | sub applies_to { return 'PPI::Token::Quote' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 10 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 10 | { name => 'max_length', | |||||||||||||||||||||||||||||||||||||||||
| 38 | description => 'The maximum line length to allow.', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | default_string => '78', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | behavior => 'integer', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | integer_minimum => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | #--------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 17 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=8 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 17 | my ( $self, $elem, $doc ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 17 | my $length = length $elem->string; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 17 | ▶ | return if $length <= $self->{_max_length}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # Allow long strings in the last statment of a subroutine | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | my $stmt = $elem->statement; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | ▶ | if ( !$stmt->snext_sibling ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | my $stmt_parent = $stmt->parent; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | if ( $stmt_parent->isa('PPI::Structure::Block') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # Named subroutine | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | return if $stmt_parent->parent->isa('PPI::Statement::Sub'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # Anonymous subroutine | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my $sib = $stmt_parent->sprevious_sibling; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | return if $sib && $sib->isa('PPI::Token::Word') && 'sub' eq $sib; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$sib and $sib->isa("PPI::Token::Word") and "sub" eq $sib
$sib and $sib->isa("PPI::Token::Word")
MC/DC0%0/3
$sib and $sib->isa("PPI::Token::Word") and "sub" eq $sib
$sib
$sib->isa("PPI::Token::Word")
"sub" eq $sib
Truth table25%1/4
A and B and C
A= $sibB= $sib->isa("PPI::Token::Word")C= "sub" eq $sib
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 7 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||||||||||||||||