Skip to content

Commit

Permalink
Merge pull request #876 from shawnlaffan/issue_853_pt1
Browse files Browse the repository at this point in the history
Replace Path::Class and File::Spec with Path::Tiny
  • Loading branch information
shawnlaffan authored Aug 12, 2023
2 parents c4bad7d + dd085f7 commit 9d2b3b0
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 81 deletions.
2 changes: 0 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ my %common_reqs = (
"Class::Inspector" => 0,
"Clone" => "0.35",
"Cpanel::JSON::XS" => "3",
"DBD::XBase" => 0,
"Data::Structure::Util" => 0,
"Data::Compare" => 0,
"Exception::Class" => 0,
Expand All @@ -28,7 +27,6 @@ my %common_reqs = (
"List::Util" => "1.54",
"Math::Polygon" => 0,
"Math::Random::MT::Auto" => "6.21",
"Path::Class" => 0,
"Readonly" => 0,
"Ref::Util" => 0,
"Ref::Util::XS" => 0,
Expand Down
2 changes: 0 additions & 2 deletions bin/load_and_randomise.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
use FindBin qw { $Bin };
use Carp;
use English qw { -no_match_vars };
use Path::Class;
use Scalar::Util qw /blessed/;

#use lib Path::Class::dir ( $Bin, '..', 'lib')->stringify;
use rlib;

local $| = 1;
Expand Down
7 changes: 2 additions & 5 deletions bin/load_and_randomise_wrapper.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
use FindBin qw { $Bin };
use English qw { -no_match_vars };
use Carp;
use File::Spec;
Path::Tiny qw /path/;

use Path::Class;

#use lib Path::Class::dir ( $Bin, '..', 'lib')->stringify;
use rlib;

our $VERSION = '4.99_001';
Expand Down Expand Up @@ -54,7 +51,7 @@


my $script_name = 'load_and_randomise.pl';
my $script = File::Spec -> catfile ($FindBin::Bin, $script_name);
my $script = path($FindBin::Bin, $script_name)->stringify;

# need to get it from the perlapp bindings?
if ($perl_app_tool eq 'PerlApp') {
Expand Down
2 changes: 0 additions & 2 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
requires "Class::Inspector";
requires "Clone", "0.35";
requires "Cpanel::JSON::XS", "3";
requires "DBD::XBase";
requires "Data::Structure::Util";
requires "Data::Compare";
#requires "Data::DumpXML";
Expand All @@ -22,7 +21,6 @@ requires "List::Unique::DeterministicOrder", "0.003";
requires "List::Util", "1.54";
requires "Math::Polygon";
requires "Math::Random::MT::Auto", "6.21";
requires "Path::Class";
requires "Readonly";
requires "Ref::Util";
requires "Ref::Util::XS";
Expand Down
1 change: 0 additions & 1 deletion lib/Biodiverse/BaseData.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use POSIX qw {fmod floor};
use Scalar::Util qw /looks_like_number blessed/;
use List::Util 1.45 qw /max min sum pairs uniq/;
use List::MoreUtils qw /first_index/;
use Path::Class;
use Path::Tiny qw /path/;
use Geo::Converter::dms2dd qw {dms2dd};
use Regexp::Common qw /number/;
Expand Down
15 changes: 7 additions & 8 deletions lib/Biodiverse/BaseData/Import.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use POSIX qw {fmod floor ceil log2};
use Scalar::Util qw /looks_like_number blessed reftype/;
use List::Util 1.45 qw /max min sum any all none notall pairs uniq/;
use List::MoreUtils qw /first_index/;
use Path::Class;
#use Path::Tiny qw /path/;
use Path::Tiny qw /path/;
use Geo::Converter::dms2dd qw {dms2dd};
use Regexp::Common qw /number/;
use Data::Compare ();
Expand Down Expand Up @@ -316,7 +315,7 @@ sub import_data {

#print "[BASEDATA] Input files to load are ", join (" ", @{$args{input_files}}), "\n";
foreach my $file ( @{ $args{input_files} } ) {
$file = Path::Class::file($file)->absolute;
$file = path($file)->absolute;
say "[BASEDATA] INPUT FILE: $file";
my $file_base = $file->basename;

Expand Down Expand Up @@ -705,8 +704,8 @@ sub import_data_raster {
);
}

$file = Path::Class::file($file)->absolute;
my $file_base = Path::Class::File->new($file)->basename();
$file = path($file)->absolute;
my $file_base = $file->basename;
say "[BASEDATA] INPUT FILE: $file";

croak "[BASEDATA] $file DOES NOT EXIST OR CANNOT BE READ "
Expand Down Expand Up @@ -1048,7 +1047,7 @@ sub import_data_shapefile {
my $file_num = 0;
foreach my $file ( @input_files ) {
$file_num++;
$file = Path::Class::file($file)->absolute->stringify;
$file = path($file)->absolute->stringify;
say "[BASEDATA] INPUT FILE: $file";

if ($file_progress) {
Expand Down Expand Up @@ -1092,7 +1091,7 @@ sub import_data_shapefile {
my $shape_x_index = first_index {$_ eq ':shape_x'} @group_field_names;
my $shape_y_index = first_index {$_ eq ':shape_y'} @group_field_names;

if (-w Path::Class::file($fnamebase)->dir->stringify
if (-w path($fnamebase)->parent->stringify
&& -w $fnamebase) {
# only works for shapefiles
eval {
Expand Down Expand Up @@ -1751,7 +1750,7 @@ sub import_data_spreadsheet {
if !defined $book; # assuming undef on fail

if ( blessed $book || !ref $book ) { # we have a file name
my $file = Path::Class::file($book)->absolute;
my $file = path($book)->absolute;
say "[BASEDATA] INPUT FILE: $file";

$book = $self->get_book_struct_from_spreadsheet_file (
Expand Down
2 changes: 0 additions & 2 deletions lib/Biodiverse/BaseStruct.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use English ( -no_match_vars );
use Scalar::Util qw /looks_like_number reftype/;
use List::Util qw /min max sum any/;
use List::MoreUtils qw /first_index/;
use File::Basename;
use Path::Class;
use POSIX qw /fmod floor/;
use Time::localtime;
use Ref::Util qw { :all };
Expand Down
30 changes: 15 additions & 15 deletions lib/Biodiverse/BaseStruct/Export.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Scalar::Util qw /looks_like_number reftype/;
use List::Util qw /min max sum any/;
use List::MoreUtils qw /first_index/;
use File::Basename;
use Path::Class;
use Path::Tiny qw /path/;
use POSIX qw /fmod floor/;
use Time::localtime;
use Ref::Util qw { :all };
Expand Down Expand Up @@ -876,7 +876,7 @@ sub write_table {
my $data = $args{data} || croak "data argument not specified\n";
is_arrayref($data) || croak "data arg must be an array ref\n";

$args{file} = Path::Class::file($args{file})->absolute;
$args{file} = path($args{file})->absolute;

return;
}
Expand Down Expand Up @@ -1436,7 +1436,7 @@ sub write_table_asciigrid {
is_arrayref($data) || croak "data arg must be an array ref\n";

my $file = $args{file} || croak "file arg not specified\n";
my ($name, $path, $suffix) = fileparse (Path::Class::file($file)->absolute, qr/\.asc/, qr/\.txt/);
my ($name, $path, $suffix) = fileparse (path($file)->absolute, qr/\.asc/, qr/\.txt/);
my $file_list_ref = $args{filelist} || [];

if (! defined $suffix || $suffix eq q{}) { # clear off the trailing .asc and store it
Expand Down Expand Up @@ -1468,7 +1468,7 @@ sub write_table_asciigrid {
my $this_file = $name . "_" . $header->[$i];
$this_file = $self->escape_filename (string => $this_file);

my $filename = Path::Class::file($path, $this_file)->stringify;
my $filename = path($path, $this_file)->stringify;
$filename .= $suffix;
$file_names[$i] = $filename;
push @$file_list_ref, $filename; # record file in list
Expand Down Expand Up @@ -1535,7 +1535,7 @@ sub write_table_floatgrid {
is_arrayref($data) || croak "data arg must be an array ref\n";

my $file = $args{file} || croak "file arg not specified\n";
my ($name, $path, $suffix) = fileparse (Path::Class::file($file)->absolute, qr/\.flt/);
my ($name, $path, $suffix) = fileparse (path($file)->absolute, qr/\.flt/);
if (! defined $suffix || $suffix eq q{}) { # clear off the trailing .flt and store it
$suffix = '.flt';
}
Expand Down Expand Up @@ -1568,7 +1568,7 @@ sub write_table_floatgrid {
my $this_file = $name . "_" . $header->[$i];
$this_file = $self->escape_filename (string => $this_file);

my $filename = Path::Class::file($path, $this_file)->stringify;
my $filename = path($path, $this_file)->stringify;
$filename .= $suffix;
$file_names[$i] = $filename;

Expand Down Expand Up @@ -1638,7 +1638,7 @@ sub write_table_divagis {
is_arrayref($data) || croak "data arg must be an array ref\n";

my $file = $args{file} || croak "file arg not specified\n";
my ($name, $path, $suffix) = fileparse (Path::Class::file($file)->stringify, qr'\.gri');
my ($name, $path, $suffix) = fileparse (path($file)->stringify, qr'\.gri');
if (! defined $suffix || $suffix eq q{}) { # clear off the trailing .gri and store it
$suffix = '.gri';
}
Expand Down Expand Up @@ -1667,7 +1667,7 @@ sub write_table_divagis {
my $this_file = $name . "_" . $header->[$i];
$this_file = $self->escape_filename (string => $this_file);

my $filename = Path::Class::file($path, $this_file)->stringify;
my $filename = path($path, $this_file)->stringify;
$filename .= $suffix;
$file_names[$i] = $filename;

Expand Down Expand Up @@ -1773,7 +1773,7 @@ sub write_table_geotiff {
is_arrayref($data) || croak "data arg must be an array ref\n";

my $file = $args{file} || croak "file arg not specified\n";
my ($name, $path, $suffix) = fileparse (Path::Class::file($file)->absolute, qr/\.tif{1,2}/);
my ($name, $path, $suffix) = fileparse (path($file)->absolute, qr/\.tif{1,2}/);
if (! defined $suffix || $suffix eq q{}) { # clear off the trailing .tif and store it
$suffix = '.tif';
}
Expand Down Expand Up @@ -1819,7 +1819,7 @@ sub write_table_geotiff {
my $this_file = $name . "_" . $header->[$i];
$this_file = $self->escape_filename (string => $this_file);

my $filename = Path::Class::file($path, $this_file)->stringify;
my $filename = path($path, $this_file)->stringify;
$filename .= $suffix;
$file_names[$i] = $filename;
$index_fname_hash{$header->[$i]} = $filename;
Expand Down Expand Up @@ -1881,7 +1881,7 @@ sub write_rgb_geotiff {
my %args = @_;

my $file = $args{file} || croak "file arg not specified\n";
my ($name, $path, $suffix) = fileparse (Path::Class::file($file)->absolute, qr/\.tif{1,2}/);
my ($name, $path, $suffix) = fileparse (path($file)->absolute, qr/\.tif{1,2}/);
if (! defined $suffix || $suffix eq q{}) { # clear off the trailing .tif and store it
$suffix = '.tif';
}
Expand All @@ -1903,7 +1903,7 @@ sub write_rgb_geotiff {
my $this_file = "${name}_${index}_rgb";
$this_file = $self->escape_filename (string => $this_file);

my $f_name = Path::Class::file($path, $this_file)->stringify;
my $f_name = path($path, $this_file)->stringify;
$f_name .= $suffix;

# we really should cache using a basestruct
Expand Down Expand Up @@ -2004,7 +2004,7 @@ sub write_table_ers {
my $file = $args{file} || croak "file arg not specified\n";

my ($name, $path, $suffix)
= fileparse (Path::Class::file($file)->absolute, qr/\.ers/);
= fileparse (path($file)->absolute, qr/\.ers/);

# add suffix if not specified
if (!defined $suffix || $suffix eq q{}) {
Expand All @@ -2030,7 +2030,7 @@ sub write_table_ers {

#my %stats;

my $data_file = Path::Class::file($path, $name)->stringify;
my $data_file = path($path, $name)->stringify;
my $ofh = $self->get_file_handle (
file_name => $data_file,
mode => '>',
Expand Down Expand Up @@ -2134,7 +2134,7 @@ END_OF_ERS_HEADER_START
"DatasetHeader End"
);

my $header_file = Path::Class::file($path, $name)->stringify . $suffix;
my $header_file = path($path, $name)->stringify . $suffix;
my $header_fh = $self->get_file_handle (
file_name => $header_file,
mode => '>:utf8',
Expand Down
3 changes: 2 additions & 1 deletion lib/Biodiverse/Cluster.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use Scalar::Util qw /looks_like_number/;
use Time::HiRes qw /time/;
use Sort::Key qw /rnkeysort/;
use Sort::Key::Natural qw /natsort/;
use Path::Tiny qw /path/;


use experimental qw /declared_refs/;
Expand Down Expand Up @@ -294,7 +295,7 @@ sub export_matrices {
$suffix = ".$suffix";
}

$file = Path::Class::file($path, $name)->absolute;
$file = path($path, $name)->absolute;

foreach my $matrix (@$matrices) {
next if ! defined $matrix; # allow for absent shadow matrix
Expand Down
28 changes: 14 additions & 14 deletions lib/Biodiverse/Common.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use List::MoreUtils qw /none/;
use List::Util qw /first/;
use Storable qw /nstore retrieve dclone/;
use File::Basename;
use Path::Class;
use Path::Tiny qw /path/;
use POSIX ();
use HTML::QuickTable;
#use XBase;
Expand Down Expand Up @@ -166,7 +166,7 @@ sub load_sereal_file {
// eval {$self->get_file_suffix}
// $EMPTY_STRING;

my $file = Path::Class::file($args{file})->absolute;
my $file = path($args{file})->absolute;
croak "[BASEDATA] File $file does not exist\n"
if !$self->file_exists_aa ($file);

Expand Down Expand Up @@ -231,7 +231,7 @@ sub load_storable_file {

my $suffix = $args{suffix} || $self->get_param('OUTSUFFIX') || $EMPTY_STRING;

my $file = Path::Class::file($args{file})->absolute;
my $file = path($args{file})->absolute;

croak "Unicode file names not supported for Storable format,"
. "please rename $file and try again\n"
Expand Down Expand Up @@ -813,9 +813,9 @@ sub save_to_sereal {
my $file = $args{filename};
if (! defined $file) {
my $prefix = $args{OUTPFX} || $self->get_param('OUTPFX') || $self->get_param('NAME') || caller();
$file = Path::Class::file($file || ($prefix . '.' . $self->get_param('OUTSUFFIX')));
$file = path($file || ($prefix . '.' . $self->get_param('OUTSUFFIX')));
}
$file = Path::Class::file($file)->absolute;
$file = path($file)->absolute;

say "[COMMON] WRITING TO SEREAL FORMAT FILE $file";

Expand Down Expand Up @@ -851,9 +851,9 @@ sub save_to_storable {
my $file = $args{filename};
if (! defined $file) {
my $prefix = $args{OUTPFX} || $self->get_param('OUTPFX') || $self->get_param('NAME') || caller();
$file = Path::Class::file($file || ($prefix . '.' . $self->get_param('OUTSUFFIX')));
$file = path($file || ($prefix . '.' . $self->get_param('OUTSUFFIX')));
}
$file = Path::Class::file($file)->absolute;
$file = path($file)->absolute;

print "[COMMON] WRITING TO STORABLE FORMAT FILE $file\n";

Expand All @@ -876,9 +876,9 @@ sub save_to_yaml {
my $file = $args{filename};
if (! defined $file) {
my $prefix = $args{OUTPFX} || $self->get_param('OUTPFX') || $self->get_param('NAME') || caller();
$file = Path::Class::file($file || ($prefix . "." . $self->get_param('OUTSUFFIX_YAML')));
$file = path($file || ($prefix . "." . $self->get_param('OUTSUFFIX_YAML')));
}
$file = Path::Class::file($file)->absolute;
$file = path($file)->absolute;

print "[COMMON] WRITING TO YAML FORMAT FILE $file\n";

Expand All @@ -896,9 +896,9 @@ sub save_to_data_dumper {
if (! defined $file) {
my $prefix = $args{OUTPFX} || $self->get_param('OUTPFX') || $self->get_param('NAME') || caller();
my $suffix = $self->get_param('OUTSUFFIX') || 'data_dumper';
$file = Path::Class::file($file || ($prefix . '.' . $suffix));
$file = path($file || ($prefix . '.' . $suffix));
}
$file = Path::Class::file($file)->absolute;
$file = path($file)->absolute;

print "[COMMON] WRITING TO DATA DUMPER FORMAT FILE $file\n";

Expand All @@ -919,7 +919,7 @@ sub dump_to_yaml {
my $data = $args{data};

if (defined $args{filename}) {
my $file = Path::Class::file($args{filename})->absolute;
my $file = path($args{filename})->absolute;
say "WRITING TO YAML FORMAT FILE $file";
YAML::Syck::DumpFile ($file, $data);
}
Expand All @@ -942,7 +942,7 @@ sub dump_to_json {
my $data = $args{data};

if (defined $args{filename}) {
my $file = Path::Class::file($args{filename})->absolute;
my $file = path($args{filename})->absolute;
say "WRITING TO JSON FILE $file";
open (my $fh, '>', $file)
or croak "Cannot open $file to write to, $!\n";
Expand Down Expand Up @@ -1038,7 +1038,7 @@ sub write_table {
my $data = $args{data} || croak "data argument not specified\n";
is_arrayref($data) || croak "data arg must be an array ref\n";

$args{file} = Path::Class::file($args{file})->absolute;
$args{file} = path($args{file})->absolute;

# now do stuff depending on what format was chosen, based on the suffix
my (undef, $suffix) = lc ($args{file}) =~ /(.*?)\.(.*?)$/;
Expand Down
Loading

0 comments on commit 9d2b3b0

Please sign in to comment.