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 / Modules / RequireBarewordIncludes.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/Modules/RequireBarewordIncludes.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::Modules::RequireBarewordIncludes;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $EXPL => q{Use a bareword instead};
23
24 #-----------------------------------------------------------------------------
25
26 sub supported_parameters { return ()                        }
27 sub default_severity     { return $SEVERITY_HIGHEST         }
28 sub default_themes       { return qw(core portability)      }
29 sub applies_to           { return 'PPI::Statement::Include' }
30
31 #-----------------------------------------------------------------------------
32
33 sub violates {
34     my ( $self, $elem, undef ) = @_;
35
36     my $child = $elem->schild(1);
37     return if !$child;
38
39     if ( $child->isa('PPI::Token::Quote') ) {
40         my $type = $elem->type;
41         my $desc = qq{"$type" statement with library name as string};
42         return $self->violation( $desc, $EXPL, $elem );
43     }
44     return; #ok!
45 }
46
47
48 1;
49
50 __END__
51
52 #-----------------------------------------------------------------------------
53
54 =pod
55
56 =head1 NAME
57
58 Perl::Critic::Policy::Modules::RequireBarewordIncludes - Write C<require Module> instead of C<require 'Module.pm'>.
59
60 =head1 AFFILIATION
61
62 This Policy is part of the core L<Perl::Critic> distribution.
63
64
65 =head1 DESCRIPTION
66
67 When including another module (or library) via the C<require> or
68 C<use> statements, it is best to identify the module (or library)
69 using a bareword rather than an explicit path.  This is because paths
70 are usually not portable from one machine to another.  Also, Perl
71 automatically assumes that the filename ends in '.pm' when the library
72 is expressed as a bareword.  So as a side-effect, this Policy
73 encourages people to write '*.pm' modules instead of the old-school
74 '*.pl' libraries.
75
76   use 'My/Perl/Module.pm';  #not ok
77   use My::Perl::Module;     #ok
78
79
80 =head1 CONFIGURATION
81
82 This Policy is not configurable except for the standard options.
83
84
85 =head1 NOTES
86
87 This Policy is a replacement for C<ProhibitRequireStatements>, which
88 completely banned the use of C<require> for the sake of eliminating
89 the old '*.pl' libraries from Perl4.  Upon further consideration, I
90 realized that C<require> is quite useful and necessary to enable
91 run-time loading.  Thus, C<RequireBarewordIncludes> does allow you to
92 use C<require>, but still encourages you to write '*.pm' modules.
93
94 Sometimes, you may want to load modules at run-time, but you don't
95 know at design-time exactly which module you will need to load
96 (L<Perl::Critic> is an example of this).  In that case, just attach
97 the C<'## no critic'> pseudo-pragma like so:
98
99   require $module_name;  ## no critic
100
101
102 =head1 CREDITS
103
104 Chris Dolan <cdolan@cpan.org> was instrumental in identifying the
105 correct motivation for and behavior of this Policy.  Thanks Chris.
106
107 =head1 AUTHOR
108
109 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
110
111 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
112
113 =head1 COPYRIGHT
114
115 This program is free software; you can redistribute it and/or modify
116 it under the same terms as Perl itself.  The full text of this license
117 can be found in the LICENSE file included with this module.
118
119 =cut
120
121 # Local Variables:
122 #   mode: cperl
123 #   cperl-indent-level: 4
124 #   fill-column: 78
125 #   indent-tabs-mode: nil
126 #   c-indentation-style: bsd
127 # End:
128 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :