« lib/Perl/Critic/Policy/Miscellanea/ProhibitTies.pm
↑ Summary
lib/Perl/Critic/Policy/ControlStructures/ProhibitDeepNests.pm »
| 1 | package Perl::Critic::Policy::RegularExpressions::RequireBracesForMultiline; | ||||||||||
| 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{ :booleans :severities }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 40 | our $VERSION = '1.156'; | |||||||||
| 13 | |||||||||||
| 14 | #----------------------------------------------------------------------------- | ||||||||||
| 15 | |||||||||||
| 16 | 40 | Readonly::Scalar my $DESC => q<Use '{' and '}' to delimit multi-line regexps>; | |||||||||
| 17 | 40 | Readonly::Scalar my $EXPL => [242]; | |||||||||
| 18 | |||||||||||
| 19 | 40 | Readonly::Array my @EXTRA_BRACKETS => qw{ () [] <> }; | |||||||||
| 20 | |||||||||||
| 21 | #----------------------------------------------------------------------------- | ||||||||||
| 22 | |||||||||||
| 23 | 91 | ▶ | sub supported_parameters { | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | return ( | ||||||||||
| 25 | { | ||||||||||
| 26 | 91 | name => 'allow_all_brackets', | |||||||||
| 27 | description => | ||||||||||
| 28 | q[In addition to allowing '{}', allow '()', '[]', and '{}'.], | ||||||||||
| 29 | behavior => 'boolean', | ||||||||||
| 30 | }, | ||||||||||
| 31 | ); | ||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 74 | ▶ | sub default_severity { return $SEVERITY_LOWEST } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 35 | 83 | ▶ | sub default_themes { return qw( core pbp cosmetic ) } | ||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 36 | 31 | ▶ | sub applies_to { return qw(PPI::Token::Regexp::Match | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | PPI::Token::Regexp::Substitute | ||||||||||
| 38 | PPI::Token::QuoteLike::Regexp) } | ||||||||||
| 39 | |||||||||||
| 40 | #----------------------------------------------------------------------------- | ||||||||||
| 41 | |||||||||||
| 42 | 48 | ▶ | sub initialize_if_enabled { | ||||||||
|
Subroutine
initialize_if_enabled: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 43 | 48 | my ( $self, undef ) = @_; | |||||||||
| 44 | |||||||||||
| 45 | 48 | my %delimiters = ( q<{}> => 1 ); | |||||||||
| 46 | 48 | ▶ | if ( $self->{_allow_all_brackets} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | @delimiters{ @EXTRA_BRACKETS } = (1) x @EXTRA_BRACKETS; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 48 | $self->{_allowed_delimiters} = \%delimiters; | |||||||||
| 51 | |||||||||||
| 52 | 48 | return $TRUE; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | #----------------------------------------------------------------------------- | ||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=3 SCAR=16.0
Pod
documented
| |||||||||||
| 58 | 1 | my ( $self, $elem, undef ) = @_; | |||||||||
| 59 | |||||||||||
| 60 | 1 | my $re = $elem->get_match_string(); | |||||||||
| 61 | 1 | ▶ | return if $re !~ m/\n/xms; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | |||||||||||
| 63 | 0 | my ($match_delim) = $elem->get_delimiters(); | |||||||||
| 64 | 0 | ▶ | return if $self->{_allowed_delimiters}{$match_delim}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | |||||||||||
| 66 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 40 | 1; | |||||||||
| 70 | |||||||||||
| 71 | __END__ | ||||||||||