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
$| = 1;
# this is pedantic necessity for the following use statements
if ( $cwd =~ q(.*LANforge-Server\scripts$)) {
use lib '/home/lanforge/scripts'
}
else {
use lib '/home/lanforge/scripts';
}
# 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 "./";
use List::Util qw(first);
use LANforge::Endpoint;
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::Format qw/%time/;
if ( -f "./LANforge/Utils.pm" ) {
use lib '.';
}
elsif ( -f "/home/lanforge/scripts/LANforge/Utils.pm" ) {
use lib "/home/lanforge/scripts/LANforge";
}
# 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 "./";
use LANforge::Utils;
use Net::Telnet ();
use Getopt::Long;

View File

@@ -17,6 +17,8 @@ use LWP::UserAgent;
use Data::Dumper;
use JSON;
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);
package main;

View File

@@ -16,6 +16,8 @@ use LWP::UserAgent;
use Data::Dumper;
use JSON;
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);
package main;

View File

@@ -23,6 +23,8 @@ use Time::HiRes qw(usleep nanosleep);
use Proc::Background;
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);
package main;

View File

@@ -17,6 +17,8 @@ use Data::Dumper;
use JSON;
use Linux::Inotify2;
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);
package main;

View File

@@ -17,6 +17,8 @@ use Data::Dumper;
use Time::HiRes qw(usleep);
use JSON;
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);
package main;
@@ -188,4 +190,4 @@ if ($action eq "annotate") {
json_post($post_uri, $rh);
}
}
#
#

View File

@@ -17,6 +17,8 @@ use Data::Dumper;
use Time::HiRes qw(usleep);
use JSON;
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);
package main;

View File

@@ -17,6 +17,8 @@ use LWP::UserAgent;
use Data::Dumper;
use JSON;
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);
package main;

View File

@@ -17,6 +17,8 @@ use LWP::UserAgent;
use Data::Dumper;
use JSON;
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);
package main;

View File

@@ -17,6 +17,8 @@ use LWP::UserAgent;
use Data::Dumper;
use JSON;
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);
package main;

View File

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

View File

@@ -14,12 +14,12 @@ $SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
$SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
# Un-buffer output
$| = 1;
if (-f "LANforge/Endpoint.pm" ) {
use lib "./";
}
else {
use lib '/home/lanforge/scripts';
}
# 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 "./";
use LANforge::Endpoint;
use LANforge::Port;
use LANforge::Utils;

View File

@@ -10,12 +10,12 @@ use Data::Dumper;
# Un-buffer output
$| = 1;
if ( -f "LANforge/Endpoint.pm" ) {
use lib "./";
}
else {
use lib '/home/lanforge/scripts';
}
# 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 "./";
use LANforge::Endpoint;
use LANforge::Port;
use LANforge::Utils;

View File

@@ -74,13 +74,11 @@ $| = 1;
use Cwd qw(getcwd);
my $cwd = getcwd();
# this is pedantic necessity for the following use statements
if ( $cwd =~ q(.*LANforge-Server\scripts$)) {
use lib '/home/lanforge/scripts'
}
else {
use lib '/home/lanforge/scripts';
}
# 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 "./";
use List::Util qw(first);
use LANforge::Endpoint;
use LANforge::Port;

View File

@@ -13,7 +13,12 @@ use Carp;
# Un-buffer output
$| = 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 "./";
use LANforge::Endpoint;
use LANforge::Port;
use LANforge::Utils;

View File

@@ -6,7 +6,12 @@ $SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
# Un-buffer output
$| = 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 "./";
use LANforge::Endpoint;
use LANforge::Port;
use LANforge::Utils;

View File

@@ -11,7 +11,12 @@ use warnings;
# Un-buffer output
$| = 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 "./";
use LANforge::Endpoint;
use LANforge::Port;
use LANforge::Utils;

View File

@@ -15,12 +15,12 @@ $SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
# Un-buffer output
$| = 1;
if (-f "LANforge/Endpoint.pm" ) {
use lib "./";
}
else {
use lib '/home/lanforge/scripts';
}
# 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 "./";
use LANforge::Endpoint;
use LANforge::Port;
use LANforge::Utils;

View File

@@ -33,7 +33,12 @@ $SIG{ __WARN__ } = sub { Carp::confess( @_ )};
use Getopt::Long;
use Cwd qw(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 "./";
use List::Util qw(first);
use LANforge::Endpoint;
use LANforge::Port;

View File

@@ -16,14 +16,11 @@ $SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
# Un-buffer output
$| = 1;
if ( -d "./LANforge" ) {
use lib ".";
use lib "./LANforge";
}
elsif ( -d "/home/lanforge/scripts/LANforge") {
use lib "/home/lanforge/scripts";
use lib "/home/lanforge/scripts/LANforge";
}
# 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 "./";
use LANforge::Endpoint;
use LANforge::Port;
use LANforge::Utils;

View File

@@ -19,14 +19,10 @@ our $Q = q(");
# Un-buffer output
$| = 1;
if ( -d "./LANforge" ) {
use lib ".";
use lib "./LANforge";
}
elsif ( -d "/home/lanforge/scripts/LANforge" ) {
use lib "/home/lanforge/scripts";
use lib "/home/lanforge/scripts/LANforge";
}
# 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 "./";
use LANforge::Endpoint;
use LANforge::Port;

View File

@@ -11,7 +11,12 @@ use strict;
use warnings;
use Carp;
$| = 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 "./";
use Getopt::Long;
use LANforge::Endpoint;
use LANforge::Port;

View File

@@ -23,7 +23,11 @@ use diagnostics;
# Un-buffer output
$| = 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 "./";
use LANforge::Endpoint;
use LANforge::Port;
use LANforge::Utils;

View File

@@ -32,16 +32,11 @@ $| = 1;
use Cwd qw(getcwd);
my $cwd = getcwd();
# this is pedantic necessity for the following use statements
if ( -f "LANforge/Endpoint.pm" ) {
use lib "./";
}
elsif ( $cwd =~ q(.*LANforge-Server\scripts$)) {
use lib '/home/lanforge/scripts'
}
else {
use lib '/home/lanforge/scripts';
}
# 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 "./";
use LANforge::Endpoint;
use LANforge::Port;
use LANforge::Utils;