File Coverage

blib/lib/Perl/Critic/Policy/BuiltinFunctions/RequireGlobFunction.pm
Criterion Covered Total %
statement 21 25 84.0
branch 0 2 0.0
condition n/a
subroutine 10 11 90.9
pod 4 5 80.0
total 35 43 81.4


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::BuiltinFunctions::RequireGlobFunction;
2              
3 40     40   26320 use 5.010001;
  40         214  
4 40     40   305 use strict;
  40         145  
  40         864  
5 40     40   237 use warnings;
  40         176  
  40         901  
6 40     40   252 use Readonly;
  40         125  
  40         2014  
7              
8 40     40   294 use Perl::Critic::Utils qw{ :severities };
  40         127  
  40         1993  
9 40     40   5614 use parent 'Perl::Critic::Policy';
  40         143  
  40         263  
10              
11             our $VERSION = '1.150';
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 89     89 0 1639 sub supported_parameters { return () }
22 74     74 1 307 sub default_severity { return $SEVERITY_HIGHEST }
23 92     92 1 346 sub default_themes { return qw( core pbp bugs ) }
24 36     36 1 99 sub applies_to { return 'PPI::Token::QuoteLike::Readline' }
25              
26             #-----------------------------------------------------------------------------
27              
28             sub violates {
29 0     0 1   my ( $self, $elem, undef ) = @_;
30              
31 0 0         if ( $elem =~ $GLOB_RX ) {
32 0           return $self->violation( $DESC, $EXPL, $elem );
33             }
34 0           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 :