pgduke65 has asked for the wisdom of the Perl Monks concerning the following question:
I am obviously missing something simnple here. But I cannot seem to find it. Please help me to understand what I am doing incorrectly.
The Goal: Write a module that will conditionally include other modules as needed based on the current o/s.
Idea calling script includes Module Security. Module Security then includes either Windows module or Unix module depending on the $^O variable value.
I have searched here and googled and have tried the following:,
Test Calling Script
use strict; use warnings; use lib 'C:/Perl'; use SecurityV1; printf "Hello World\n";
Security Module Code
package SecurityV1; BEGIN { my $LoadModule = ($^O ne 'MSWin32') ? 'UnixSecurity' : 'Win32Secur +ity'; eval "require $LoadModule; 1;" or die $@ if $LoadModule; $LoadModule->import(); } use strict; use warnings; use constant { TRUE => 1, FALSE => 0 }; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK ); our $VERSION = 1.00; our @ISA = qw(Exporter); @EXPORT = qw(); @EXPORT_OK = qw(); Test(); 1;
Win32Security Module
package SecurityWin32; use strict; use warnings; use constant { TRUE => 1, FALSE => 0 }; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK ); our $VERSION = 1.00; our @ISA = qw(Exporter); @EXPORT = qw(Test); @EXPORT_OK = qw(); sub Test { printf "Loading %s\n", __PACKAGE__; } 1;
UnixSecurity Module
package SecurityUnix; use strict; use warnings; use constant { TRUE => 1, FALSE => 0 }; printf "Loading %s\n", __PACKAGE__; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK ); our $VERSION = 1.00; our @ISA = qw(Exporter); @EXPORT = qw(Test); @EXPORT_OK = qw(); sub Test { printf "Loading %s\n", __PACKAGE__; } 1;
The Error:
Can't locate Win32Security.pm in @INC (you may need to install the Win32Security module) (@INC contains: C:/Perl C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib .) at (eval 1) line 1. BEGIN failed--compilation aborted at C:/Perl/SecurityV1.pm line 38. Compilation failed in require at C:\Perl\TestLoad.pl line 5. BEGIN failed--compilation aborted at C:\Perl\TestLoad.pl line 5. C:\Perl>
The C:\Perl Directory contains all modules and the calling script.>