diff --git a/Changes b/Changes index 20f9f1d..2da416a 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,7 @@ Revision history for DBIx-Class-Migration. - update DBIx::Class::DeploymentHandler dep to 0.002222 - thanks @KES777 for report - POD improvements - thanks @manwar - use Log::Any for errors - thanks @upasana-me + - coerce target_dir to absolute to work right on 5.26+ 0.061 2019-02-25 - POD improvements - thanks @n7st and @willsheppard diff --git a/lib/DBIx/Class/Migration.pm b/lib/DBIx/Class/Migration.pm index 9cf6c68..2cde6bb 100644 --- a/lib/DBIx/Class/Migration.pm +++ b/lib/DBIx/Class/Migration.pm @@ -8,7 +8,10 @@ use JSON::MaybeXS qw(JSON); use File::Copy 'cp'; use File::Spec::Functions 'catdir', 'catfile', 'updir'; use File::Path 'mkpath', 'remove_tree'; -use DBIx::Class::Migration::Types 'LoadableClass', 'LoadableDBICSchemaClass'; +use DBIx::Class::Migration::Types qw( + LoadableClass LoadableDBICSchemaClass + AbsolutePath +); use Class::Load 'load_class'; use Devel::PartialDump; use SQL::Translator; @@ -99,7 +102,7 @@ has target_dir_builder => ( is => 'ro', lazy_build => 1); ->new(schema_class=>$inferred_schema_class); } -has target_dir => (is=>'ro', isa=>'Str', lazy_build=>1); +has target_dir => (is => 'ro', isa=> AbsolutePath, coerce => 1, lazy_build=>1); sub _build_target_dir { shift->target_dir_builder->build; diff --git a/lib/DBIx/Class/Migration/Script.pm b/lib/DBIx/Class/Migration/Script.pm index 309e003..abd6017 100644 --- a/lib/DBIx/Class/Migration/Script.pm +++ b/lib/DBIx/Class/Migration/Script.pm @@ -4,7 +4,9 @@ use Moose; use MooseX::Attribute::ENV; use Pod::Find (); use Pod::Usage (); -use DBIx::Class::Migration::Types 'LoadableClass', 'ArraySQLTProducers'; +use DBIx::Class::Migration::Types qw( + LoadableClass ArraySQLTProducers AbsolutePath +); use Log::Any; use Carp 'croak'; @@ -45,7 +47,8 @@ has schema => (is=>'ro', predicate=>'has_schema'); has schema_class => (traits => [ 'Getopt', 'ENV' ], is => 'ro', isa => 'Str', predicate=>'has_schema_class', env_prefix=>ENV_PREFIX, cmd_aliases => 'S'); -has target_dir => (traits => [ 'Getopt', 'ENV' ], is => 'ro', isa=> 'Str', +has target_dir => (traits => [ 'Getopt', 'ENV' ], + is => 'ro', isa=> AbsolutePath, coerce => 1, predicate=>'has_target_dir', env_prefix=>ENV_PREFIX, cmd_aliases => 'dir'); has sandbox_dir => (traits => [ 'Getopt', 'ENV' ], is => 'ro', isa=> 'Str', diff --git a/lib/DBIx/Class/Migration/Types.pm b/lib/DBIx/Class/Migration/Types.pm index 86bfbd5..64eaf4a 100644 --- a/lib/DBIx/Class/Migration/Types.pm +++ b/lib/DBIx/Class/Migration/Types.pm @@ -14,9 +14,14 @@ package #hide from PAUSE use MooseX::Types::LoadableClass 'LoadableClass'; use MooseX::Types::Moose 'Str', 'ClassName', 'ArrayRef'; -use MooseX::Types -declare => [ 'LoadableDBICSchemaClass', 'SQLTProducer', 'ArraySQLTProducers' ]; +use MooseX::Types -declare => [ + 'LoadableDBICSchemaClass', + 'SQLTProducer', 'ArraySQLTProducers', + 'AbsolutePath', +]; use Module::Find (); use MooseX::Getopt::OptionTypeMap (); +use File::Spec::Functions 'file_name_is_absolute', 'rel2abs'; subtype LoadableDBICSchemaClass, as LoadableClass, @@ -48,6 +53,15 @@ MooseX::Getopt::OptionTypeMap->add_option_type_to_map( ArraySQLTProducers() => '=s@' ); +subtype AbsolutePath, + as Str, + where { file_name_is_absolute $_ }, + ; +coerce AbsolutePath, + from Str, + via { rel2abs $_ }, + ; + 1; =head1 NAME diff --git a/t/migration-postgresql.t b/t/migration-postgresql.t index 2ec7eee..70b31dc 100644 --- a/t/migration-postgresql.t +++ b/t/migration-postgresql.t @@ -13,9 +13,8 @@ use File::Spec::Functions 'catfile'; use File::Path 'rmtree'; use Test::Requires qw(Test::Postgresql58); use File::Temp 'tempdir'; -use Cwd 'abs_path'; # if no abs_path, need "." in @INC -my $dir = tempdir(DIR => abs_path('t'), CLEANUP => 1); +my $dir = tempdir(DIR => 't', CLEANUP => 1); ok( my $migration = DBIx::Class::Migration->new( diff --git a/t/migration-sqlite.t b/t/migration-sqlite.t index 775eda1..f3ae84a 100644 --- a/t/migration-sqlite.t +++ b/t/migration-sqlite.t @@ -8,9 +8,8 @@ use DBIx::Class::Migration; use File::Spec::Functions 'catfile'; use File::Path 'rmtree'; use File::Temp 'tempdir'; -use Cwd 'abs_path'; # if no abs_path, need "." in @INC -my $dir = tempdir(DIR => abs_path('t'), CLEANUP => 1); +my $dir = tempdir(DIR => 't', CLEANUP => 1); ok( my $migration = DBIx::Class::Migration->new( diff --git a/t/upgrade-downgrade-sqlite.t b/t/upgrade-downgrade-sqlite.t index 0456466..6898fc2 100644 --- a/t/upgrade-downgrade-sqlite.t +++ b/t/upgrade-downgrade-sqlite.t @@ -7,9 +7,8 @@ use Test::Most; use DBIx::Class::Migration; use File::Spec::Functions 'catfile'; use File::Temp 'tempdir'; -use Cwd 'abs_path'; # if no abs_path, need "." in @INC -my $dir = tempdir(DIR => abs_path('t'), CLEANUP => 1); +my $dir = tempdir(DIR => 't', CLEANUP => 1); my ($target_dir, $schema_args); # Outer Scope so we can reuse