Fix perl use of 'use lib'

The 'use lib' logic happens in the pre-compile stage, so one cannot
use normal 'if' logic to use a particular INC.  Instead, just make sure
that best dir is added to 'use lib' last since it prepends to INC.
This commit is contained in:
Ben Greear
2020-03-04 16:35:47 -08:00
parent 45b4512ba2
commit d824eb2e66
25 changed files with 100 additions and 66 deletions

View File

@@ -17,13 +17,12 @@ package main;
# Un-buffer output # Un-buffer output
$| = 1; $| = 1;
# this is pedantic necessity for the following use statements
if ( $cwd =~ q(.*LANforge-Server\scripts$)) { # use lib prepends to @INC, so put lower priority first
use lib '/home/lanforge/scripts' # This is before run-time, so cannot condition this with normal 'if' logic.
} use lib '/home/lanforge/scripts';
else { use lib "./";
use lib '/home/lanforge/scripts';
}
use List::Util qw(first); use List::Util qw(first);
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Utils; use LANforge::Utils;

View File

@@ -9,12 +9,12 @@ if (defined $ENV{DEBUG}) {
} }
use Time::HiRes qw(usleep ualarm gettimeofday stat lstat utime); use Time::HiRes qw(usleep ualarm gettimeofday stat lstat utime);
#use Time::Format qw/%time/; #use Time::Format qw/%time/;
if ( -f "./LANforge/Utils.pm" ) {
use lib '.'; # use lib prepends to @INC, so put lower priority first
} # This is before run-time, so cannot condition this with normal 'if' logic.
elsif ( -f "/home/lanforge/scripts/LANforge/Utils.pm" ) { use lib '/home/lanforge/scripts';
use lib "/home/lanforge/scripts/LANforge"; use lib "./";
}
use LANforge::Utils; use LANforge::Utils;
use Net::Telnet (); use Net::Telnet ();
use Getopt::Long; use Getopt::Long;

View File

@@ -17,6 +17,8 @@ use LWP::UserAgent;
use Data::Dumper; use Data::Dumper;
use JSON; use JSON;
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "../";
use lib "./";
use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list); use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list);
package main; package main;

View File

@@ -16,6 +16,8 @@ use LWP::UserAgent;
use Data::Dumper; use Data::Dumper;
use JSON; use JSON;
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "../";
use lib "./";
use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names); use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names);
package main; package main;

View File

@@ -23,6 +23,8 @@ use Time::HiRes qw(usleep nanosleep);
use Proc::Background; use Proc::Background;
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "../";
use lib "./";
use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names); use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names);
package main; package main;

View File

@@ -17,6 +17,8 @@ use Data::Dumper;
use JSON; use JSON;
use Linux::Inotify2; use Linux::Inotify2;
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "../";
use lib "./";
use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names); use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names);
package main; package main;

View File

@@ -17,6 +17,8 @@ use Data::Dumper;
use Time::HiRes qw(usleep); use Time::HiRes qw(usleep);
use JSON; use JSON;
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "../";
use lib "./";
use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list); use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list);
package main; package main;
@@ -188,4 +190,4 @@ if ($action eq "annotate") {
json_post($post_uri, $rh); json_post($post_uri, $rh);
} }
} }
# #

View File

@@ -17,6 +17,8 @@ use Data::Dumper;
use Time::HiRes qw(usleep); use Time::HiRes qw(usleep);
use JSON; use JSON;
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "../";
use lib "./";
use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list); use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list);
package main; package main;

View File

@@ -17,6 +17,8 @@ use LWP::UserAgent;
use Data::Dumper; use Data::Dumper;
use JSON; use JSON;
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "../";
use lib "./";
use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list); use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list);
package main; package main;

View File

@@ -17,6 +17,8 @@ use LWP::UserAgent;
use Data::Dumper; use Data::Dumper;
use JSON; use JSON;
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "../";
use lib "./";
use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names); use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names);
package main; package main;

View File

@@ -17,6 +17,8 @@ use LWP::UserAgent;
use Data::Dumper; use Data::Dumper;
use JSON; use JSON;
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "../";
use lib "./";
use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list); use LANforge::JsonUtils qw(logg err json_request get_links_from get_thru json_post get_port_names flatten_list);
package main; package main;

View File

@@ -17,6 +17,8 @@ use LWP::UserAgent;
use Data::Dumper; use Data::Dumper;
use JSON; use JSON;
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "../";
use lib "./";
use LANforge::JsonUtils qw(err logg xpand json_request); use LANforge::JsonUtils qw(err logg xpand json_request);
@@ -57,4 +59,4 @@ for my $rh_e (@{$rh->{interfaces}}) {
sleep 0.1; sleep 0.1;
} }
# #

View File

@@ -14,12 +14,12 @@ $SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
$SIG{ __WARN__ } = sub { Carp::confess( @_ ) }; $SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
# Un-buffer output # Un-buffer output
$| = 1; $| = 1;
if (-f "LANforge/Endpoint.pm" ) {
use lib "./"; # use lib prepends to @INC, so put lower priority first
} # This is before run-time, so cannot condition this with normal 'if' logic.
else { use lib '/home/lanforge/scripts';
use lib '/home/lanforge/scripts'; use lib "./";
}
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;
use LANforge::Utils; use LANforge::Utils;

View File

@@ -10,12 +10,12 @@ use Data::Dumper;
# Un-buffer output # Un-buffer output
$| = 1; $| = 1;
if ( -f "LANforge/Endpoint.pm" ) {
use lib "./"; # use lib prepends to @INC, so put lower priority first
} # This is before run-time, so cannot condition this with normal 'if' logic.
else { use lib '/home/lanforge/scripts';
use lib '/home/lanforge/scripts'; use lib "./";
}
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;
use LANforge::Utils; use LANforge::Utils;

View File

@@ -74,13 +74,11 @@ $| = 1;
use Cwd qw(getcwd); use Cwd qw(getcwd);
my $cwd = getcwd(); my $cwd = getcwd();
# this is pedantic necessity for the following use statements # use lib prepends to @INC, so put lower priority first
if ( $cwd =~ q(.*LANforge-Server\scripts$)) { # This is before run-time, so cannot condition this with normal 'if' logic.
use lib '/home/lanforge/scripts' use lib '/home/lanforge/scripts';
} use lib "./";
else {
use lib '/home/lanforge/scripts';
}
use List::Util qw(first); use List::Util qw(first);
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;

View File

@@ -13,7 +13,12 @@ use Carp;
# Un-buffer output # Un-buffer output
$| = 1; $| = 1;
# use lib prepends to @INC, so put lower priority first
# This is before run-time, so cannot condition this with normal 'if' logic.
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "./";
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;
use LANforge::Utils; use LANforge::Utils;

View File

@@ -6,7 +6,12 @@ $SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
# Un-buffer output # Un-buffer output
$| = 1; $| = 1;
# use lib prepends to @INC, so put lower priority first
# This is before run-time, so cannot condition this with normal 'if' logic.
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "./";
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;
use LANforge::Utils; use LANforge::Utils;

View File

@@ -11,7 +11,12 @@ use warnings;
# Un-buffer output # Un-buffer output
$| = 1; $| = 1;
# use lib prepends to @INC, so put lower priority first
# This is before run-time, so cannot condition this with normal 'if' logic.
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "./";
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;
use LANforge::Utils; use LANforge::Utils;

View File

@@ -15,12 +15,12 @@ $SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
# Un-buffer output # Un-buffer output
$| = 1; $| = 1;
if (-f "LANforge/Endpoint.pm" ) {
use lib "./"; # use lib prepends to @INC, so put lower priority first
} # This is before run-time, so cannot condition this with normal 'if' logic.
else { use lib '/home/lanforge/scripts';
use lib '/home/lanforge/scripts'; use lib "./";
}
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;
use LANforge::Utils; use LANforge::Utils;

View File

@@ -33,7 +33,12 @@ $SIG{ __WARN__ } = sub { Carp::confess( @_ )};
use Getopt::Long; use Getopt::Long;
use Cwd qw(getcwd); use Cwd qw(getcwd);
my $cwd = getcwd(); my $cwd = getcwd();
# use lib prepends to @INC, so put lower priority first
# This is before run-time, so cannot condition this with normal 'if' logic.
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "./";
use List::Util qw(first); use List::Util qw(first);
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;

View File

@@ -16,14 +16,11 @@ $SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
# Un-buffer output # Un-buffer output
$| = 1; $| = 1;
if ( -d "./LANforge" ) { # use lib prepends to @INC, so put lower priority first
use lib "."; # This is before run-time, so cannot condition this with normal 'if' logic.
use lib "./LANforge"; use lib '/home/lanforge/scripts';
} use lib "./";
elsif ( -d "/home/lanforge/scripts/LANforge") {
use lib "/home/lanforge/scripts";
use lib "/home/lanforge/scripts/LANforge";
}
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;
use LANforge::Utils; use LANforge::Utils;

View File

@@ -19,14 +19,10 @@ our $Q = q(");
# Un-buffer output # Un-buffer output
$| = 1; $| = 1;
if ( -d "./LANforge" ) { # use lib prepends to @INC, so put lower priority first
use lib "."; # This is before run-time, so cannot condition this with normal 'if' logic.
use lib "./LANforge"; use lib '/home/lanforge/scripts';
} use lib "./";
elsif ( -d "/home/lanforge/scripts/LANforge" ) {
use lib "/home/lanforge/scripts";
use lib "/home/lanforge/scripts/LANforge";
}
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;

View File

@@ -11,7 +11,12 @@ use strict;
use warnings; use warnings;
use Carp; use Carp;
$| = 1;# Un-buffer output $| = 1;# Un-buffer output
# use lib prepends to @INC, so put lower priority first
# This is before run-time, so cannot condition this with normal 'if' logic.
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "./";
use Getopt::Long; use Getopt::Long;
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;

View File

@@ -23,7 +23,11 @@ use diagnostics;
# Un-buffer output # Un-buffer output
$| = 1; $| = 1;
# use lib prepends to @INC, so put lower priority first
# This is before run-time, so cannot condition this with normal 'if' logic.
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';
use lib "./";
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;
use LANforge::Utils; use LANforge::Utils;

View File

@@ -32,16 +32,11 @@ $| = 1;
use Cwd qw(getcwd); use Cwd qw(getcwd);
my $cwd = getcwd(); my $cwd = getcwd();
# this is pedantic necessity for the following use statements # use lib prepends to @INC, so put lower priority first
if ( -f "LANforge/Endpoint.pm" ) { # This is before run-time, so cannot condition this with normal 'if' logic.
use lib "./"; use lib '/home/lanforge/scripts';
} use lib "./";
elsif ( $cwd =~ q(.*LANforge-Server\scripts$)) {
use lib '/home/lanforge/scripts'
}
else {
use lib '/home/lanforge/scripts';
}
use LANforge::Endpoint; use LANforge::Endpoint;
use LANforge::Port; use LANforge::Port;
use LANforge::Utils; use LANforge::Utils;