Skip to content

Commit 16285a8

Browse files
authored
Merge pull request #941 from metacpan/oalders/some-path-tiny
Begin using Path::Tiny in more places
2 parents 08a29a4 + f194993 commit 16285a8

File tree

8 files changed

+39
-43
lines changed

8 files changed

+39
-43
lines changed

lib/MetaCPAN/Model/Release.pm

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use MetaCPAN::Types qw(ArrayRef AbsFile Str);
1515
use MetaCPAN::Util qw( fix_version);
1616
use Module::Metadata 1.000012 (); # Improved package detection.
1717
use MooseX::StrictConstructor;
18-
use Path::Class ();
18+
use Path::Tiny qw(path);
1919
use Parse::PMFile;
2020
use Try::Tiny qw( catch try );
2121

@@ -337,10 +337,7 @@ sub _build_files {
337337
my $extract_dir = $self->extract;
338338
File::Find::find(
339339
sub {
340-
my $child
341-
= -d $File::Find::name
342-
? Path::Class::Dir->new($File::Find::name)
343-
: Path::Class::File->new($File::Find::name);
340+
my $child = path($File::Find::name);
344341
return if $self->_is_broken_file($File::Find::name);
345342
my $relative = $child->relative($extract_dir);
346343
my $stat = do {

lib/MetaCPAN/Role/Logger.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use Moose::Role;
55
use MetaCPAN::Types qw(:all);
66
use Log::Contextual qw( set_logger );
77
use Log::Log4perl ':easy';
8-
use Path::Class ();
8+
use Path::Tiny qw( path );
99

1010
has level => (
1111
is => 'ro',
@@ -58,7 +58,7 @@ sub _build_logger {
5858
if ( $c->{class} =~ /Appender::File$/ && $c->{filename} ) {
5959

6060
# Create the log file's parent directory if necessary.
61-
Path::Class::File->new( $c->{filename} )->parent->mkpath;
61+
path( $c->{filename} )->parent->mkpath;
6262
}
6363

6464
my $app = Log::Log4perl::Appender->new( $c->{class}, %$c );

t/00_setup.t

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use lib 't/lib';
44

55
use CPAN::Faker 0.010;
66
use Devel::Confess;
7-
use File::Copy qw( copy );
87
use MetaCPAN::Script::Tickets ();
98
use MetaCPAN::Server::Test;
109
use MetaCPAN::TestHelpers qw(
@@ -31,7 +30,7 @@ BEGIN {
3130

3231
# Ensure we're starting fresh
3332
my $tmp_dir = tmp_dir();
34-
$tmp_dir->rmtree;
33+
$tmp_dir->remove_tree;
3534
$tmp_dir->mkpath;
3635

3736
ok( $tmp_dir->stat, "$tmp_dir exists for testing" );
@@ -46,26 +45,26 @@ my $mod_faker = 'Module::Faker::Dist::WithPerl';
4645
eval "require $mod_faker" or die $@; ## no critic (StringyEval)
4746

4847
my $fakecpan_dir = fakecpan_dir();
49-
$fakecpan_dir->rmtree;
48+
$fakecpan_dir->remove_tree;
5049
$fakecpan_dir = fakecpan_dir(); # recreate dir
5150

5251
my $fakecpan_configs = fakecpan_configs_dir();
5352

5453
my $cpan = CPAN::Faker->new(
5554
{
56-
source => $fakecpan_configs->subdir('configs')->stringify,
55+
source => $fakecpan_configs->child('configs')->stringify,
5756
dest => $fakecpan_dir->stringify,
5857
dist_class => $mod_faker,
5958
}
6059
);
6160

6261
ok( $cpan->make_cpan, 'make fake cpan' );
63-
$fakecpan_dir->subdir('authors')->mkpath;
64-
$fakecpan_dir->subdir('indices')->mkpath;
62+
$fakecpan_dir->child('authors')->mkpath;
63+
$fakecpan_dir->child('indices')->mkpath;
6564

6665
# make some changes to 06perms.txt
6766
{
68-
my $perms_file = $fakecpan_dir->subdir('modules')->file('06perms.txt');
67+
my $perms_file = $fakecpan_dir->child('modules')->child('06perms.txt');
6968
my $perms = $perms_file->slurp;
7069
$perms =~ s/^Some,LOCAL,f$/Some,MO,f/m;
7170
my $fh = $perms_file->openw;
@@ -84,16 +83,16 @@ local $Parse::PMFile::VERBOSE = $ENV{TEST_VERBOSE} ? 9 : 0;
8483

8584
my $src_dir = $fakecpan_configs;
8685

87-
$src_dir->file('00whois.xml')
88-
->copy_to( $fakecpan_dir->file(qw(authors 00whois.xml)) );
86+
$src_dir->child('00whois.xml')
87+
->copy( $fakecpan_dir->child(qw(authors 00whois.xml)) );
8988

90-
copy( $src_dir->file('author-1.0.json'),
91-
$fakecpan_dir->file(qw(authors id M MO MO author-1.0.json)) );
89+
$src_dir->child('author-1.0.json')
90+
->copy( $fakecpan_dir->child(qw(authors id M MO MO author-1.0.json)) );
9291

93-
copy( $src_dir->file('bugs.tsv'), $fakecpan_dir->file('bugs.tsv') );
92+
$src_dir->child('bugs.tsv')->copy( $fakecpan_dir->child('bugs.tsv') );
9493

95-
copy( $src_dir->file('mirrors.json'),
96-
$fakecpan_dir->file(qw(indices mirrors.json)) );
94+
$src_dir->child('mirrors.json')
95+
->copy( $fakecpan_dir->child(qw(indices mirrors.json)) );
9796

9897
$server->index_permissions;
9998
$server->index_packages;
@@ -113,11 +112,11 @@ ok(
113112
%{$config},
114113
rt_summary_url => uri(
115114
scheme => 'file',
116-
path => $fakecpan_dir->file('bugs.tsv')->absolute->stringify,
115+
path => $fakecpan_dir->child('bugs.tsv')->absolute->stringify,
117116
),
118117
github_issues => uri(
119118
scheme => 'file',
120-
path => $fakecpan_dir->subdir('github')->absolute->stringify
119+
path => $fakecpan_dir->child('github')->absolute->stringify
121120
. '/%s/%s.json?per_page=100'
122121
),
123122
}

t/lib/MetaCPAN/TestHelpers.pm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Cpanel::JSON::XS;
88
use FindBin;
99
use Git::Helpers qw( checkout_root );
1010
use MetaCPAN::Script::Runner;
11-
use Path::Class qw( dir );
11+
use Path::Tiny qw( path );
1212
use Test::More;
1313
use Test::Routine::Util;
1414
use Try::Tiny qw( catch try );
@@ -84,7 +84,7 @@ sub test_release {
8484

8585
# If the first arg is a string, treat it like 'AUTHOR/Release-Name'.
8686
if ( !ref( $_[0] ) ) {
87-
my ( $author, $name ) = split /\//, shift;
87+
my ( $author, $name ) = split m{/}, shift;
8888
$release = { name => $name, author => $author };
8989
}
9090

@@ -98,27 +98,27 @@ sub get_config {
9898
my $config = do {
9999

100100
# build_config expects test to be t/*.t
101-
local $FindBin::RealBin = dir( undef, checkout_root(), 't' );
101+
local $FindBin::RealBin = path( checkout_root(), 't' );
102102
MetaCPAN::Script::Runner->build_config;
103103
};
104104
return $config;
105105
}
106106

107107
sub tmp_dir {
108-
my $dir = dir( checkout_root(), 'var', 't', 'tmp' );
108+
my $dir = path( checkout_root(), 'var', 't', 'tmp' );
109109
$dir->mkpath;
110110
return $dir;
111111
}
112112

113113
sub fakecpan_dir {
114114
my $dir = tmp_dir();
115-
my $fakecpan = $dir->subdir('fakecpan');
115+
my $fakecpan = $dir->child('fakecpan');
116116
$fakecpan->mkpath;
117117
return $fakecpan;
118118
}
119119

120120
sub fakecpan_configs_dir {
121-
my $source = dir( undef, checkout_root(), 'test-data', 'fakecpan' );
121+
my $source = path( checkout_root(), 'test-data', 'fakecpan' );
122122
$source->mkpath;
123123
return $source;
124124
}

t/model/archive.t

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use strict;
22
use warnings;
33
use lib 't/lib';
44

5+
use Digest::SHA qw( sha1_hex );
56
use MetaCPAN::TestHelpers qw( fakecpan_dir );
67
use Test::Most;
7-
use Digest::SHA qw( sha1_hex );
88

99
my $CLASS = 'MetaCPAN::Model::Archive';
1010
require_ok $CLASS;
@@ -35,8 +35,8 @@ subtest 'archive extraction' => sub {
3535
);
3636

3737
my $archive = $CLASS->new(
38-
file => fakecpan_dir->file(
39-
'/authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz')
38+
file => fakecpan_dir->child(
39+
'/authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz')->stringify
4040
);
4141

4242
ok !$archive->is_impolite;
@@ -62,8 +62,8 @@ subtest 'temp cleanup' => sub {
6262

6363
{
6464
my $archive = $CLASS->new(
65-
file => fakecpan_dir->file(
66-
'authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz')
65+
file => fakecpan_dir->child(
66+
'authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz')->stringify
6767
);
6868

6969
$tempdir = $archive->extract;
@@ -79,8 +79,8 @@ subtest 'temp cleanup' => sub {
7979

8080
subtest 'extract once' => sub {
8181
my $archive = $CLASS->new(
82-
file => fakecpan_dir->file(
83-
'authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz')
82+
file => fakecpan_dir->child(
83+
'authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz')->stringify
8484
);
8585

8686
is $archive->extract, $archive->extract;
@@ -91,8 +91,8 @@ subtest 'set extract dir' => sub {
9191

9292
{
9393
my $archive = $CLASS->new(
94-
file => fakecpan_dir->file(
95-
'authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz'),
94+
file => fakecpan_dir->child(
95+
'authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz')->stringify,
9696
extract_dir => $temp->dirname
9797
);
9898

t/model/release/dependencies.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ my $config = get_config();
1212

1313
subtest 'basic dependencies' => sub {
1414
my $file
15-
= fakecpan_dir->file(
15+
= fakecpan_dir->child(
1616
'/authors/id/M/MS/MSCHWERN/Prereqs-Basic-0.01.tar.gz');
1717

1818
my $release = MetaCPAN::Model::Release->new(

t/model/release/metadata.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use MetaCPAN::Script::Runner;
88
use MetaCPAN::TestHelpers qw( fakecpan_dir get_config );
99
use Test::More;
1010

11-
my $authordir = fakecpan_dir->file('authors/id/L/LO/LOCAL');
11+
my $authordir = fakecpan_dir->child('authors/id/L/LO/LOCAL');
1212

1313
my $config = get_config();
1414

t/server/controller/pod.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ use Cpanel::JSON::XS ();
66
use HTTP::Request::Common qw( GET );
77
use MetaCPAN::Server ();
88
use MetaCPAN::TestHelpers;
9-
use Path::Class qw(dir);
9+
use Path::Tiny qw(path);
1010
use Plack::Test;
1111
use Test::More;
1212
use Try::Tiny qw( catch try );
1313

14-
my $dir = dir( MetaCPAN::Server->model('Source')->base_dir,
14+
my $dir = path( MetaCPAN::Server->model('Source')->base_dir,
1515
'DOY/Moose-0.02/Moose-0.02' );
1616
$dir->mkpath;
1717

18-
my $file = $dir->file('binary.bin');
18+
my $file = $dir->child('binary.bin');
1919
$file->openw->print( "\x00" x 10 );
2020

2121
my %tests = (

0 commit comments

Comments
 (0)