Rudif has asked for the wisdom of the Perl Monks concerning the following question:
#! perl -w # file h:/devperl/perlmonks/Test/ModDir.pm package Test::ModDir; use strict; use File::Basename; sub new { my ($class, %args) = @_; my $self = {}; bless $self, $class; return $self; } sub moduleDir { my $self = shift; my $class = ref $self; # "ModuleDir::ModDir" (my $moduleFile = "$class.pm") =~ s!::!/!; my $modulePath = $INC{$moduleFile}; # print "module $_ from file $INC{$_}\n" foreach keys %INC; my $moduleDir = dirname $modulePath; } 1; __END__ #! perl -w # file h:/devperl/perlmonks/TestModuleDir.pm use strict; use lib qw ( h:/devperl/perlmonks ); use Test::ModDir; my $md = Test::ModDir->new; printf "===%s===\n", $md->moduleDir; ### prints ===h:/devperl/perlmonks/Test=== __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I get the name of the file from which the class was loaded?
by merlyn (Sage) on Oct 23, 2000 at 01:07 UTC | |
by Rudif (Hermit) on Oct 23, 2000 at 15:55 UTC | |
by merlyn (Sage) on Oct 23, 2000 at 16:00 UTC | |
by Rudif (Hermit) on Oct 24, 2000 at 00:41 UTC | |
|
RE: How do I get the name of the file from which the class was loaded?
by Adam (Vicar) on Oct 23, 2000 at 22:40 UTC |