ryo0ka has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks, I have a weird question.
My String module has a hash reference:
and has an AUTOLOAD subroutine:$reg = { url => qr[^http://], };
so I can use "is_**" subroutine and add new regix whenever I want, for example, I add like:sub AUTOLOAD { our $AUTOLOAD; my $arg = shift; if ($AUTOLOAD =~ /^is_/) { my $key = substr $AUTOLOAD, 3; my $val = $reg->{$val}; return 1 if $arg =~ /$val/; } }
so I can use "is_file" subroutine.$reg = { url => qr[^http://], file => qr[^[a-Z]:/], };
Then, to avoid typing String::is_url($str) but just is_url($str) on another file, I want to export "is***" subroutine by using Export.
To do so, I added this code:
But it does not load AUTOLOADed subroutine "is_**" because it will be loaded when it's called.use Export; our @EXPORT = do { no strict 'refs'; grep {*$_{CODE}} keys %Str::; };
Are there any way to call "is_***" without "String::" from another module?
Thanks in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to export un-exist subroutines
by Corion (Patriarch) on May 26, 2013 at 15:29 UTC | |
|
Re: How to export un-exist subroutines
by tobyink (Canon) on May 26, 2013 at 18:45 UTC | |
by ryo0ka (Novice) on May 26, 2013 at 20:21 UTC |