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) $
6 ##############################################################################
8 package Perl::Critic::Policy::Modules::RequireBarewordIncludes;
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $EXPL => q{Use a bareword instead};
24 #-----------------------------------------------------------------------------
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' }
31 #-----------------------------------------------------------------------------
34 my ( $self, $elem, undef ) = @_;
36 my $child = $elem->schild(1);
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 );
52 #-----------------------------------------------------------------------------
58 Perl::Critic::Policy::Modules::RequireBarewordIncludes - Write C<require Module> instead of C<require 'Module.pm'>.
62 This Policy is part of the core L<Perl::Critic> distribution.
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
76 use 'My/Perl/Module.pm'; #not ok
77 use My::Perl::Module; #ok
82 This Policy is not configurable except for the standard options.
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.
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:
99 require $module_name; ## no critic
104 Chris Dolan <cdolan@cpan.org> was instrumental in identifying the
105 correct motivation for and behavior of this Policy. Thanks Chris.
109 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
111 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
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.
123 # cperl-indent-level: 4
125 # indent-tabs-mode: nil
126 # c-indentation-style: bsd
128 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :