diff --git a/Makefile.PL b/Makefile.PL index 1d6ea9f..f8c4539 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -14,7 +14,6 @@ requires 'Digest::MD5' => '2.39'; requires 'Hash::Merge' => '0.11'; requires 'List::MoreUtils' => '0.22'; requires 'Module::Runtime' => '0.013'; -requires 'Moose' => '1.10'; requires 'Moo' => '1.006'; requires 'namespace::clean'; requires 'Path::Class' => '0.21'; diff --git a/lib/Test/DBIx/Class.pm b/lib/Test/DBIx/Class.pm index 1af6b5f..c6dda54 100644 --- a/lib/Test/DBIx/Class.pm +++ b/lib/Test/DBIx/Class.pm @@ -1133,7 +1133,7 @@ to an already existing and populated database, set this option to false. =item traits -Traits are Ls that are applied to the class managing the connection +Traits are Ls that are applied to the class managing the connection to your database. If you leave this option blank and you don't specify anything for 'connect_info' (above), we automatically load the SQLite trait (which can be reviewed at L). This trait @@ -1387,7 +1387,7 @@ directory. =head1 TRAITS -As described, a trait is a L that is applied to the class +As described, a trait is a L that is applied to the class managing your database and test instance. Traits are installed by the 'traits' configuration option, which expects an ArrayRef as its input (however will also normalize a scalar to an ArrayRef). diff --git a/lib/Test/DBIx/Class/Role/FixtureCommand.pm b/lib/Test/DBIx/Class/Role/FixtureCommand.pm index fc44aa6..d736071 100755 --- a/lib/Test/DBIx/Class/Role/FixtureCommand.pm +++ b/lib/Test/DBIx/Class/Role/FixtureCommand.pm @@ -1,6 +1,6 @@ package Test::DBIx::Class::Role::FixtureCommand; { - use Moose::Role; + use Moo::Role; requires qw/install_fixtures/; has 'schema_manager' => ( diff --git a/lib/Test/DBIx/Class/SchemaManager.pm b/lib/Test/DBIx/Class/SchemaManager.pm index 7b6275b..15c2a94 100755 --- a/lib/Test/DBIx/Class/SchemaManager.pm +++ b/lib/Test/DBIx/Class/SchemaManager.pm @@ -1,8 +1,8 @@ package Test::DBIx::Class::SchemaManager; -use Moose::Util; use Test::More (); use List::MoreUtils qw(uniq); +use Moo::Role (); use Test::DBIx::Class::Types qw( :types :to ); use Types::Standard qw(Bool HashRef Str); @@ -197,7 +197,7 @@ sub initialize_schema { @traits = map { __PACKAGE__."::Trait::$_"} uniq @traits; $config->{traits} = \@traits; - my $self = Moose::Util::with_traits($class, @traits)->new($config) + my $self = Moo::Role->create_class_with_roles($class, @traits)->new($config) or return; $self->schema->storage->ensure_connected; diff --git a/lib/Test/DBIx/Class/SchemaManager/Trait/SQLite.pm b/lib/Test/DBIx/Class/SchemaManager/Trait/SQLite.pm index b6ae57c..aee46c5 100755 --- a/lib/Test/DBIx/Class/SchemaManager/Trait/SQLite.pm +++ b/lib/Test/DBIx/Class/SchemaManager/Trait/SQLite.pm @@ -1,8 +1,9 @@ package Test::DBIx::Class::SchemaManager::Trait::SQLite; { - - use Moose::Role; + use Test::DBIx::Class::Types qw(ConnectInfo); + use Moo::Role; + sub dbname { my ($self) = @_; diff --git a/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm b/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm index c32524e..0fddeb5 100755 --- a/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm +++ b/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm @@ -1,6 +1,5 @@ package Test::DBIx::Class::SchemaManager::Trait::Testmysqld; -use Moose::Role; use Test::mysqld; use Test::More (); use Path::Class qw(dir); @@ -10,21 +9,24 @@ use File::Temp qw(tempdir); use File::Path qw(make_path); use Types::Standard qw(ArrayRef HashRef Str); +use Moo::Role; + requires 'setup', 'cleanup'; ## has '+force_drop_table' => (is=>'rw',default=>1); -has base_dir => (is => 'ro', builder => '_build_base_dir'); +has base_dir => (is => 'ro', builder => 1,); sub _build_base_dir { $ENV{base_dir} || $ENV{BASE_DIR} } -has mysql_install_db => (is => 'ro', builder => '_build_mysql_install_db'); +has mysql_install_db => (is => 'ro', builder => 1,); sub _build_mysql_install_db { $ENV{mysql_install_db} || $ENV{MYSQL_INSTALL_DB} } -has mysqld => (is => 'ro', builder => '_build_mysqld'); +has mysqld => (is => 'ro', builder => 1,); sub _build_mysqld { $ENV{mysqld} || $ENV{MYSQLD} } has test_db_manager => ( is=>'ro', init_arg=>undef, - lazy_build=>1, + lazy=>1, + builder=>1, ); sub _build_test_db_manager { @@ -42,15 +44,14 @@ sub _build_test_db_manager { } } -has default_cnf => ( +has _default_cnf => ( is=>'ro', init_arg=>undef, isa=>HashRef, - auto_deref=>1, - lazy_build=>1, + lazy=>1, + builder=>1, ); - -sub _build_default_cnf { +sub _build__default_cnf { my $port = $_[0]->find_next_unused_port(); return { 'server-id'=>1, @@ -59,29 +60,67 @@ sub _build_default_cnf { 'port'=>$port, }; } +sub default_cnf { wantarray ? %{$_[0]->_default_cnf} : $_[0]->_default_cnf } + has port_to_try_first => ( - is=>'rw', - default=> sub { 8000 + int(rand(2000)) }, + is =>'rw', + builder => 1, ); +sub _build_port_to_try_first { 8000 + int(rand(2000)) } -has my_cnf => ( +has _my_cnf => ( is=>'ro', isa=>HashRef, - auto_deref=>1, + init_arg=>'my_cnf', ); +sub my_cnf { + my $self = shift; + if (not defined $self->{_my_cnf}) { + return wantarray ? () : undef; + } + return wantarray ? %{$self->_my_cnf} : $self->_my_cnf; +} ## Replicant stuff... probably should be a delegate -has deployed_replicants => (is=>'rw', isa=>ArrayRef, auto_deref=>1); +has _deployed_replicants => ( + is=>'rw', + isa=>ArrayRef, + init_arg=>'deployed_replicants', +); +sub deployed_replicants { + my $self = shift; + + return $self->_deployed_replicants(@_) if (@_); + + if (not defined $self->{_deployed_replicants}) { + return wantarray ? () : undef; + } + + return wantarray ? @{$self->_deployed_replicants} + : $self->_deployed_replicants; +} -has replicants => ( +has _replicants => ( is=>'rw', isa=>ReplicantsConnectInfo, coerce=>1, - auto_deref=>1, + init_arg=>'replicants', predicate=>'has_replicants', ); +sub replicants { + my $self = shift; + + my $ret = $self->_replicants; + return $self->_replicants(@_) if (@_); + + if (not defined $ret) { + return wantarray ? () : undef; + } + + return wantarray ? @$ret : $ret; +} has pool_args => ( is=>'ro', @@ -111,20 +150,34 @@ has balancer_args => ( }, ); -has default_replicant_cnf => ( +has _default_replicant_cnf => ( is=>'ro', init_arg=>undef, isa=>HashRef, - auto_deref=>1, + init_arg=>'default_replicant_cnf', required=>1, default=> sub { +{} }, ); +sub default_replicant_cnf { + my $self = shift; + if (not defined $self->{_default_replicant_cnf}) { + return wantarray ? () : undef; + } + return wantarray ? %{$self->_default_replicant_cnf} : $self->_default_replicant_cnf; +} -has my_replicant_cnf => ( +has _my_replicant_cnf => ( is=>'ro', isa=>HashRef, - auto_deref=>1, + init_arg=>'my_replicant_cnf', ); +sub my_replicant_cnf { + my $self = shift; + if (not defined $self->{_my_replicant_cnf}) { + return wantarray ? () : undef; + } + return wantarray ? %{$self->_my_replicant_cnf} : $self->_my_replicant_cnf; +} sub prepare_replicant_config { my ($self, $replicant, @replicants,%extra) = @_; diff --git a/lib/Test/DBIx/Class/SchemaManager/Trait/Testpostgresql.pm b/lib/Test/DBIx/Class/SchemaManager/Trait/Testpostgresql.pm index 0b63893..3a232e5 100755 --- a/lib/Test/DBIx/Class/SchemaManager/Trait/Testpostgresql.pm +++ b/lib/Test/DBIx/Class/SchemaManager/Trait/Testpostgresql.pm @@ -1,24 +1,26 @@ package Test::DBIx::Class::SchemaManager::Trait::Testpostgresql; { - - use Moose::Role; + use Test::PostgreSQL; use Test::More (); use Path::Class qw(dir); + use Moo::Role; + has postgresqlobj => ( is=>'ro', init_arg=>undef, - lazy_build=>1, + lazy=>1, + builder=>1, ); - has base_dir => ( is => 'ro', builder => '_build_base_dir' ); + has base_dir => ( is => 'ro', builder => 1 ); sub _build_base_dir { $ENV{base_dir} || $ENV{BASE_DIR} }; - has initdb => ( is => 'ro', builder => '_build_initdb' ); + has initdb => ( is => 'ro', builder => 1 ); sub _build_initdb { $ENV{initdb} || $ENV{INITDB} }; - has postmaster => ( is => 'ro', builder => '_build_postmaster' ); + has postmaster => ( is => 'ro', builder => 1 ); sub _build_postmaster { $ENV{postmaster} || $ENV{POSTMASTER} }; sub _build_postgresqlobj { @@ -75,11 +77,11 @@ package Test::DBIx::Class::SchemaManager::Trait::Testpostgresql; { } }; - override drop_table_sql => sub { + sub drop_table_sql { my $self = shift; my $table = shift; return "drop table $table cascade"; - }; + } } 1;