in reply to Re^3: "use" modules inside modules
in thread "use" modules inside modules
First, let's simplify your code a bit.
In the .pl file, replace
withuse Cwd; use File::Basename; BEGIN { my $dir = dirname($0); my $path; if ($dir =~ /^\//) { #--absolute path $path = $dir; } elsif ($dir eq ".") { #-- relative, current dir $path = getcwd(); } else { #-- relative, but not from current dir $dir =~ s/^\.\///; $path = getcwd()."/$dir"; } unshift(@INC, "$path/lib"); unshift(@INC, "$path/lib-perl"); unshift(@INC, "$path/lib-perl/sun4-solaris-64int"); }
use Cwd qw( realpath ); use File::Basename; my $script_dir; BEGIN { $script_dir = dirname(realpath($0)); } use lib "$script_dir/lib", "$script_dir/lib-perl";
In the .pm files, remove the following
use File::Basename; use Cwd; BEGIN { my $dir = dirname($0); my $path; if ($dir =~ /^\//) { #--absolute path $path = $dir; } elsif ($dir eq ".") { #-- relative, current dir $path = getcwd(); } else { #-- relative, but not from current dir $dir =~ s/^\.\///; $path = getcwd()."/$dir"; } unshift(@INC, "$path/lib"); unshift(@INC, "$path/lib-perl"); }
It makes no sense to tell perl where to find the library after it's already been found!
Now on to your question.
To determine the presence of an element I use the statement defined($ntCapabilities{$type}{'SW_PAR'}).
From where? The .pl file? There is no such variable there. You would have to export %ntCapabilities in order to do that (and roll out your own import since no module will help you export a lexical variable).
But since exporting variables (as oppose to functions) is rather fishy, it would be better to create an accessor (sub is_capable?) and export the accessor from Capability or use its full name.
if (Capability::is_capable(...)) { ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: "use" modules inside modules
by Anonymous Monk on Jun 29, 2009 at 06:10 UTC | |
by ikegami (Patriarch) on Jun 29, 2009 at 14:14 UTC | |
by bogaertb (Novice) on Jul 03, 2009 at 06:15 UTC | |
by ikegami (Patriarch) on Jul 03, 2009 at 17:28 UTC |