« lib/Perl/Critic/Policy/CodeLayout/ProhibitParensWithBuiltins.pm
↑ Summary
lib/Perl/Critic/Policy/Variables/ProhibitEvilVariables.pm »
| 1 | package Perl::Critic::Policy::InputOutput::RequireBracedFileHandleWithPrint; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 40 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 40 | ▶ | use Perl::Critic::Utils qw{ :severities :classification :data_conversion }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 40 | Readonly::Array my @POSTFIX_WORDS => qw( if unless for ); | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 40 | Readonly::Hash my %POSTFIX_WORDS => hashify( @POSTFIX_WORDS ); | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | 40 | Readonly::Scalar my $PRINT_RX => qr/ \A (?: print f? | say ) \z /xms; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 40 | Readonly::Scalar my $DESC => q{File handle for "print" or "printf" is not braced}; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 40 | Readonly::Scalar my $EXPL => [ 217 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 74 | ▶ | sub default_severity { return $SEVERITY_LOWEST } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 83 | ▶ | sub default_themes { return qw( core pbp cosmetic ) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 31 | ▶ | sub applies_to { return 'PPI::Token::Word' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 332 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=18 SCAR=36.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 332 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 332 | ▶ | return if $elem !~ $PRINT_RX; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | return if ! is_function_call($elem); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | my @sib; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | $sib[0] = $elem->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | return if !$sib[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Deal with situations where 'print' is called with parentheses | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | ▶ | if ( $sib[0]->isa('PPI::Structure::List') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $expr = $sib[0]->schild(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return if !$expr; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $sib[0] = $expr->schild(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | return if !$sib[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | $sib[1] = $sib[0]->next_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | return if !$sib[1]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | $sib[2] = $sib[1]->next_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | ▶ | return if !$sib[2]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # First token must be a scalar symbol or bareword; | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | ▶ | return if !( ($sib[0]->isa('PPI::Token::Symbol') && $sib[0] =~ m/\A \$/xms) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$sib[0]->isa("PPI::Token::Symbol") and $sib[0] =~ /\A \$/msx or $sib[0]->isa("PPI::Token::Word")
$sib[0]->isa("PPI::Token::Symbol") and $sib[0] =~ /\A \$/msx
MC/DC0%0/3
$sib[0]->isa("PPI::Token::Symbol") and $sib[0] =~ /\A \$/msx or $sib[0]->isa("PPI::Token::Word")
$sib[0]->isa("PPI::Token::Symbol")
$sib[0] =~ /\A \$/msx
$sib[0]->isa("PPI::Token::Word")
Truth table40%2/5
A and B or C
A= $sib[0]->isa("PPI::Token::Symbol")B= $sib[0] =~ /\A \$/msxC= $sib[0]->isa("PPI::Token::Word")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | || $sib[0]->isa('PPI::Token::Word') ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # First token must not be a builtin function or control | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | return if is_perl_builtin($sib[0]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | ▶ | return if exists $POSTFIX_WORDS{ $sib[0] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # Second token must be white space | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | ▶ | return if !$sib[1]->isa('PPI::Token::Whitespace'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # Third token must not be an operator | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | return if $sib[2]->isa('PPI::Token::Operator'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # Special case for postfix controls | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | return if exists $POSTFIX_WORDS{ $sib[2] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return if $sib[0]->isa('PPI::Structure::Block'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||