From 981383c30777f737e86d8d648a7de68961134048 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 24 Feb 2013 21:14:53 +0000 Subject: [PATCH] Use Path::Class for path and file name construction consistently --- Netdisco/Changes | 1 + Netdisco/bin/netdisco-daemon | 7 ++++--- Netdisco/bin/netdisco-deploy | 3 ++- Netdisco/bin/netdisco-web | 8 ++++---- Netdisco/lib/App/Netdisco/Util/Connect.pm | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index ea3ebb6b..1c271fd1 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -5,6 +5,7 @@ * random() and LIMIT the number of daemon jobs requested from Netdisco queue * Remove Daemon's job queue DBIC schema from user config * Add log messages to the Daemon + * Use Path::Class for path and file name construction consistently 2.005000_002 - 2013-02-10 diff --git a/Netdisco/bin/netdisco-daemon b/Netdisco/bin/netdisco-daemon index 274b410e..e85bd003 100755 --- a/Netdisco/bin/netdisco-daemon +++ b/Netdisco/bin/netdisco-daemon @@ -2,11 +2,12 @@ use strict; use warnings FATAL => 'all'; +use Path::Class 'file'; BEGIN { eval "use Daemon::Control"; if ($@) { - exec("$ENV{HOME}/bin/localenv", $0, @ARGV); + exec(file($ENV{HOME}, 'bin', 'localenv'), $0, @ARGV); } } @@ -14,12 +15,12 @@ use Path::Class; my $log_dir = dir($ENV{HOME}, 'logs'); mkdir $log_dir if ! -d $log_dir; -my $program = "$ENV{HOME}/bin/netdisco-daemon-fg"; +my $program = file($ENV{HOME}, 'bin', 'netdisco-daemon-fg'); Daemon::Control->new({ name => 'Netdisco Daemon', program => ($ENV{NETDISCO_DAEMON} || $program), - pid_file => "$ENV{HOME}/netdisco-daemon.pid", + pid_file => file($ENV{HOME}, 'netdisco-daemon.pid'), stderr_file => file($log_dir, 'netdisco-daemon.log'), stdout_file => file($log_dir, 'netdisco-daemon.log'), })->run; diff --git a/Netdisco/bin/netdisco-deploy b/Netdisco/bin/netdisco-deploy index 03544407..b76b1def 100755 --- a/Netdisco/bin/netdisco-deploy +++ b/Netdisco/bin/netdisco-deploy @@ -14,6 +14,7 @@ use Term::ReadLine; use Archive::Extract; use HTTP::Tiny; use Try::Tiny; +use Path::Class 'file'; =head1 netdisco-deploy @@ -108,7 +109,7 @@ sub deploy_oui { sub deploy_mibs { my $url = 'http://downloads.sourceforge.net/project/netdisco/netdisco-mibs/latest-snapshot/netdisco-mibs-snapshot.tar.gz'; - my $file = "$ENV{HOME}/netdisco-mibs-snapshot.tar.gz"; + my $file = file($ENV{HOME}, 'netdisco-mibs-snapshot.tar.gz'); my $resp = HTTP::Tiny->new->mirror($url, $file); if ($resp->{success}) { diff --git a/Netdisco/bin/netdisco-web b/Netdisco/bin/netdisco-web index de75a4b8..b8fed430 100755 --- a/Netdisco/bin/netdisco-web +++ b/Netdisco/bin/netdisco-web @@ -2,23 +2,23 @@ use strict; use warnings FATAL => 'all'; +use Path::Class; BEGIN { eval "use Daemon::Control"; if ($@) { - exec("$ENV{HOME}/bin/localenv", $0, @ARGV); + exec(file($ENV{HOME}, 'bin', 'localenv'), $0, @ARGV); } } -use Path::Class; my $log_dir = dir($ENV{HOME}, 'logs'); mkdir $log_dir if ! -d $log_dir; Daemon::Control->new({ name => 'Netdisco Web', program => 'plackup', - program_args => ["$ENV{HOME}/bin/netdisco-web-fg"], - pid_file => "$ENV{HOME}/netdisco-web.pid", + program_args => [file($ENV{HOME}, 'bin', 'netdisco-web-fg')], + pid_file => file($ENV{HOME}, 'netdisco-web.pid'), stderr_file => file($log_dir, 'netdisco-web.log'), stdout_file => file($log_dir, 'netdisco-web.log'), })->run; diff --git a/Netdisco/lib/App/Netdisco/Util/Connect.pm b/Netdisco/lib/App/Netdisco/Util/Connect.pm index 381971c7..09ffda61 100644 --- a/Netdisco/lib/App/Netdisco/Util/Connect.pm +++ b/Netdisco/lib/App/Netdisco/Util/Connect.pm @@ -5,6 +5,7 @@ use Dancer::Plugin::DBIC 'schema'; use SNMP::Info; use Try::Tiny; +use Path::Class 'dir'; use base 'Exporter'; our @EXPORT = (); @@ -145,8 +146,7 @@ sub snmp_connect { } sub _build_mibdirs { - # FIXME: make this cross-platform (Path::Class?) - return map { setting('mibhome') .'/'. $_ } + return map { dir(setting('mibhome'), $_) } @{ setting('mibdirs') || [] }; }