require '/path/to/some/script.pl';
with
use lib '/path/to/some'; require 'script.pl';
and I was able to run some of the scripts locally (I had to add some paths to @INC).
After several days, we noticed some of the scripts failed. I inspected the code and discovered that there was one newer OO module that was written "correctly": it lived in a .pm file and declared a package. It used lib and only required the script names.
Combining "right" and "wrong" led to "even worse": The OO module required several .pl files. All the subroutines they declared were therefore created in the namespace of the module. Later, when a calling script required the same .pl file, it already existed in %INC, so it was not read again. No import was called anywhere, so the subroutines did not appear in the main:: package.
Here are sample files so you can try it yourself:
package module; use warnings; use strict; require 'required1.pl'; subroutine(); warn 'module INC: ', $INC{'required1.pl'}; __PACKAGE__
#!/usr/bin/perl use warnings; use strict; warn "Loading 1"; sub subroutine { my $file = (caller)[1]; $file =~ s=.*/==; warn 'subroutine defined in ', $file; } subroutine(); 1;
#!/usr/bin/perl use warnings; use strict; use FindBin; use lib $FindBin::Bin; require 'required1.pl'; use module; warn 'script INC ', $INC{'required1.pl'}; subroutine();
Update:
We now have 2 options:
Update2:
I just had an idea: there is a third option. In the OO module, store %INC at the beginning, do all you need, then set %INC back to what it was.
my %_INC = %INC; # ... %INC = %_INC;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Wrong + Right = Even Worse
by davido (Cardinal) on Apr 03, 2014 at 15:52 UTC | |
|
Re: Wrong + Right = Even Worse
by locked_user sundialsvc4 (Abbot) on Apr 03, 2014 at 14:24 UTC | |
|
Re: Wrong + Right = Even Worse
by LanX (Saint) on Apr 03, 2014 at 22:44 UTC | |
|
Re: Wrong + Right = Even Worse (do)
by tye (Sage) on Apr 04, 2014 at 06:17 UTC | |
by choroba (Cardinal) on Apr 04, 2014 at 07:34 UTC | |
by tye (Sage) on Apr 04, 2014 at 13:45 UTC | |
by choroba (Cardinal) on Apr 04, 2014 at 14:58 UTC | |
|
Re: Wrong + Right = Even Worse
by tobyink (Canon) on Apr 03, 2014 at 22:01 UTC | |
by choroba (Cardinal) on Apr 03, 2014 at 22:20 UTC | |
by tobyink (Canon) on Apr 03, 2014 at 22:41 UTC | |
by choroba (Cardinal) on Apr 03, 2014 at 22:44 UTC | |
|
Re: Wrong + Right = Even Worse
by LanX (Saint) on Apr 03, 2014 at 23:37 UTC | |
|
Re: Wrong + Right = Even Worse
by LanX (Saint) on Apr 04, 2014 at 14:45 UTC | |
by tye (Sage) on Apr 04, 2014 at 15:52 UTC | |
by LanX (Saint) on Apr 04, 2014 at 16:08 UTC | |
|
Re: Wrong + Right = Even Worse
by locked_user sundialsvc4 (Abbot) on Apr 04, 2014 at 13:46 UTC |