DreamT has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I have used stubmaker.pl to successfully generate a pm file (service.pm) , that I use in a calling script (caller.pl) to connect to a webservice.

eval {use AdminService qw (:all); };

In itself, this works without problems. But, caller.pl is sometimes included in other pl-scripts in different locations. This becomes a problem because caller.pl sometimes doesn't know where to find service.pm.
. I have tried to use
use Cwd; my $dir = getcwd; use lib $dir."/mysubdirectory";
to "find out" the search path, but since getcwd gets the path from the source script (that in turn includes caller.pl), this fails for all scripts that resides in another directory.

To solve the problem, I see two possible solutions:
1. Include the code in service.pm in caller.pl.
2. Find a failsafe way to find out the path to service.pm.

Number 1 is preferred due to distribution reasons.

Regarding number 2, I could surely enter the path manually, but the software is supposed to work "out-of-the-box" in different configurations.

Replies are listed 'Best First'.
Re: Include stubmaker-generated pm file in calling script!
by Anonymous Monk on Apr 28, 2010 at 19:26 UTC
    eval {use AdminService qw (:all); };

    use happens at compile time, not at run time . For that to work you would have to write

    BEGIN { eval { require AdminService; AdminService->import(':all'); }

    my $dir = getcwd; use lib $dir."/mysubdirectory";...

    If cwd were what you wanted

    use File::Spec; use Cwd(); use lib File::Spec->catfile( Cwd::cwd(), 'mysubdirectory' );
    but cwd isn't what you want, you want
    File::Spec->catfile( File::Basename::dirname( File::Spec->rel2abs(__FI +LE__) ), 'mysubdirectory' )
    Regarding number 2, I could surely enter the path manually, but the software is supposed to work "out-of-the-box" in different configurations.

    That is accomplished is by installing the module and program, like Pod::Perldoc and perldoc

      Ok, thank you for your reply! But I also want to know if alt. 1 is possible?

      I.e, can I take the contents from service.pm and put it in caller.pl?