[plug] Perl Question

Ryan ryan at is.as.geeky.as
Tue Mar 9 00:02:28 WST 2004


On Mon, 2004-03-08 at 16:04, /me wrote:

> This will tell you what is loaded:
> 
> my $key;
> 
> foreach $key (sort keys(%INC)) {
>    print "$key => $INC{$key}\n";
> }
> 
> For example if you made module.pm and use/require it, you'll get:
> 
> module.pm => /some/path/module.pm
> 
> Can you grep the hash for your $foo thing and see if it is 
> already loaded and go from there?
> 
> If it IS loaded and you want to call it, you can do some dodgy
> reference that I forget how to do, the idea of which is do
> to something like this:  &$foo::baa() (but I'm almost positive
> that is wrong and I can't test it right now) :)
> 
> Check on perlmonks, that will find it for you pretty quick.

Okay home now, I'll do it for you then :)

blah.pl
-------
#!/usr/bin/perl
use module;
$foo = $ARGV[0];
&{$foo.'::function'}() if grep {/^$foo\.pm/} keys(%INC);

module.pm
---------
package module;
sub function {
    print "module::function\n";
}
1;

testing it
----------
ryan at devel:/tmp$ ./blah.pl
ryan at devel:/tmp$ ./blah.pl bar
ryan at devel:/tmp$ ./blah.pl module
module::function
ryan at devel:/tmp$


Is that what you wanted?

Ryan





More information about the plug mailing list