« lib/Perl/Critic/Policy/NamingConventions/Capitalization.pm
↑ Summary
lib/Perl/Critic/Policy/Documentation/RequirePackageMatchesPodName.pm »
| 1 | package Perl::Critic::Policy::InputOutput::RequireEncodingWithUTF8Layer; | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 7 | 40 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use Perl::Critic::Utils qw{ :severities :ppi }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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{I/O layer ":utf8" used}; | |||||||||||||||||||||||||||
| 17 | 40 | Readonly::Scalar my $EXPL => q{Use ":encoding(UTF-8)" to get strict validation}; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 40 | Readonly::Scalar my $THREE_ARGUMENT_OPEN => 3; | |||||||||||||||||||||||||||
| 20 | 40 | Readonly::Hash my %RECOVER_ENCODING => ( | |||||||||||||||||||||||||||
| 21 | binmode => \&_recover_binmode_encoding, | ||||||||||||||||||||||||||||
| 22 | open => \&_recover_open_encoding, | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 74 | ▶ | sub default_severity { return $SEVERITY_HIGHEST } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 73 | ▶ | sub default_themes { return qw(core bugs security) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 37 | ▶ | sub applies_to { return 'PPI::Token::Word' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 361 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=4 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 361 | my ($self, $elem, undef) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 361 | ▶ | my $handler = $RECOVER_ENCODING{ $elem->content() } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | or return; # If we don't have a handler, we're not interested. | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my $encoding = $handler->( parse_arg_list( $elem ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | or return; # If we can't recover an encoding, we give up. | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return if $encoding !~ m/ (?: \A | : ) utf8 \b /smxi; # OK | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # my $string = _get_argument_string( $arg[1] ); | ||||||||||||||||||||||||||||
| 49 | # | ||||||||||||||||||||||||||||
| 50 | # This subroutine returns the string from the given argument (which must | ||||||||||||||||||||||||||||
| 51 | # be a reference to an array of PPI objects), _PROVIDED_ the array | ||||||||||||||||||||||||||||
| 52 | # contains a single PPI::Token::Quote object. Otherwise it simply | ||||||||||||||||||||||||||||
| 53 | # returns, since we're too stupid to analyze anything else. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub _get_argument_string { | ||||||||||||||||||||||||||
|
Subroutine
_get_argument_string: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 56 | 0 | my ( $arg ) = @_; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | ref $arg eq 'ARRAY' or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return if @{ $arg } == 0 || @{ $arg } > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@{$arg;} == 0 or @{$arg;} > 1
MC/DC0%0/2
@{$arg;} == 0 or @{$arg;} > 1
@{$arg;} == 0
@{$arg;} > 1
Truth table0%0/3
A or B
A= @{$arg;} == 0B= @{$arg;} > 1
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return $arg->[0]->string() if $arg->[0]->isa( 'PPI::Token::Quote' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | return; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # my $encoding = _recover_binmode_encoding( _parse_arg_list( $elem ) ); | ||||||||||||||||||||||||||||
| 66 | # | ||||||||||||||||||||||||||||
| 67 | # This subroutine returns the encoding specified by the given $elem, | ||||||||||||||||||||||||||||
| 68 | # which _MUST_ be the 'binmode' of a binmode() call. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub _recover_binmode_encoding { | ||||||||||||||||||||||||||
|
Subroutine
_recover_binmode_encoding: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 71 | 0 | my ( @args ) = @_; | |||||||||||||||||||||||||||
| 72 | 0 | return _get_argument_string( $args[1] ); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # my $encoding = _recover_open_encoding( _parse_arg_list( $elem ) ); | ||||||||||||||||||||||||||||
| 78 | # | ||||||||||||||||||||||||||||
| 79 | # This subroutine returns the encoding specified by the given $elem, | ||||||||||||||||||||||||||||
| 80 | # which _MUST_ be the 'open' of an open() call. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub _recover_open_encoding { | ||||||||||||||||||||||||||
|
Subroutine
_recover_open_encoding: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 83 | 0 | my ( @args ) = @_; | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | @args < $THREE_ARGUMENT_OPEN | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | and return; | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | defined( my $string = _get_argument_string( $args[1] ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | or return; | ||||||||||||||||||||||||||||
| 88 | 0 | $string =~ s/ [+]? (?: < | >{1,2} ) //smx; | |||||||||||||||||||||||||||
| 89 | 0 | return $string; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 40 | 1; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||