Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.>


In reply to Problem with conditional module load by pgduke65

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (4)
    As of 2020-03-28 09:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      To "Disagree to disagree" means to:









      Results (167 votes). Check out past polls.

      Notices?