File Coverage

blib/lib/Perl/Critic/Policy/BuiltinFunctions/RequireGlobFunction.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 2 100.0
condition n/a
subroutine 11 11 100.0
pod 4 5 80.0
total 42 43 97.6


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::BuiltinFunctions::RequireGlobFunction;
2              
3 40     40   26897 use 5.010001;
  40         217  
4 40     40   301 use strict;
  40         125  
  40         1196  
5 40     40   274 use warnings;
  40         113  
  40         956  
6 40     40   236 use Readonly;
  40         112  
  40         1999  
7              
8 40     40   323 use Perl::Critic::Utils qw{ :severities };
  40         154  
  40         2075  
9 40     40   5230 use parent 'Perl::Critic::Policy';
  40         124  
  40         247  
10              
11             our $VERSION = '1.146';
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $GLOB_RX => qr< [*?] >xms;
16             Readonly::Scalar my $DESC => q{Glob written as <...>};
17             Readonly::Scalar my $EXPL => [ 167 ];
18              
19             #-----------------------------------------------------------------------------
20              
21 93     93 0 1643 sub supported_parameters { return () }
22 78     78 1 391 sub default_severity { return $SEVERITY_HIGHEST }
23 92     92 1 435 sub default_themes { return qw( core pbp bugs ) }
24 40     40 1 181 sub applies_to { return 'PPI::Token::QuoteLike::Readline' }
25              
26             #-----------------------------------------------------------------------------
27              
28             sub violates {
29 5     5 1 15 my ( $self, $elem, undef ) = @_;
30              
31 5 100       27 if ( $elem =~ $GLOB_RX ) {
32 4         41 return $self->violation( $DESC, $EXPL, $elem );
33             }
34 1         9 return; #ok!
35             }
36              
37             1;
38              
39             __END__
40              
41             #-----------------------------------------------------------------------------
42              
43             =pod
44              
45             =head1 NAME
46              
47             Perl::Critic::Policy::BuiltinFunctions::RequireGlobFunction - Use C<glob q{*}> instead of <*>.
48              
49              
50             =head1 AFFILIATION
51              
52             This Policy is part of the core L<Perl::Critic|Perl::Critic>
53             distribution.
54              
55              
56             =head1 DESCRIPTION
57              
58             Conway discourages the use of the C<< <..> >> construct for globbing, as
59             it is easily confused with the angle bracket file input operator.
60             Instead, he recommends the use of the C<glob()> function as it makes
61             it much more obvious what you're attempting to do.
62              
63             @files = <*.pl>; # not ok
64             @files = glob '*.pl'; # ok
65              
66              
67             =head1 CONFIGURATION
68              
69             This Policy is not configurable except for the standard options.
70              
71              
72             =head1 AUTHOR
73              
74             Graham TerMarsch <graham@howlingfrog.com>
75              
76              
77             =head1 COPYRIGHT
78              
79             Copyright (c) 2005-2011 Graham TerMarsch. All rights reserved.
80              
81             This program is free software; you can redistribute it and/or modify
82             it under the same terms as Perl itself.
83              
84             =cut
85              
86             # Local Variables:
87             # mode: cperl
88             # cperl-indent-level: 4
89             # fill-column: 78
90             # indent-tabs-mode: nil
91             # c-indentation-style: bsd
92             # End:
93             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :