YuckFoo has asked for the wisdom of the Perl Monks concerning the following question:
use Local::Some::Real::Cool::Module; $this = Local::Some::Real::Cool::Module->new(); $that = Local::Some::Real::Cool::Module->new(); $more = Local::Some::Real::Cool::Module->new();
Sometime ago I learned I could set a string to the module name and use it instead:
use Local::Some::Real::Cool::Module; $gimme = 'Local::Some::Real::Cool::Module'; $this = $gimme->new(); $that = $gimme->new(); $more = $gimme->new();
That is better, but still kinda sucks. So I try to have the module return its own name and get it that way, but of course the return of use can't be used:
# Nope $gimme = use Local::Some::Real::Cool::Module;
Maybe the return of require can be used to grab the module name? Yes it can. But will I be sorry if I do? Any other suggestions?
#!/usr/bin/perl my $gimme = require Local::Some::Real::Cool::Module; import $gimme qw(some import stuff here); my $this = $gimme->new(); my $that = $gimme->new(); my $more = $gimme->new(); #----------------------------------------------------------- # Local/Some/Real/Cool/Module.pm #----------------------------------------------------------- package Local::Some::Real::Cool::Module; sub import { # . . . } sub new { return bless {}, shift; } 'Local::Some::Real::Cool::Module';
YuckUse
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use, require, and constructors
by fglock (Vicar) on Oct 26, 2004 at 22:40 UTC | |
|
Re: use, require, and constructors (factories++)
by tye (Sage) on Oct 27, 2004 at 02:50 UTC | |
by ysth (Canon) on Oct 27, 2004 at 06:23 UTC | |
by tye (Sage) on Oct 27, 2004 at 15:25 UTC | |
by ysth (Canon) on Oct 27, 2004 at 17:53 UTC | |
|
Re: use, require, and constructors
by PodMaster (Abbot) on Oct 26, 2004 at 23:21 UTC | |
|
Re: use, require, and constructors
by Duco (Sexton) on Oct 27, 2004 at 22:14 UTC |