in reply to Want to create a common Perl module

Something like this might work in principle:

package abc; use strict; use warnings; use File::Path (); ... sub import { my $caller = caller(); strict->import(); warnings->import(); { eval "package $caller; File::Path->import('mkpath');" } ... } 1;

One of the problems is that Exporter, from which many modules inherit the import() method, uses caller to determine where to export to... That's the reason for the eval, because the calling package that you have to mimic for this in abc's import() will only be known at runtime.

Replies are listed 'Best First'.
Re^2: Want to create a common Perl module
by pankaj41483 (Initiate) on Jun 28, 2010 at 14:33 UTC
    I just tested. it is not working. gives error "Undefined subroutine &main::InitializeLog called at .....".
    I also tried a module named ToolSet for the same. but when i run it gives me error.
    "Base class package "ToolSet" is empty. (Perhaps you need to 'use' the module which defines that package first.)".

      Could you show the exact code that you've written for abc.pm?  Which module is InitializeLog supposed to be imported from?

        package abc;
        use strict;
        use myCustom::SysLogLoader;
        use myCustom::amodule;
        use myCustom:firstmod;
        use File::Path 'mkpath'; # for mkdir
        #use warnings;
        use integer;
        use File::Basename;
        use File::Copy; # for move
        use IO::Zlib; # to read gzip input files use IO::File; # to read non gzip input files use Text::Trim; use Data::Types qw(is_int is_string);
        use Shell qw (cat);
        use Sys::Hostname;
        use Time::Local;
        #our @ISA = qw(Exporter);
        sub import {
        my $caller =caller();
        strict->import();
        warning->import();
        MyCustom ::amodule ->import();
        myCustom:: firstmod->import();
        myCustom ::SysLogLoader->import();

        now i am using this package abc into my other myplscript.pl file. then it gives me this error.