Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: RFC: new.pm - a perl -e use/new shortener (class name)

by tye (Sage)
on Dec 24, 2016 at 18:00 UTC ( [id://1178471]=note: print w/replies, xml ) Need Help??


in reply to RFC: new.pm - a perl -e use/new shortener

I'd much rather have a good way to get the class name into a variable so that I can use it for more than one call to new() and to use in calls to other class methods. The effect is to allow the programmer to use a variable as an alias for the long class name. Using a variable is nice because it provides the ability to define the scope for which you want that alias to apply. Having the helper module import a variable thwarts the ability to chose the scope and also makes the code less obvious when being read.

my $log = require 'Log::Logger::Log4Perl::SysLog';

The above even "works" if your module ends with "__PACKAGE__" instead of ending with "1"... except that it then only works for the first time a particular module is required. It would be good if there were an INC global in Perl that cached the value returned from the first call to require so that subsequent calls returned the same value.

At the very least, improve your module so that the variable name is passed to it as '$x' instead of as 'x' so the meaning of the code becomes slightly more obvious.

- tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178471]
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: (4)
As of 2024-04-19 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found