From 7d3107343f353160fdacf377de3c5dcaa1be2480 Mon Sep 17 00:00:00 2001 From: Fitz Elliott Date: Fri, 26 Sep 2014 16:50:22 -0400 Subject: [PATCH 1/4] switch from MooseX::Types to Type::Tiny --- Makefile.PL | 2 +- lib/Test/DBIx/Class/SchemaManager.pm | 21 +++++++++---------- .../Class/SchemaManager/Trait/Testmysqld.pm | 17 ++++++++------- lib/Test/DBIx/Class/Types.pm | 17 ++++++++------- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 4cfa1fc..eae8495 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -16,13 +16,13 @@ requires 'List::MoreUtils' => '0.22'; requires 'Module::Runtime' => '0.013'; requires 'Moose' => '1.10'; requires 'MooseX::Attribute::ENV' => '0.01'; -requires 'MooseX::Types' => '0.23'; requires 'Path::Class' => '0.21'; requires 'SQL::Translator' => '0.11006'; requires 'Scalar::Util' => '1.23'; requires 'Sub::Exporter' => '0.982'; requires 'Test::Builder' => '0.96'; requires 'Test::Deep' => '0.106'; +requires 'Type::Tiny' => '1.000002'; requires 'File::Temp'; requires 'File::Path'; diff --git a/lib/Test/DBIx/Class/SchemaManager.pm b/lib/Test/DBIx/Class/SchemaManager.pm index e0a99a4..c4e3849 100755 --- a/lib/Test/DBIx/Class/SchemaManager.pm +++ b/lib/Test/DBIx/Class/SchemaManager.pm @@ -5,32 +5,31 @@ use MooseX::Attribute::ENV; use Moose::Util; use Test::More (); use List::MoreUtils qw(uniq); -use Test::DBIx::Class::Types qw( - TestBuilder SchemaManagerClass FixtureClass ConnectInfo -); +use Test::DBIx::Class::Types qw( :types :to ); +use Types::Standard qw(Bool HashRef Str); has 'force_drop_table' => ( traits=>['ENV'], is=>'rw', - isa=>'Bool', required=>1, default=>0, + isa=>Bool, ); has [qw/keep_db tdbic_debug/] => ( traits=>['ENV'], is=>'ro', - isa=>'Bool', required=>1, default=>0, + isa=>Bool, ); has 'deploy_db' => ( traits=>['ENV'], is=>'ro', - isa=>'Bool', required=>1, default=>1, + isa=>Bool, ); has 'builder' => ( @@ -61,19 +60,19 @@ has 'connect_info' => ( has 'connect_opts' => ( is => 'ro', - isa => 'HashRef', + isa => HashRef, ); has 'deploy_opts' => ( is => 'ro', - isa => 'HashRef', + isa => HashRef, default => sub { {} }, ); has 'connect_info_with_opts' => ( is => 'ro', - isa => 'HashRef', lazy_build => 1, + isa => HashRef, ); has 'fixture_class' => ( @@ -93,12 +92,12 @@ has 'fixture_command' => ( has 'fixture_sets' => ( is => 'ro', - isa => 'HashRef', + isa => HashRef, ); has 'last_statement' => ( is=>'rw', - isa=>'Str', + isa=>Str, ); sub get_fixture_sets { diff --git a/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm b/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm index eb40290..5652f96 100755 --- a/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm +++ b/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm @@ -9,6 +9,7 @@ use Test::DBIx::Class::Types qw(ReplicantsConnectInfo); use Socket; use File::Temp qw(tempdir); use File::Path qw(make_path); +use Types::Standard qw(ArrayRef HashRef Str); requires 'setup', 'cleanup'; @@ -43,7 +44,7 @@ sub _build_test_db_manager { has default_cnf => ( is=>'ro', init_arg=>undef, - isa=>'HashRef', + isa=>HashRef, auto_deref=>1, lazy_build=>1, ); @@ -65,13 +66,13 @@ has port_to_try_first => ( has my_cnf => ( is=>'ro', - isa=>'HashRef', + isa=>HashRef, auto_deref=>1, ); ## Replicant stuff... probably should be a delegate -has deployed_replicants => (is=>'rw', isa=>'ArrayRef', auto_deref=>1); +has deployed_replicants => (is=>'rw', isa=>ArrayRef, auto_deref=>1); has replicants => ( is=>'rw', @@ -83,14 +84,14 @@ has replicants => ( has pool_args => ( is=>'ro', - isa=>'HashRef', + isa=>HashRef, required=>0, predicate=>'has_pool_args', ); has balancer_type => ( is=>'ro', - isa=>'Str', + isa=>Str, required=>1, predicate=>'has_balancer_type', default=>'::Random', @@ -98,7 +99,7 @@ has balancer_type => ( has balancer_args => ( is=>'ro', - isa=>'HashRef', + isa=>HashRef, required=>1, predicate=>'has_balancer_args', default=> sub { @@ -112,7 +113,7 @@ has balancer_args => ( has default_replicant_cnf => ( is=>'ro', init_arg=>undef, - isa=>'HashRef', + isa=>HashRef, auto_deref=>1, required=>1, default=> sub { +{} }, @@ -120,7 +121,7 @@ has default_replicant_cnf => ( has my_replicant_cnf => ( is=>'ro', - isa=>'HashRef', + isa=>HashRef, auto_deref=>1, ); diff --git a/lib/Test/DBIx/Class/Types.pm b/lib/Test/DBIx/Class/Types.pm index a04e95d..37ab0ee 100755 --- a/lib/Test/DBIx/Class/Types.pm +++ b/lib/Test/DBIx/Class/Types.pm @@ -3,17 +3,20 @@ package Test::DBIx::Class::Types; use strict; use warnings; -use Class::MOP; -use Scalar::Util qw(reftype); -use MooseX::Types::Moose qw(Str Int ClassName ArrayRef HashRef); -use MooseX::Types -declare => [qw/ +use Type::Library + -base, + -declare => qw( TestBuilder SchemaManagerClass ConnectInfo FixtureClass ReplicantsConnectInfo -/]; + ); +use Type::Utils -all; +use Types::Standard qw(Str Int ClassName ArrayRef HashRef); + use Module::Runtime qw(use_module); +use Scalar::Util qw(reftype); subtype TestBuilder, - as class_type('Test::Builder'); + as class_type({ class => 'Test::Builder'}); subtype SchemaManagerClass, as ClassName; @@ -111,7 +114,7 @@ Test::DBIx::Class::Types - Type Constraint Library =head1 DESCRIPTION -L based type constraint library +L based type constraint library =head1 AUTHOR From 5bbde4829fb3c44e2e1869af96973addf2cea355 Mon Sep 17 00:00:00 2001 From: Fitz Elliott Date: Fri, 26 Sep 2014 17:31:53 -0400 Subject: [PATCH 2/4] get rid of MooseX::Attribute::ENV --- Makefile.PL | 1 - lib/Test/DBIx/Class/SchemaManager.pm | 43 ++++++++++++++----- .../DBIx/Class/SchemaManager/Trait/SQLite.pm | 1 - .../Class/SchemaManager/Trait/Testmysqld.pm | 11 ++--- .../SchemaManager/Trait/Testpostgresql.pm | 12 +++--- 5 files changed, 45 insertions(+), 23 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index eae8495..761ee0c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -15,7 +15,6 @@ requires 'Hash::Merge' => '0.11'; requires 'List::MoreUtils' => '0.22'; requires 'Module::Runtime' => '0.013'; requires 'Moose' => '1.10'; -requires 'MooseX::Attribute::ENV' => '0.01'; requires 'Path::Class' => '0.21'; requires 'SQL::Translator' => '0.11006'; requires 'Scalar::Util' => '1.23'; diff --git a/lib/Test/DBIx/Class/SchemaManager.pm b/lib/Test/DBIx/Class/SchemaManager.pm index c4e3849..2274643 100755 --- a/lib/Test/DBIx/Class/SchemaManager.pm +++ b/lib/Test/DBIx/Class/SchemaManager.pm @@ -1,7 +1,6 @@ package Test::DBIx::Class::SchemaManager; use Moose; -use MooseX::Attribute::ENV; use Moose::Util; use Test::More (); use List::MoreUtils qw(uniq); @@ -9,28 +8,44 @@ use Test::DBIx::Class::Types qw( :types :to ); use Types::Standard qw(Bool HashRef Str); has 'force_drop_table' => ( - traits=>['ENV'], is=>'rw', required=>1, - default=>0, isa=>Bool, + builder => '_build_force_drop_table', ); +sub _build_force_drop_table { + $ENV{force_drop_table} || $ENV{FORCE_DROP_TABLE} || 0 +} -has [qw/keep_db tdbic_debug/] => ( - traits=>['ENV'], +has 'keep_db' => ( is=>'ro', + isa=>Bool, required=>1, - default=>0, + builder=>'_build_keep_db', +); +sub _build_keep_db { + $ENV{keep_db} || $ENV{KEEP_DB} || 0 +} + +has 'tdbic_debug' => ( + is=>'ro', isa=>Bool, + required=>1, + builder=>'_build_tdbic_debug', ); +sub _build_tdbic_debug { + $ENV{tdbic_debug} || $ENV{TDBIC_DEBUG} || 0 +} has 'deploy_db' => ( - traits=>['ENV'], is=>'ro', required=>1, - default=>1, isa=>Bool, + builder=>'_build_deploy_db', ); +sub _build_deploy_db { + $ENV{deploy_db} || $ENV{DEPLOY_DB} || 1 +} has 'builder' => ( is => 'ro', @@ -39,12 +54,16 @@ has 'builder' => ( ); has 'schema_class' => ( - traits => ['ENV'], is => 'ro', isa => SchemaManagerClass, required => 1, coerce => 1, + builder => '_build_schema_class', ); +sub _build_schema_class { + $ENV{schema_class} || $ENV{SCHEMA_CLASS} + || die '"schema_class" is a required parameter'; +} has 'schema' => ( is => 'ro', @@ -76,13 +95,15 @@ has 'connect_info_with_opts' => ( ); has 'fixture_class' => ( - traits => ['ENV'], is => 'ro', isa => FixtureClass, required => 1, coerce => 1, - default => '::Populate', + builder => '_build_fixture_class', ); +sub _build_fixture_class { + $ENV{fixture_class} || $ENV{FIXTURE_CLASS} || '::Populate' +} has 'fixture_command' => ( is => 'ro', diff --git a/lib/Test/DBIx/Class/SchemaManager/Trait/SQLite.pm b/lib/Test/DBIx/Class/SchemaManager/Trait/SQLite.pm index ddefe99..b6ae57c 100755 --- a/lib/Test/DBIx/Class/SchemaManager/Trait/SQLite.pm +++ b/lib/Test/DBIx/Class/SchemaManager/Trait/SQLite.pm @@ -1,7 +1,6 @@ package Test::DBIx::Class::SchemaManager::Trait::SQLite; { use Moose::Role; - use MooseX::Attribute::ENV; use Test::DBIx::Class::Types qw(ConnectInfo); sub dbname { diff --git a/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm b/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm index 5652f96..c32524e 100755 --- a/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm +++ b/lib/Test/DBIx/Class/SchemaManager/Trait/Testmysqld.pm @@ -1,7 +1,6 @@ package Test::DBIx::Class::SchemaManager::Trait::Testmysqld; use Moose::Role; -use MooseX::Attribute::ENV; use Test::mysqld; use Test::More (); use Path::Class qw(dir); @@ -15,10 +14,12 @@ requires 'setup', 'cleanup'; ## has '+force_drop_table' => (is=>'rw',default=>1); -has [qw/base_dir mysql_install_db mysqld/] => ( - is=>'ro', - traits=>['ENV'], -); +has base_dir => (is => 'ro', builder => '_build_base_dir'); +sub _build_base_dir { $ENV{base_dir} || $ENV{BASE_DIR} } +has mysql_install_db => (is => 'ro', builder => '_build_mysql_install_db'); +sub _build_mysql_install_db { $ENV{mysql_install_db} || $ENV{MYSQL_INSTALL_DB} } +has mysqld => (is => 'ro', builder => '_build_mysqld'); +sub _build_mysqld { $ENV{mysqld} || $ENV{MYSQLD} } has test_db_manager => ( is=>'ro', diff --git a/lib/Test/DBIx/Class/SchemaManager/Trait/Testpostgresql.pm b/lib/Test/DBIx/Class/SchemaManager/Trait/Testpostgresql.pm index ed8df79..0b63893 100755 --- a/lib/Test/DBIx/Class/SchemaManager/Trait/Testpostgresql.pm +++ b/lib/Test/DBIx/Class/SchemaManager/Trait/Testpostgresql.pm @@ -1,7 +1,6 @@ package Test::DBIx::Class::SchemaManager::Trait::Testpostgresql; { use Moose::Role; - use MooseX::Attribute::ENV; use Test::PostgreSQL; use Test::More (); use Path::Class qw(dir); @@ -13,11 +12,14 @@ package Test::DBIx::Class::SchemaManager::Trait::Testpostgresql; { lazy_build=>1, ); + has base_dir => ( is => 'ro', builder => '_build_base_dir' ); + sub _build_base_dir { $ENV{base_dir} || $ENV{BASE_DIR} }; - has [qw/base_dir initdb postmaster/] => ( - is=>'ro', - traits=>['ENV'], - ); + has initdb => ( is => 'ro', builder => '_build_initdb' ); + sub _build_initdb { $ENV{initdb} || $ENV{INITDB} }; + + has postmaster => ( is => 'ro', builder => '_build_postmaster' ); + sub _build_postmaster { $ENV{postmaster} || $ENV{POSTMASTER} }; sub _build_postgresqlobj { my ($self) = @_; From e416d30eeea000694c27b7c83061f97d5953f783 Mon Sep 17 00:00:00 2001 From: Fitz Elliott Date: Mon, 29 Sep 2014 10:48:03 -0400 Subject: [PATCH 3/4] convert use Moose to use Moo --- Makefile.PL | 2 ++ .../DBIx/Class/FixtureCommand/Populate.pm | 4 ++- .../DBIx/Class/FixtureCommand/PopulateMore.pm | 4 ++- lib/Test/DBIx/Class/SchemaManager.pm | 28 +++++++++++-------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 761ee0c..1d6ea9f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -15,6 +15,8 @@ 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'; requires 'SQL::Translator' => '0.11006'; requires 'Scalar::Util' => '1.23'; diff --git a/lib/Test/DBIx/Class/FixtureCommand/Populate.pm b/lib/Test/DBIx/Class/FixtureCommand/Populate.pm index 1ee881e..f0a04bb 100755 --- a/lib/Test/DBIx/Class/FixtureCommand/Populate.pm +++ b/lib/Test/DBIx/Class/FixtureCommand/Populate.pm @@ -1,8 +1,10 @@ package Test::DBIx::Class::FixtureCommand::Populate; { - use Moose; use Test::More (); + + use Moo; with 'Test::DBIx::Class::Role::FixtureCommand'; + use namespace::clean; sub install_fixtures { my ($self, $arg, @rest) = @_; diff --git a/lib/Test/DBIx/Class/FixtureCommand/PopulateMore.pm b/lib/Test/DBIx/Class/FixtureCommand/PopulateMore.pm index 94bf3bf..752ec2f 100644 --- a/lib/Test/DBIx/Class/FixtureCommand/PopulateMore.pm +++ b/lib/Test/DBIx/Class/FixtureCommand/PopulateMore.pm @@ -1,9 +1,11 @@ package Test::DBIx::Class::FixtureCommand::PopulateMore; { - use Moose; use Test::More (); use DBIx::Class::Schema::PopulateMore::Command; + + use Moo; with 'Test::DBIx::Class::Role::FixtureCommand'; + use namespace::clean; sub install_fixtures { my ($self, $arg, @rest) = @_; diff --git a/lib/Test/DBIx/Class/SchemaManager.pm b/lib/Test/DBIx/Class/SchemaManager.pm index 2274643..7b6275b 100755 --- a/lib/Test/DBIx/Class/SchemaManager.pm +++ b/lib/Test/DBIx/Class/SchemaManager.pm @@ -1,17 +1,19 @@ package Test::DBIx::Class::SchemaManager; -use Moose; use Moose::Util; use Test::More (); use List::MoreUtils qw(uniq); use Test::DBIx::Class::Types qw( :types :to ); use Types::Standard qw(Bool HashRef Str); +use Moo; +use namespace::clean; + has 'force_drop_table' => ( is=>'rw', required=>1, isa=>Bool, - builder => '_build_force_drop_table', + builder=>1, ); sub _build_force_drop_table { $ENV{force_drop_table} || $ENV{FORCE_DROP_TABLE} || 0 @@ -21,7 +23,7 @@ has 'keep_db' => ( is=>'ro', isa=>Bool, required=>1, - builder=>'_build_keep_db', + builder=>1, ); sub _build_keep_db { $ENV{keep_db} || $ENV{KEEP_DB} || 0 @@ -31,7 +33,7 @@ has 'tdbic_debug' => ( is=>'ro', isa=>Bool, required=>1, - builder=>'_build_tdbic_debug', + builder=>1, ); sub _build_tdbic_debug { $ENV{tdbic_debug} || $ENV{TDBIC_DEBUG} || 0 @@ -41,7 +43,7 @@ has 'deploy_db' => ( is=>'ro', required=>1, isa=>Bool, - builder=>'_build_deploy_db', + builder=>1, ); sub _build_deploy_db { $ENV{deploy_db} || $ENV{DEPLOY_DB} || 1 @@ -58,7 +60,7 @@ has 'schema_class' => ( isa => SchemaManagerClass, required => 1, coerce => 1, - builder => '_build_schema_class', + builder => 1, ); sub _build_schema_class { $ENV{schema_class} || $ENV{SCHEMA_CLASS} @@ -67,14 +69,16 @@ sub _build_schema_class { has 'schema' => ( is => 'ro', - lazy_build => 1, + lazy => 1, + builder => 1, ); has 'connect_info' => ( is => 'ro', isa => ConnectInfo, coerce => 1, - lazy_build => 1, + lazy => 1, + builder => 1, ); has 'connect_opts' => ( @@ -90,8 +94,9 @@ has 'deploy_opts' => ( has 'connect_info_with_opts' => ( is => 'ro', - lazy_build => 1, isa => HashRef, + lazy => 1, + builder => 1, ); has 'fixture_class' => ( @@ -99,7 +104,7 @@ has 'fixture_class' => ( isa => FixtureClass, required => 1, coerce => 1, - builder => '_build_fixture_class', + builder => 1, ); sub _build_fixture_class { $ENV{fixture_class} || $ENV{FIXTURE_CLASS} || '::Populate' @@ -108,7 +113,8 @@ sub _build_fixture_class { has 'fixture_command' => ( is => 'ro', init_arg => undef, - lazy_build => 1, + lazy => 1, + builder => 1, ); has 'fixture_sets' => ( From 93aca80cb44e82a0949117a364c524ffed9fdc91 Mon Sep 17 00:00:00 2001 From: Fitz Elliott Date: Mon, 29 Sep 2014 10:50:52 -0400 Subject: [PATCH 4/4] convert roles to Moo::Role --- Makefile.PL | 1 - lib/Test/DBIx/Class.pm | 4 +- lib/Test/DBIx/Class/Role/FixtureCommand.pm | 2 +- lib/Test/DBIx/Class/SchemaManager.pm | 4 +- .../DBIx/Class/SchemaManager/Trait/SQLite.pm | 5 +- .../Class/SchemaManager/Trait/Testmysqld.pm | 95 +++++++++++++++---- .../SchemaManager/Trait/Testpostgresql.pm | 18 ++-- 7 files changed, 92 insertions(+), 37 deletions(-) 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;