in reply to Re: Re: Perlish dice for gamers (oh, and importing autoloaded functions)
in thread Perlish dice for gamers (oh, and importing autoloaded functions)
my $meth = \sub {"__PACKAGE__::$dice"};Ya know, i stared at that for about 20 minutes trying to figure out why it worked. It seemed to me that all the first line should do is create an anonymous sub that returns "__PACKAGE__::$dice" ... so i did some digging, and sure enough that *IS* all it does.
*{$pkg . '::' . $dice} = $meth;
I don't know what you and I have been doing wrong with our attempts at putting things in the package's symbol table, but evidently none of it was doing anything (at least: not anything that affected what we were testing).
It turns out that THIS is all you need to import an AUTOLOADed method...
sub import { my $pkg = shift; @EXPORT_OK = @_; __PACKAGE__->export_to_level(1, $pkg, @_); }
But for the sake of correctness, it should probably only copy things into @EXPORT_OK that match the regexp -- that way writting "use Smonk qw(r3d3 foo)" will generate...
"foo" is not exported by the Smonk module at monk.pl line 4 Can't continue after import errors at monk.pl line 4 BEGIN failed--compilation aborted at monk.pl line 4.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Perlish dice for gamers (oh, and importing autoloaded functions)
by Solo (Deacon) on Sep 10, 2002 at 13:31 UTC |