From: Arthur Axel 'fREW' Schmidt Date: Tue, 23 Feb 2010 16:24:57 +0000 (-0600) Subject: coercion for database list X-Git-Tag: v0.001000_01~139 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cf400f483c5280a6d302f715b0d730ae829a4523;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git coercion for database list --- diff --git a/lib/DBIx/Class/DeploymentHandler.pm b/lib/DBIx/Class/DeploymentHandler.pm index 2e2950a..e78d07f 100644 --- a/lib/DBIx/Class/DeploymentHandler.pm +++ b/lib/DBIx/Class/DeploymentHandler.pm @@ -8,6 +8,17 @@ require DBIx::Class::ResultSet; # loaded for type constraint use Carp::Clan '^DBIx::Class::DeploymentHandler'; use SQL::Translator; +BEGIN { + use Moose::Util::TypeConstraints; + subtype 'DBIx::Class::DeploymentHandler::Databases' + => as 'ArrayRef[Str]'; + + coerce 'DBIx::Class::DeploymentHandler::Databases' + => from 'Str' + => via { [$_] }; + no Moose::Util::TypeConstraints; +} + has schema => ( isa => 'DBIx::Class::Schema', is => 'ro', @@ -64,9 +75,9 @@ has version_rs => ( ); has databases => ( - # make this coerce from Str - isa => 'ArrayRef[Str]', - is => 'ro', + coerce => 1, + isa => 'DBIx::Class::DeploymentHandler::Databases', + is => 'ro', default => sub { [qw( MySQL SQLite PostgreSQL )] }, ); diff --git a/t/02-instantiation.t b/t/02-instantiation.t index 57e141a..60d5216 100644 --- a/t/02-instantiation.t +++ b/t/02-instantiation.t @@ -19,7 +19,7 @@ VERSION1: { my $handler = DBIx::Class::DeploymentHandler->new({ upgrade_directory => $sql_dir, schema => $s, - databases => ['SQLite'], + databases => 'SQLite', }); ok($handler, 'DBIx::Class::DeploymentHandler w/1.0 instantiates correctly'); @@ -48,7 +48,7 @@ VERSION2: { my $handler = DBIx::Class::DeploymentHandler->new({ upgrade_directory => $sql_dir, schema => $s, - databases => ['SQLite'], + databases => 'SQLite', }); ok($handler, 'DBIx::Class::DeploymentHandler w/2.0 instantiates correctly'); @@ -87,7 +87,7 @@ VERSION3: { my $handler = DBIx::Class::DeploymentHandler->new({ upgrade_directory => $sql_dir, schema => $s, - databases => ['SQLite'], + databases => 'SQLite', }); ok($handler, 'DBIx::Class::DeploymentHandler w/3.0 instantiates correctly');