Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: RFC: - 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: - 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