Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: What's the right way to include a config file as a .pm bareword?

by Anonymous Monk
on Aug 07, 2015 at 10:28 UTC ( [id://1137825]=note: print w/replies, xml ) Need Help??


in reply to What's the right way to include a config file as a .pm bareword?

PerlCritic rules are sometimes just good suggestions, and often the experienced programmer will know better.

$ perlcritic --verbose 11 foo.pl "require" statement with library name as string at line 6, near 'requi +re '/tmp/config.pl';'. Modules::RequireBarewordIncludes (Severity: 5) When including another module (or library) via the `require' or `u +se' statements, it is best to identify the module (or library) using a bareword rather than an explicit path. This is because paths are u +sually not portable from one machine to another. Also, Perl automatically assumes that the filename ends in '.pm' when the library is expres +sed as a bareword. So as a side-effect, this Policy encourages people to +write '*.pm' modules instead of the old-school '*.pl' libraries. use 'My/Perl/Module.pm'; #not ok use My::Perl::Module; #ok

So this means the rule exists because its author(s) were worried that people are writing Perl-4-style libraries. Since in this case you know better and config.pl is not a library, you are free to overrule PerlCritic:

require '/tmp/config.pl'; ## no critic (RequireBarewordIncludes)

Of course there are other ways to "fix" the issue, e.g. to use do or even eval (but require is fine). Also, you could just turn config.pl into MyConfig.pm and make things easier that way too.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1137825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-24 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found