in reply to Re^2: "use" modules inside modules
in thread "use" modules inside modules
Here we see the (among others):"Main program" #!/usr/bin/perl -w ... # docu and version info -- skipped use strict; use FileHandle; use File::stat; use Getopt::Long; use POSIX ":sys_wait_h"; use POSIX qw(ceil); use Socket; #===================================================================== +========= #== Find the lib dir use 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 Net::TFTP; use Net::SNMP::Security::USM v3.0.0; use IsamCli; use Isam7354RUCli; use Crypt::Lite; use Utils; # -- BB -- use Octopus; use Capability; use ToolCommon qw(:CONSTANTS); use PbmtConfig; use ErrorCodes qw(:EXIT_CODES :SWDL); use FamilyCommon; ....
This is the Octopus.pm module (at least a the beginning):use Octopus; use Capability;
So here again we have the usage of the module Capability because this module contains functions that logically belong there (it is a module having capabilities of elements it is dealing with). Now we turn to the Capability module. Half of this module is data (intented to be static). The rest of the module are accessor functions to access the data elements to prevent "direct" usage of the hashes defined inside but rather retrieve the data through the accessor functions. We are not using the Exporter (I tried it but it made no difference).package Octopus; use strict; 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"); } require Utils; require Capability; use ErrorCodes qw(:EXIT_CODES); use ToolCommon qw(:CONSTANTS); require ReduceSWP; ...
The problem I have is occuring on this hash. To determine the presence of an element I use the statementpackage Capability; use strict; use 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"); } use IsamCli; use ToolCommon qw(:CONSTANTS); use ErrorCodes qw(:EXIT_CODES); #===================================================================== +========= #== Prototypes #===================================================================== +========= sub GetVersion(); sub GetError(); ... my %ntCapabilities = ('EANT-A' => {'SW_PAR' => undef}, 'EBNT-A' => {'SW_PAR' => undef}, 'ECNT-A' => {'SW_PAR' => $ECNTA_MINSWPARSIZE, 'PREFIX' => {'ALL' => 'L5YY'}, 'BRDCODE' => 12355, 'SAFE_ICS' => 13, 'SHUB_TYPE' => 'ECNTA', 'EQPT_TYPE' => $XD, 'IF_BASE' => $OTHER_IFBASE, 'FAMILY' => {'ALL' => $ISAM, '400 410' => $ISAM_ANSI}, 'NO_UPG' => {'240' => [$IMPOSSIBLE, $FTP_ISSUE], '241' => ['248 249 244 246', $INCOMP_RELSTREAM +], '242' => ['248 249 244 246', $INCOMP_RELSTREAM +]}, 'NO_MIG' => {'117' => [$IMPOSSIBLE, 'No migration possible from this release +'], # No migrations for this release '233' => ['241 242 243 248 249 244 246 250', 'Feature incompatibilty w.r.t. pppoe rel +ay tagging'], # No migrations due to pppoe relay tags of 2.3.03 '240' => [$IMPOSSIBLE, 'No upgrade possible due to file transfe +r problem'], '241' => ['248 249 244 246 300', $INCOMP_RELST +REAM], '242' => ['248 249 244 246 300', $INCOMP_RELST +REAM], '244' => ['250 300 310 320', $INCOMP_RELSTREAM +], '245' => ['250', $NO_MIG_PATH ], '246' => ['250 300 310 320', $INCOMP_RELSTREAM +], '248' => ['250', $INCOMP_RELSTREAM], '249' => ['250', $INCOMP_RELSTREAM], '250' => ['300', $INCOMP_RELSTREAM]}, 'MIG_EXCLUDED_TO' => {$ISAM => "330 340 400"} }, .... );
When I remove the call require Capability.pm from Octopus.pm and replace the function call by the code executed by the function the program is running fine, if the require statement is present and I use the accessor function, the program fails for exactly the same element that was OK when the require was removed. It is the intention that the data hash remains "local" to Capability.pm. I hope this is sufficient code allowing a "judgement".defined($ntCapabilities{$type}{'SW_PAR'}).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: "use" modules inside modules
by ikegami (Patriarch) on Jun 29, 2009 at 01:03 UTC | |
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 | |
|
Re^4: "use" modules inside modules
by ELISHEVA (Prior) on Jun 28, 2009 at 19:14 UTC | |
by Bloodnok (Vicar) on Jun 28, 2009 at 20:17 UTC | |
by bogaertb (Novice) on Jun 29, 2009 at 14:15 UTC | |
by Anonymous Monk on Jun 29, 2009 at 06:16 UTC | |
by Anonymous Monk on Jun 29, 2009 at 06:36 UTC | |
by bogaertb (Novice) on Jun 29, 2009 at 07:32 UTC |