From: Arthur Axel 'fREW' Schmidt Date: Sat, 18 Aug 2012 06:25:11 +0000 (-0500) Subject: switch to Path::Class for fewer mistakes X-Git-Tag: v0.002201~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=297e662fab9ba5a6798db95abbdbca2181373c92;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git switch to Path::Class for fewer mistakes --- diff --git a/dist.ini b/dist.ini index 89fabf7..4c4fc1d 100644 --- a/dist.ini +++ b/dist.ini @@ -26,7 +26,7 @@ parent = 0.225 autodie = 0 namespace::autoclean = 0 Log::Contextual = 0.004200 -File::Path = 2.08 +Path::Class = 0.26 DBIx::Class = 0.08121 Moose = 1.0 MooseX::Role::Parameterized = 0.18 diff --git a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm index 0e89098..d7601c6 100644 --- a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm +++ b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm @@ -16,8 +16,7 @@ require SQL::Translator::Diff; require DBIx::Class::Storage; # loaded for type constraint use DBIx::Class::DeploymentHandler::Types; -use File::Path 'mkpath'; -use File::Spec::Functions; +use Path::Class qw(file dir); with 'DBIx::Class::DeploymentHandler::HandlesDeploy'; @@ -94,16 +93,16 @@ sub __ddl_consume_with_prefix { my ($self, $type, $versions, $prefix) = @_; my $base_dir = $self->script_directory; - my $main = catfile( $base_dir, $type ); + my $main = dir( $base_dir, $type ); my $common = - catfile( $base_dir, '_common', $prefix, join q(-), @{$versions} ); + dir( $base_dir, '_common', $prefix, join q(-), @{$versions} ); my $common_any = - catfile( $base_dir, '_common', $prefix, '_any' ); + dir( $base_dir, '_common', $prefix, '_any' ); my $dir; if (-d $main) { - $dir = catfile($main, $prefix, join q(-), @{$versions}) + $dir = dir($main, $prefix, join q(-), @{$versions}) } else { if ($self->ignore_ddl) { return [] @@ -111,7 +110,7 @@ sub __ddl_consume_with_prefix { croak "$main does not exist; please write/generate some SQL" } } - my $dir_any = catfile($main, $prefix, '_any'); + my $dir_any = dir($main, $prefix, '_any'); my %files; try { @@ -126,9 +125,9 @@ sub __ddl_consume_with_prefix { }; for my $dirname (grep { -d $_ } $common, $common_any, $dir_any) { opendir my($dh), $dirname; - for my $filename (grep { /\.(?:sql|pl)$/ && -f catfile($dirname,$_) } readdir $dh) { + for my $filename (grep { /\.(?:sql|pl)$/ && -f file($dirname,$_) } readdir $dh) { unless ($files{$filename}) { - $files{$filename} = catfile($dirname,$filename); + $files{$filename} = file($dirname,$filename); } } closedir $dh; @@ -151,7 +150,7 @@ sub _ddl_protoschema_deploy_consume_filenames { my ($self, $version) = @_; my $base_dir = $self->script_directory; - my $dir = catfile( $base_dir, '_source', 'deploy', $version); + my $dir = dir( $base_dir, '_source', 'deploy', $version); return [] unless -d $dir; opendir my($dh), $dir; @@ -165,7 +164,7 @@ sub _ddl_protoschema_upgrade_consume_filenames { my ($self, $versions) = @_; my $base_dir = $self->script_directory; - my $dir = catfile( $base_dir, '_preprocess_schema', 'upgrade', join q(-), @{$versions}); + my $dir = dir( $base_dir, '_preprocess_schema', 'upgrade', join q(-), @{$versions}); return [] unless -d $dir; @@ -180,7 +179,7 @@ sub _ddl_protoschema_downgrade_consume_filenames { my ($self, $versions) = @_; my $base_dir = $self->script_directory; - my $dir = catfile( $base_dir, '_preprocess_schema', 'downgrade', join q(-), @{$versions}); + my $dir = dir( $base_dir, '_preprocess_schema', 'downgrade', join q(-), @{$versions}); return [] unless -d $dir; @@ -193,18 +192,18 @@ sub _ddl_protoschema_downgrade_consume_filenames { sub _ddl_protoschema_produce_filename { my ($self, $version) = @_; - my $dirname = catfile( $self->script_directory, '_source', 'deploy', $version ); - mkpath($dirname) unless -d $dirname; + my $dirname = dir( $self->script_directory, '_source', 'deploy', $version ); + $dirname->mkpath unless -d $dirname; - return catfile( $dirname, '001-auto.yml' ); + return "" . file( $dirname, '001-auto.yml' ); } sub _ddl_schema_produce_filename { my ($self, $type, $version) = @_; - my $dirname = catfile( $self->script_directory, $type, 'deploy', $version ); - mkpath($dirname) unless -d $dirname; + my $dirname = dir( $self->script_directory, $type, 'deploy', $version ); + $dirname->mkpath unless -d $dirname; - return catfile( $dirname, '001-auto.sql' ); + return "" . file( $dirname, '001-auto.sql' ); } sub _ddl_schema_upgrade_consume_filenames { @@ -221,18 +220,18 @@ sub _ddl_schema_upgrade_produce_filename { my ($self, $type, $versions) = @_; my $dir = $self->script_directory; - my $dirname = catfile( $dir, $type, 'upgrade', join q(-), @{$versions}); - mkpath($dirname) unless -d $dirname; + my $dirname = dir( $dir, $type, 'upgrade', join q(-), @{$versions}); + $dirname->mkpath unless -d $dirname; - return catfile( $dirname, '001-auto.sql' ); + return "" . file( $dirname, '001-auto.sql' ); } sub _ddl_schema_downgrade_produce_filename { my ($self, $type, $versions, $dir) = @_; - my $dirname = catfile( $dir, $type, 'downgrade', join q(-), @{$versions} ); - mkpath($dirname) unless -d $dirname; + my $dirname = dir( $dir, $type, 'downgrade', join q(-), @{$versions} ); + $dirname->mkpath unless -d $dirname; - return catfile( $dirname, '001-auto.sql'); + return "" . file( $dirname, '001-auto.sql'); } sub _run_sql_array { @@ -338,8 +337,8 @@ sub _run_sql_and_perl { my $sql = ($sql_to_run)?join ";\n", @$sql_to_run:''; FILENAME: - for my $filename (@files) { - if ($self->ignore_ddl && $filename =~ /^[^_]*-auto.*\.sql$/) { + for my $filename (map file($_), @files) { + if ($self->ignore_ddl && $filename->basename =~ /^[^_]*-auto.*\.sql$/) { next FILENAME } elsif ($filename =~ /\.sql$/) { $sql .= $self->_run_sql($filename) @@ -535,10 +534,10 @@ sub _resultsource_install_filename { my ($self, $source_name) = @_; return sub { my ($self, $type, $version) = @_; - my $dirname = catfile( $self->script_directory, $type, 'deploy', $version ); - mkpath($dirname) unless -d $dirname; + my $dirname = dir( $self->script_directory, $type, 'deploy', $version ); + $dirname->mkpath unless -d $dirname; - return catfile( $dirname, "001-auto-$source_name.sql" ); + return "" . file( $dirname, "001-auto-$source_name.sql" ); } } @@ -546,10 +545,10 @@ sub _resultsource_protoschema_filename { my ($self, $source_name) = @_; return sub { my ($self, $version) = @_; - my $dirname = catfile( $self->script_directory, '_source', 'deploy', $version ); - mkpath($dirname) unless -d $dirname; + my $dirname = dir( $self->script_directory, '_source', 'deploy', $version ); + $dirname->mkpath unless -d $dirname; - return catfile( $dirname, "001-auto-$source_name.yml" ); + return "" . file( $dirname, "001-auto-$source_name.yml" ); } } diff --git a/t/02-instantiation-no-ddl.t b/t/02-instantiation-no-ddl.t index ff4c591..521446f 100644 --- a/t/02-instantiation-no-ddl.t +++ b/t/02-instantiation-no-ddl.t @@ -8,7 +8,6 @@ use DBICDHTest; use DBIx::Class::DeploymentHandler; use aliased 'DBIx::Class::DeploymentHandler', 'DH'; -use File::Path 'remove_tree'; use Test::More; use File::Temp 'tempdir'; use Test::Fatal qw(lives_ok dies_ok); diff --git a/t/02-instantiation-wo-component.t b/t/02-instantiation-wo-component.t index 8838b66..abe28e4 100644 --- a/t/02-instantiation-wo-component.t +++ b/t/02-instantiation-wo-component.t @@ -8,7 +8,6 @@ use DBICDHTest; use DBIx::Class::DeploymentHandler; use aliased 'DBIx::Class::DeploymentHandler', 'DH'; -use File::Path 'remove_tree'; use Test::More; use File::Temp 'tempdir'; use Test::Fatal qw(lives_ok dies_ok); diff --git a/t/02-instantiation.t b/t/02-instantiation.t index f5b18a5..8cdd65d 100644 --- a/t/02-instantiation.t +++ b/t/02-instantiation.t @@ -8,7 +8,6 @@ use DBICDHTest; use DBIx::Class::DeploymentHandler; use aliased 'DBIx::Class::DeploymentHandler', 'DH'; -use File::Path 'remove_tree'; use Test::More; use File::Temp 'tempdir'; use Test::Fatal qw(lives_ok dies_ok); diff --git a/t/03-deprecated.t b/t/03-deprecated.t index 462f152..98e22fe 100644 --- a/t/03-deprecated.t +++ b/t/03-deprecated.t @@ -7,7 +7,6 @@ use lib 't/lib'; use DBICDHTest; use aliased 'DBIx::Class::DeploymentHandler::Deprecated'; -use File::Path 'remove_tree'; use Test::More; use File::Temp 'tempdir'; use Test::Fatal qw(lives_ok dies_ok); diff --git a/t/04-preconnect.t b/t/04-preconnect.t index 860b394..d265dc2 100644 --- a/t/04-preconnect.t +++ b/t/04-preconnect.t @@ -8,7 +8,7 @@ use DBICDHTest; use DBIx::Class::DeploymentHandler; use aliased 'DBIx::Class::DeploymentHandler', 'DH'; -use File::Path qw(remove_tree mkpath); +use Path::Class 'dir'; use Test::More; use File::Temp 'tempdir'; @@ -31,7 +31,7 @@ VERSION1: { ok !$s->storage->connected, 'creating handler did not connect'; ok($handler, 'DBIx::Class::DeploymentHandler w/1 instantiates correctly'); - mkpath("$sql_dir/SQLite/initialize/1"); + dir($sql_dir, qw(SQLite initialize 1))->mkpath; $handler->initialize({ version => 1, storage_type => 'SQLite' }); ok !$s->storage->connected, 'creating schema did not connect'; } diff --git a/t/bugs/01-emailed-bug-01.t b/t/bugs/01-emailed-bug-01.t index a4e25c3..d2294b6 100644 --- a/t/bugs/01-emailed-bug-01.t +++ b/t/bugs/01-emailed-bug-01.t @@ -8,7 +8,6 @@ use DBICDHTest; use DBIx::Class::DeploymentHandler; use aliased 'DBIx::Class::DeploymentHandler', 'DH'; -use File::Path 'remove_tree'; use Test::More; use File::Temp 'tempdir'; use Test::Fatal qw(lives_ok dies_ok); diff --git a/t/deploy_methods/sql_translator.t b/t/deploy_methods/sql_translator.t index dc2bf18..3158584 100644 --- a/t/deploy_methods/sql_translator.t +++ b/t/deploy_methods/sql_translator.t @@ -9,8 +9,7 @@ use Test::Fatal qw(lives_ok dies_ok); use lib 't/lib'; use DBICDHTest; use aliased 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator'; -use File::Spec::Functions qw(catfile splitdir); -use File::Path qw(rmtree mkpath); +use Path::Class qw(dir file); use File::Temp qw(tempfile tempdir); my $dbh = DBICDHTest::dbh(); @@ -19,17 +18,17 @@ my $sql_dir = tempdir( CLEANUP => 1 ); my (undef, $stuffthatran_fn) = tempfile(OPEN => 0); for (qw(initialize upgrade downgrade deploy)) { - mkpath(catfile(splitdir($sql_dir), '_common', $_, '_any' )); + dir($sql_dir, '_common', $_, '_any')->mkpath; open my $fh, '>', - catfile(splitdir($sql_dir), '_common', $_, qw(_any 000-win.pl )); + file($sql_dir, '_common', $_, qw(_any 000-win.pl )); print {$fh} qq^sub {open my \$fh, ">>", '$stuffthatran_fn'; use Data::Dumper::Concise; print {\$fh} join(",", \@{\$_[1]||[]}) . "\\n"; }^; close $fh; } for (qw(initialize upgrade downgrade deploy)) { - mkpath(catfile(splitdir($sql_dir), 'SQLite', $_, '_any' )); + dir($sql_dir, 'SQLite', $_, '_any')->mkpath; open my $fh, '>', - catfile(splitdir($sql_dir), 'SQLite', $_, qw(_any 000-win2.pl )); + file($sql_dir, 'SQLite', $_, qw(_any 000-win2.pl )); print {$fh} qq^sub {open my \$fh, ">>", '$stuffthatran_fn'; use Data::Dumper::Concise; print {\$fh} join(",", \@{\$_[1]||[]}) . "\\n"; }^; close $fh; } @@ -48,9 +47,9 @@ VERSION1: { $dm->prepare_deploy; - mkpath(catfile(splitdir($sql_dir), qw(SQLite initialize 1.0 ))); + dir($sql_dir, qw(SQLite initialize 1.0 ))->mkpath; open my $prerun, '>', - catfile(splitdir($sql_dir), qw(SQLite initialize 1.0 003-semiautomatic.pl )); + file($sql_dir, qw(SQLite initialize 1.0 003-semiautomatic.pl )); my (undef, $fn) = tempfile(OPEN => 0); print {$prerun} "sub { open my \$fh, '>', '$fn'}"; close $prerun; @@ -61,7 +60,7 @@ VERSION1: { dies_ok {$dm->prepare_deploy} 'prepare_deploy dies if you run it twice' ; ok( - -f catfile(splitdir($sql_dir), qw(SQLite deploy 1.0 001-auto.sql )), + -f file($sql_dir, qw(SQLite deploy 1.0 001-auto.sql )), '1.0 schema gets generated properly' ); @@ -96,10 +95,10 @@ VERSION2: { my $version = $s->schema_version(); $dm->prepare_deploy; ok( - -f catfile(splitdir($sql_dir), qw(SQLite deploy 2.0 001-auto.sql )), + -f file($sql_dir, qw(SQLite deploy 2.0 001-auto.sql )), '2.0 schema gets generated properly' ); - mkpath(catfile(splitdir($sql_dir), qw(SQLite upgrade 1.0-2.0 ))); + dir($sql_dir, qw(SQLite upgrade 1.0-2.0 ))->mkpath; $dm->prepare_upgrade({ from_version => '1.0', to_version => '2.0', @@ -117,17 +116,17 @@ VERSION2: { ok( $warned, 'prepare_upgrade with a bogus preversion warns' ); } ok( - -f catfile(splitdir($sql_dir), qw(SQLite upgrade 1.0-2.0 001-auto.sql )), + -f file($sql_dir, qw(SQLite upgrade 1.0-2.0 001-auto.sql )), '1.0-2.0 diff gets generated properly and default start and end versions get set' ); - mkpath(catfile(splitdir($sql_dir), qw(SQLite downgrade 2.0-1.0 ))); + dir($sql_dir, qw(SQLite downgrade 2.0-1.0 ))->mkpath; $dm->prepare_downgrade({ from_version => $version, to_version => '1.0', version_set => [$version, '1.0'] }); ok( - -f catfile(splitdir($sql_dir), qw(SQLite downgrade 2.0-1.0 001-auto.sql )), + -f file($sql_dir, qw(SQLite downgrade 2.0-1.0 001-auto.sql )), '2.0-1.0 diff gets generated properly' ); dies_ok { @@ -143,14 +142,14 @@ VERSION2: { }) } 'schema not uppgrayyed'; - mkpath catfile(splitdir($sql_dir), qw(_common upgrade 1.0-2.0 )); + dir($sql_dir, qw(_common upgrade 1.0-2.0 ))->mkpath; open my $common, '>', - catfile(splitdir($sql_dir), qw(_common upgrade 1.0-2.0 002-semiautomatic.sql )); + file($sql_dir, qw(_common upgrade 1.0-2.0 002-semiautomatic.sql )); print {$common} qq; close $common; open my $common_pl, '>', - catfile(splitdir($sql_dir), qw(_common upgrade 1.0-2.0 003-semiautomatic.pl )); + file($sql_dir, qw(_common upgrade 1.0-2.0 003-semiautomatic.pl )); print {$common_pl} q| sub { my $schema = shift; @@ -203,7 +202,7 @@ VERSION3: { my $version = $s->schema_version(); $dm->prepare_deploy; ok( - -f catfile(splitdir($sql_dir), qw(SQLite deploy 3.0 001-auto.sql )), + -f file($sql_dir, qw(SQLite deploy 3.0 001-auto.sql )), '2.0 schema gets generated properly' ); $dm->prepare_downgrade({ @@ -212,7 +211,7 @@ VERSION3: { version_set => [$version, '1.0'] }); ok( - -f catfile(splitdir($sql_dir), qw(SQLite downgrade 3.0-1.0 001-auto.sql )), + -f file($sql_dir, qw(SQLite downgrade 3.0-1.0 001-auto.sql )), '3.0-1.0 diff gets generated properly' ); $dm->prepare_upgrade({ @@ -221,7 +220,7 @@ VERSION3: { version_set => ['1.0', $version] }); ok( - -f catfile(splitdir($sql_dir), qw(SQLite upgrade 1.0-3.0 001-auto.sql )), + -f file($sql_dir, qw(SQLite upgrade 1.0-3.0 001-auto.sql )), '1.0-3.0 diff gets generated properly' ); $dm->prepare_upgrade({ @@ -238,7 +237,7 @@ VERSION3: { } 'prepare_upgrade dies if you clobber an existing upgrade file' ; ok( - -f catfile(splitdir($sql_dir), qw(SQLite upgrade 1.0-2.0 001-auto.sql )), + -f file($sql_dir, qw(SQLite upgrade 1.0-2.0 001-auto.sql )), '2.0-3.0 diff gets generated properly' ); dies_ok { diff --git a/t/deploy_methods/sql_translator_deprecated.t b/t/deploy_methods/sql_translator_deprecated.t index 4e039a8..6f791f5 100644 --- a/t/deploy_methods/sql_translator_deprecated.t +++ b/t/deploy_methods/sql_translator_deprecated.t @@ -8,7 +8,7 @@ use DBICDHTest; use aliased 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::Deprecated'; -use File::Spec::Functions qw(catfile splitdir); +use Path::Class 'file'; use File::Temp 'tempdir'; my $dbh = DBICDHTest::dbh(); @@ -32,7 +32,7 @@ VERSION1: { $dm->prepare_deploy; ok( - -f catfile(splitdir($sql_dir), qw(DBICVersion-Schema-1.0-SQLite.sql )), + -f file($sql_dir, qw(DBICVersion-Schema-1.0-SQLite.sql )), '1.0 schema gets generated properly' ); diff --git a/t/deploy_methods/sql_translator_protoschema_transform.t b/t/deploy_methods/sql_translator_protoschema_transform.t index c91f415..ee6fbcb 100644 --- a/t/deploy_methods/sql_translator_protoschema_transform.t +++ b/t/deploy_methods/sql_translator_protoschema_transform.t @@ -8,8 +8,7 @@ use Test::More; use lib 't/lib'; use DBICDHTest; use aliased 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator'; -use File::Spec::Functions qw(catfile splitdir); -use File::Path qw(rmtree mkpath); +use Path::Class qw(dir file); use File::Temp qw(tempfile tempdir); my $dbh = DBICDHTest::dbh(); @@ -42,9 +41,9 @@ VERSION2: { }); $dm->prepare_deploy; - mkpath(catfile(splitdir($sql_dir), qw(_preprocess_schema upgrade 1.0-2.0 ))); + dir($sql_dir, qw(_preprocess_schema upgrade 1.0-2.0 ))->mkpath; open my $prerun, '>', - catfile(splitdir($sql_dir), qw(_preprocess_schema upgrade 1.0-2.0 003-semiautomatic.pl )); + file($sql_dir, qw(_preprocess_schema upgrade 1.0-2.0 003-semiautomatic.pl )); my (undef, $fn) = tempfile(OPEN => 0); print {$prerun} qq^sub { diff --git a/t/lib/DBICDHTest.pm b/t/lib/DBICDHTest.pm index 22017e3..4d6e5c7 100644 --- a/t/lib/DBICDHTest.pm +++ b/t/lib/DBICDHTest.pm @@ -3,7 +3,6 @@ package DBICDHTest; use strict; use warnings; -use File::Path 'remove_tree'; use DBI; sub dbh { diff --git a/t/no-component-lib/DBICDHTest.pm b/t/no-component-lib/DBICDHTest.pm index f833c69..336d8ef 100644 --- a/t/no-component-lib/DBICDHTest.pm +++ b/t/no-component-lib/DBICDHTest.pm @@ -3,16 +3,6 @@ package DBICDHTest; use strict; use warnings; -use File::Path 'remove_tree'; -use Test::More; - -sub ready { - if (-d 't/sql') { - remove_tree('t/sql'); - mkdir 't/sql'; - } -} - sub dbh { DBI->connect('dbi:SQLite::memory:', undef, undef, { RaiseError => 1 }) }