in reply to Re: Filename of current package
in thread Filename of current package
Thanks for the pointer, but I'm still not able to find the filename of the package. I have played a little with caller(), but it seems to provide details of the calling program, rather than the included module?
Here is more what I am looking to do:
# my.pl use My::Factory; my $obj = My::Factory->new('Apple'); ... # My/Factory.pm package My::Factory; 1; sub new{ my $factoryclass = shift; my $class = "My::" . shift; # My::Apple my $filename = $class; $filename =~ s/::/\//g; $filename .= '.pm'; # My/Apple.pm if ( -e $filename ) { require $filename; } else { die "not found: $filename"; } }
Which all looks good and dandy, except that My::Factory is picked up from @INC at runtime. I thought that a package might know its own filename?
Note that I don't want to pick up My::Apple from somewhere else in @INC - I want it to be in the same place as My/Factory.pm
Apologies if that is not clear...
Off to see if I can figure out how Carp does it...
Regards
Jeff
|
|---|