Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / BuiltinFunctions / ProhibitStringySplit.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitStringySplit.pm $
3 #     $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :characters :severities :classification :ppi };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC => q{String delimiter used with "split"};
23 Readonly::Scalar my $EXPL => q{Express it as a regex instead};
24
25 #-----------------------------------------------------------------------------
26
27 sub supported_parameters { return ()                    }
28 sub default_severity     { return $SEVERITY_LOW         }
29 sub default_themes       { return qw(core pbp cosmetic) }
30 sub applies_to           { return 'PPI::Token::Word'    }
31
32 #-----------------------------------------------------------------------------
33
34 sub violates {
35     my ( $self, $elem, undef ) = @_;
36
37     return if $elem ne 'split';
38     return if ! is_function_call($elem);
39
40     my @args = parse_arg_list($elem);
41     my $pattern = @args ? $args[0]->[0] : return;
42
43     if ( $pattern->isa('PPI::Token::Quote') && $pattern->string() ne $SPACE ) {
44         return $self->violation( $DESC, $EXPL, $elem );
45     }
46
47     return;  #ok
48 }
49
50
51 1;
52
53 __END__
54
55 #-----------------------------------------------------------------------------
56
57 =pod
58
59 =head1 NAME
60
61 Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit - Write C<split /-/, $string> instead of C<split '-', $string>.
62
63 =head1 AFFILIATION
64
65 This Policy is part of the core L<Perl::Critic> distribution.
66
67
68 =head1 DESCRIPTION
69
70 The C<split> function always interprets the PATTERN argument as a
71 regular expression, even if you specify it as a string.  This causes
72 much confusion if the string contains regex metacharacters.  So for
73 clarity, always express the PATTERN argument as a regex.
74
75   $string = 'Fred|Barney';
76   @names = split '|', $string; #not ok, is ('F', 'r', 'e', 'd', '|', 'B', 'a' ...)
77   @names = split m/[|]/, $string; #ok, is ('Fred', Barney')
78
79 When the PATTERN is a single space the C<split> function has special
80 behavior, so Perl::Critic forgives that usage.  See C<"perldoc -f
81 split"> for more information.
82
83
84 =head1 CONFIGURATION
85
86 This Policy is not configurable except for the standard options.
87
88
89 =head1 SEE ALSO
90
91 L<Perl::Critic::Policy::ControlStrucutres::RequireBlockGrep>
92
93 L<Perl::Critic::Policy::ControlStrucutres::RequireBlockMap>
94
95 =head1 AUTHOR
96
97 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
98
99 =head1 COPYRIGHT
100
101 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
102
103 This program is free software; you can redistribute it and/or modify
104 it under the same terms as Perl itself.  The full text of this license
105 can be found in the LICENSE file included with this module.
106
107 =cut
108
109 # Local Variables:
110 #   mode: cperl
111 #   cperl-indent-level: 4
112 #   fill-column: 78
113 #   indent-tabs-mode: nil
114 #   c-indentation-style: bsd
115 # End:
116 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :