Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moo Conversion #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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 'MooseX::Attribute::ENV' => '0.01';
requires 'MooseX::Types' => '0.23';
requires 'Moo' => '1.006';
requires 'namespace::clean';
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';

Expand Down
4 changes: 2 additions & 2 deletions lib/Test/DBIx/Class.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ to an already existing and populated database, set this option to false.

=item traits

Traits are L<Moose::Role>s that are applied to the class managing the connection
Traits are L<Moo::Role>s 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<Test::DBIx::Class::SchemaManager::Trait::SQLite>). This trait
Expand Down Expand Up @@ -1387,7 +1387,7 @@ directory.

=head1 TRAITS

As described, a trait is a L<Moose::Role> that is applied to the class
As described, a trait is a L<Moo::Role> 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).
Expand Down
4 changes: 3 additions & 1 deletion lib/Test/DBIx/Class/FixtureCommand/Populate.pm
Original file line number Diff line number Diff line change
@@ -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) = @_;
Expand Down
4 changes: 3 additions & 1 deletion lib/Test/DBIx/Class/FixtureCommand/PopulateMore.pm
Original file line number Diff line number Diff line change
@@ -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) = @_;
Expand Down
2 changes: 1 addition & 1 deletion lib/Test/DBIx/Class/Role/FixtureCommand.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package Test::DBIx::Class::Role::FixtureCommand; {

use Moose::Role;
use Moo::Role;
requires qw/install_fixtures/;

has 'schema_manager' => (
Expand Down
84 changes: 55 additions & 29 deletions lib/Test/DBIx/Class/SchemaManager.pm
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
package Test::DBIx::Class::SchemaManager;

use Moose;
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 Moo::Role ();
use Test::DBIx::Class::Types qw( :types :to );
use Types::Standard qw(Bool HashRef Str);

use Moo;
use namespace::clean;

has 'force_drop_table' => (
traits=>['ENV'],
is=>'rw',
isa=>'Bool',
required=>1,
default=>0,
isa=>Bool,
builder=>1,
);
sub _build_force_drop_table {
$ENV{force_drop_table} || $ENV{FORCE_DROP_TABLE} || 0
}

has 'keep_db' => (
is=>'ro',
isa=>Bool,
required=>1,
builder=>1,
);
sub _build_keep_db {
$ENV{keep_db} || $ENV{KEEP_DB} || 0
}

has [qw/keep_db tdbic_debug/] => (
traits=>['ENV'],
has 'tdbic_debug' => (
is=>'ro',
isa=>'Bool',
isa=>Bool,
required=>1,
default=>0,
builder=>1,
);
sub _build_tdbic_debug {
$ENV{tdbic_debug} || $ENV{TDBIC_DEBUG} || 0
}

has 'deploy_db' => (
traits=>['ENV'],
is=>'ro',
isa=>'Bool',
required=>1,
default=>1,
isa=>Bool,
builder=>1,
);
sub _build_deploy_db {
$ENV{deploy_db} || $ENV{DEPLOY_DB} || 1
}

has 'builder' => (
is => 'ro',
Expand All @@ -40,65 +56,75 @@ has 'builder' => (
);

has 'schema_class' => (
traits => ['ENV'],
is => 'ro',
isa => SchemaManagerClass,
required => 1,
coerce => 1,
builder => 1,
);
sub _build_schema_class {
$ENV{schema_class} || $ENV{SCHEMA_CLASS}
|| die '"schema_class" is a required parameter';
}

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' => (
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,
lazy => 1,
builder => 1,
);

has 'fixture_class' => (
traits => ['ENV'],
is => 'ro',
isa => FixtureClass,
required => 1,
coerce => 1,
default => '::Populate',
builder => 1,
);
sub _build_fixture_class {
$ENV{fixture_class} || $ENV{FIXTURE_CLASS} || '::Populate'
}

has 'fixture_command' => (
is => 'ro',
init_arg => undef,
lazy_build => 1,
lazy => 1,
builder => 1,
);

has 'fixture_sets' => (
is => 'ro',
isa => 'HashRef',
isa => HashRef,
);

has 'last_statement' => (
is=>'rw',
isa=>'Str',
isa=>Str,
);

sub get_fixture_sets {
Expand Down Expand Up @@ -171,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;
Expand Down
6 changes: 3 additions & 3 deletions lib/Test/DBIx/Class/SchemaManager/Trait/SQLite.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package Test::DBIx::Class::SchemaManager::Trait::SQLite; {

use Moose::Role;
use MooseX::Attribute::ENV;

use Test::DBIx::Class::Types qw(ConnectInfo);

use Moo::Role;

sub dbname {
my ($self) = @_;

Expand Down
Loading