blib/lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitStringySplit.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 62.5% 5 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 85.4% 53 / 62 CC 6 SCAR 11.9
CC
6
Cov
86%
violates
7.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.3
« blib/lib/Perl/Critic/Utils/POD.pm ↑ Summary blib/lib/Perl/Critic/Policy/CodeLayout/RequireConsistentNewlines.pm »
1 package Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit;
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{ :characters :severities :classification :ppi };
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.150';
12  
13 #-----------------------------------------------------------------------------
14  
15 40 Readonly::Scalar my $DESC => q{String delimiter used with "split"};
16 40 Readonly::Scalar my $EXPL => q{Express it as a regex instead};
17  
18 #-----------------------------------------------------------------------------
19  
20 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 75 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
22 84 ▶sub default_themes { return qw(core pbp cosmetic certrule ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
23 31 ▶sub applies_to { return 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
24  
25 #-----------------------------------------------------------------------------
26  
27 sub violates {
28 332 ▶ my ( $self, $elem, undef ) = @_;
Subroutine violates: called CC=6 SCAR=19.6
Pod documented
29  
30 332 ▶ return if $elem->content() ne 'split';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->content ne "split" 331 1 332
31 1 ▶ return if ! is_function_call($elem);
Branch: 1 branch
BranchTrueFalseTotal
unless is_function_call($elem) 0 1 1
32  
33 1 my @args = parse_arg_list($elem);
34 1 ▶ my $pattern = @args ? $args[0]->[0] : return;
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 1 0 1
35  
36 1 ▶ if ( $pattern->isa('PPI::Token::Quote') && $pattern->string() ne $SPACE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern->isa("PPI::Token::Quote") and $pattern->string ne $Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit::SPACE) 0 1 1
Condition33%1/3
$pattern->isa("PPI::Token::Quote") and $pattern->string ne $Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit::SPACE
!ll&&!rl&&r
100
MC/DC0%0/2
$pattern->isa("PPI::Token::Quote") and $pattern->string ne $Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit::SPACE
$pattern->isa("PPI::Token::Quote") $pattern->string ne $Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit::SPACE
Truth table33%1/3
A and B
A= $pattern->isa("PPI::Token::Quote")B= $pattern->string ne $Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit::SPACE
ABresult
0X0
100
111
37 0 return $self->violation( $DESC, $EXPL, $elem );
38 }
39  
40 1 return; #ok
41 }
42  
43  
44 40 1;
45  
46 __END__
47  
48 #-----------------------------------------------------------------------------
49  
50 =pod
51  
52 =head1 NAME
53  
54 Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit - Write C<split /-/, $string> instead of C<split '-', $string>.
55  
56  
57 =head1 AFFILIATION
58  
59 This Policy is part of the core L<Perl::Critic|Perl::Critic>
60 distribution.
61  
62  
63 =head1 DESCRIPTION
64  
65 The C<split> function always interprets the PATTERN argument as a
66 regular expression, even if you specify it as a string. This causes
67 much confusion if the string contains regex metacharacters. So for
68 clarity, always express the PATTERN argument as a regex.
69  
70 $string = 'Fred|Barney';
71 @names = split '|', $string; #not ok, is ('F', 'r', 'e', 'd', '|', 'B', 'a' ...)
72 @names = split m/[|]/, $string; #ok, is ('Fred', Barney')
73  
74 When the PATTERN is a single space the C<split> function has special
75 behavior, so Perl::Critic forgives that usage. See C<"perldoc -f
76 split"> for more information.
77  
78  
79 =head1 CONFIGURATION
80  
81 This Policy is not configurable except for the standard options.
82  
83  
84 =head1 SEE ALSO
85  
86 L<Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep|Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep>
87  
88 L<Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap|Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap>
89  
90  
91 =head1 AUTHOR
92  
93 Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
94  
95  
96 =head1 COPYRIGHT
97  
98 Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
99  
100 This program is free software; you can redistribute it and/or modify
101 it under the same terms as Perl itself. The full text of this license
102 can be found in the LICENSE file included with this module.
103  
104 =cut
105  
106 # Local Variables:
107 # mode: cperl
108 # cperl-indent-level: 4
109 # fill-column: 78
110 # indent-tabs-mode: nil
111 # c-indentation-style: bsd
112 # End:
113 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
« blib/lib/Perl/Critic/Utils/POD.pm ↑ Summary blib/lib/Perl/Critic/Policy/CodeLayout/RequireConsistentNewlines.pm »