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
In reply to Re: use, require, and constructors (factories++)
by tye
in thread use, require, and constructors
by YuckFoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |