in reply to use, require, and constructors
Unfortunately, require will only return that value the first time you require the module, so you really shouldn't use this.
It would be nice if require and/or use would return a factory (by default, just the class name). It probably wouldn't be hard to fix require (patch Perl) since it nearly works already. And in the chatterbox Larry said that Perl6's use will return a factory (at least that was how I understood it).
In modern Perl, the closest I can come to this is initializing a factory variable. You'd use the OO module like:
use Disney::Animation::Animal::Mouse::WithGloves( \my $Mickey ); # ... my $logo= $Mickey->new( "Smiling" );
The OO module would have something like:
sub import { my( $us, $ref )= @_; $$ref= $us if ref($ref); }
Just as one example of how you could do it.
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: use, require, and constructors (factories++)
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 |