File::Path = 2.08
DBIx::Class = 0.08121
Moose = 1.0
+Moo = 1.0
+MooX::Types::MooseLike = 0.04
+Package::Variant = 0
+Module::Runtime = 0
MooseX::Role::Parameterized = 0.18
Try::Tiny = 0
SQL::Translator = 0.11005
use Moose;
extends 'DBIx::Class::DeploymentHandler::Dad';
+use DBIx::Class::DeploymentHandler::WithApplicatorDumple2;
# a single with would be better, but we can't do that
# see: http://rt.cpan.org/Public/Bug/Display.html?id=46347
-with 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
+with WithApplicatorDumple2(
interface_role => 'DBIx::Class::DeploymentHandler::HandlesDeploy',
class_name => 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator',
delegate_name => 'deploy_method',
attributes_to_copy => [qw(
ignore_ddl databases script_directory sql_translator_args force_overwrite
)],
- },
- 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
+ ),
+ WithApplicatorDumple2(
interface_role => 'DBIx::Class::DeploymentHandler::HandlesVersioning',
class_name => 'DBIx::Class::DeploymentHandler::VersionHandler::Monotonic',
delegate_name => 'version_handler',
attributes_to_assume => [qw( database_version schema_version to_version )],
- },
- 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
+ ),
+ WithApplicatorDumple2(
interface_role => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
class_name => 'DBIx::Class::DeploymentHandler::VersionStorage::Standard',
delegate_name => 'version_storage',
attributes_to_assume => ['schema'],
- };
+ );
with 'DBIx::Class::DeploymentHandler::WithReasonableDefaults';
sub prepare_version_storage_install {
# ABSTRACT: Parent class for DeploymentHandlers
-use Moose;
-require DBIx::Class::Schema; # loaded for type constraint
+use Moo;
use Carp::Clan '^DBIx::Class::DeploymentHandler';
use DBIx::Class::DeploymentHandler::LogImporter ':log';
-use DBIx::Class::DeploymentHandler::Types;
+use DBIx::Class::DeploymentHandler::Types 'StrSchemaVersion';
+use MooX::Types::MooseLike::Base qw(Str);
has schema => (
is => 'ro',
);
has backup_directory => (
- isa => 'Str',
+ isa => Str,
is => 'ro',
predicate => 'has_backup_directory',
);
has to_version => (
is => 'ro',
- isa => 'Str',
- lazy_build => 1,
+ isa => Str,
+ builder => '_build_to_version',
);
sub _build_to_version { $_[0]->schema_version }
has schema_version => (
is => 'ro',
- isa => 'StrSchemaVersion',
- lazy_build => 1,
+ isa => StrSchemaVersion,
+ builder => '_build_schema_version',
);
sub _build_schema_version { $_[0]->schema->schema_version }
$self->schema->storage->backup($self->backup_directory)
}
-__PACKAGE__->meta->make_immutable;
-
1;
# vim: ts=2 sw=2 expandtab
package DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator;
-use Moose;
+use Moo;
# ABSTRACT: Manage your SQL and Perl migrations in nicely laid out directories
+use Sub::Quote 'quote_sub';
+use MooX::Types::MooseLike::Base qw(ArrayRef Bool HashRef Str);
+
use autodie;
use Carp qw( carp croak );
use DBIx::Class::DeploymentHandler::LogImporter qw(:log :dlog);
use SQL::Translator;
require SQL::Translator::Diff;
-require DBIx::Class::Storage; # loaded for type constraint
-use DBIx::Class::DeploymentHandler::Types;
+use DBIx::Class::DeploymentHandler::Types 'Storage';
use File::Path 'mkpath';
use File::Spec::Functions;
with 'DBIx::Class::DeploymentHandler::HandlesDeploy';
has ignore_ddl => (
- isa => 'Bool',
+ isa => Bool,
is => 'ro',
- default => undef,
);
has force_overwrite => (
- isa => 'Bool',
+ isa => Bool,
is => 'ro',
- default => undef,
);
has schema => (
);
has storage => (
- isa => 'DBIx::Class::Storage',
+ isa => Storage,
is => 'ro',
- lazy_build => 1,
+ builder => '_build_storage',
);
sub _build_storage {
}
has sql_translator_args => (
- isa => 'HashRef',
+ isa => HashRef,
is => 'ro',
- default => sub { {} },
+ default => quote_sub(q( {} )),
);
+
has script_directory => (
- isa => 'Str',
+ isa => Str,
is => 'ro',
- required => 1,
- default => 'sql',
+ default => quote_sub(q{ 'sql' }),
);
has databases => (
- coerce => 1,
- isa => 'DBIx::Class::DeploymentHandler::Databases',
is => 'ro',
- default => sub { [qw( MySQL SQLite PostgreSQL )] },
+ #isa => ArrayRef[Str],
+ #coerce => quote_sub(q{
+ #if (ref(\$_[0]) eq 'SCALAR') {
+ #return [$_[0]]
+ #} else {
+ #return $_[0]
+ #}
+ #}),
+ default => quote_sub(q{ [qw( MySQL SQLite PostgreSQL )] }),
);
has txn_wrap => (
is => 'ro',
- isa => 'Bool',
- default => 1,
+ isa => Bool,
+ default => quote_sub(q{ 1 }),
);
has schema_version => (
is => 'ro',
- isa => 'Str',
- lazy_build => 1,
+ isa => Str,
+ builder => '_build_schema_version',
);
# this will probably never get called as the DBICDH
my $from_file = shift;
my $to_file = shift;
my $dir = $self->script_directory;
- my $databases = $self->databases;
+ my $databases = ref $self->databases ? $self->databases : [$self->databases];
my $version = $self->schema_version;
foreach my $db (@$databases) {
sub _prepare_changegrade {
my ($self, $from_version, $to_version, $version_set, $direction) = @_;
my $schema = $self->schema;
- my $databases = $self->databases;
+ my $databases = ref $self->databases ? $self->databases : [$self->databases];
my $dir = $self->script_directory;
my $schema_version = $self->schema_version;
package DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::Deprecated;
-use Moose;
+use Moo;
# ABSTRACT: (DEPRECATED) Use this if you are stuck in the past
return [$self->_ddl_schema_up_produce_filename($type, $versions)]
}
-__PACKAGE__->meta->make_immutable;
-
1;
# vim: ts=2 sw=2 expandtab
use Moose::Util 'apply_all_roles';
extends 'DBIx::Class::DeploymentHandler::Dad';
+use DBIx::Class::DeploymentHandler::WithApplicatorDumple2;
# a single with would be better, but we can't do that
# see: http://rt.cpan.org/Public/Bug/Display.html?id=46347
-with 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
+with WithApplicatorDumple2(
interface_role => 'DBIx::Class::DeploymentHandler::HandlesDeploy',
class_name => 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::Deprecated',
delegate_name => 'deploy_method',
attributes_to_assume => ['schema'],
attributes_to_copy => [qw( script_directory databases sql_translator_args )],
- },
- 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
+ ),
+ WithApplicatorDumple2(
interface_role => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
class_name => 'DBIx::Class::DeploymentHandler::VersionStorage::Deprecated',
delegate_name => 'version_storage',
attributes_to_assume => ['schema'],
- };
+ );
with 'DBIx::Class::DeploymentHandler::WithReasonableDefaults';
sub BUILD {
if ($self->schema->can('ordered_versions') && $self->schema->ordered_versions) {
apply_all_roles(
$self,
- 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
+ WithApplicatorDumple2(
interface_role => 'DBIx::Class::DeploymentHandler::HandlesVersioning',
class_name => 'DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions',
delegate_name => 'version_handler',
attributes_to_assume => [qw( database_version schema_version to_version )],
- }
+ )
);
} else {
apply_all_roles(
$self,
- 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
+ WithApplicatorDumple2(
interface_role => 'DBIx::Class::DeploymentHandler::HandlesVersioning',
class_name => 'DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions',
delegate_name => 'version_handler',
attributes_to_assume => [qw( database_version schema_version to_version )],
- }
+ )
);
}
# the following is just a hack so that ->version_storage
package DBIx::Class::DeploymentHandler::HandlesDeploy;
-use Moose::Role;
+use Moo::Role;
# ABSTRACT: Interface for deploy methods
package DBIx::Class::DeploymentHandler::HandlesVersionStorage;
-use Moose::Role;
+use Moo::Role;
# ABSTRACT: Interface for version storage methods
package DBIx::Class::DeploymentHandler::HandlesVersioning;
-use Moose::Role;
+use Moo::Role;
# ABSTRACT: Interface for version methods
# ABSTRACT: Types internal to DBIx::Class::DeploymentHandler
-use Moose::Util::TypeConstraints;
-subtype 'DBIx::Class::DeploymentHandler::Databases'
- => as 'ArrayRef[Str]';
-
-coerce 'DBIx::Class::DeploymentHandler::Databases'
- => from 'Str'
- => via { [$_] };
-
-subtype 'StrSchemaVersion'
- => as 'Str'
- => message {
- defined $_
- ? "Schema version (currently '$_') must be a string"
- : 'Schema version must be defined'
- };
-
-no Moose::Util::TypeConstraints;
+use Sub::Quote 'quote_sub';
+
+use Sub::Exporter -setup => {
+ exports => [ qw(Storage ResultSet StrSchemaVersion) ],
+};
+
+sub ResultSet {
+quote_sub(q{
+ use Check::ISA;
+ obj($_[0], 'DBIx::Class::ResultSet')
+ or die 'version_rs should be a DBIx::Class::ResultSet!'
+ })
+}
+
+sub Storage {
+quote_sub(q{
+ use Check::ISA;
+ obj($_[0], 'DBIx::Class::Storage')
+ or die 'storage should be a DBIx::Class::Storage!'
+ })
+}
+
+sub StrSchemaVersion {
+ quote_sub(q{
+ die(defined $_[0]
+ ? "Schema version (currently '$_[0]') must be a string"
+ : 'Schema version must be defined'
+ ) unless ref(\$_[0]) eq 'SCALAR'
+ })
+}
+
1;
# vim: ts=2 sw=2 expandtab
package DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions;
-use Moose;
+use Moo;
+use Sub::Quote 'quote_sub';
+use MooX::Types::MooseLike::Base qw(Str Bool);
# ABSTRACT: Go straight from Database to Schema version
with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
has schema_version => (
- isa => 'Str',
+ isa => Str,
is => 'ro',
required => 1,
);
has database_version => (
- isa => 'Str',
+ isa => Str,
is => 'ro',
required => 1,
);
has to_version => ( # configuration
- is => 'ro',
- isa => 'Str',
- lazy_build => 1,
+ is => 'ro',
+ isa => Str,
+ builder => '_build_to_version',
);
sub _build_to_version { $_[0]->schema_version }
has once => (
is => 'rw',
- isa => 'Bool',
- default => undef,
+ isa => Bool,
+ default => quote_sub(q{undef}),
);
sub next_version_set {
return [$self->database_version, $self->to_version];
}
-
-__PACKAGE__->meta->make_immutable;
-
1;
# vim: ts=2 sw=2 expandtab
package DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions;
-use Moose;
+use Moo;
+use MooX::Types::MooseLike::Base qw(Str ArrayRef Int HashRef);
# ABSTRACT: Define your own list of versions to use for migrations
with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
has schema_version => (
- isa => 'Str',
+ isa => Str,
is => 'ro',
required => 1,
);
has database_version => (
- isa => 'Str',
+ isa => Str,
is => 'ro',
required => 1,
);
has to_version => (
is => 'ro',
- isa => 'Str',
- lazy_build => 1,
+ isa => Str,
+ builder => '_build_to_version',
+ lazy => 1,
);
sub _build_to_version { $_[0]->schema_version }
has ordered_versions => (
is => 'ro',
- isa => 'ArrayRef',
+ isa => ArrayRef,
required => 1,
);
has _index_of_versions => (
is => 'ro',
- isa => 'HashRef',
- lazy_build => 1,
+ isa => HashRef,
+ builder => '_build__index_of_versions',
+ lazy => 1,
);
sub _build__index_of_versions {
has _version_idx => (
is => 'rw',
- isa => 'Int',
- lazy_build => 1,
+ isa => Int,
+ builder => '_build__version_idx',
+ lazy => 1,
);
sub _build__version_idx { $_[0]->_index_of_versions->{$_[0]->database_version} }
}
}
-__PACKAGE__->meta->make_immutable;
-
1;
# vim: ts=2 sw=2 expandtab
package DBIx::Class::DeploymentHandler::VersionHandler::Monotonic;
-use Moose;
+use Moo;
+use MooX::Types::MooseLike::Base qw(Int);
# ABSTRACT: Obvious version progressions
with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
has schema_version => (
- isa => 'Int',
+ isa => Int,
is => 'ro',
required => 1,
);
has database_version => (
- isa => 'Int',
+ isa => Int,
is => 'ro',
required => 1,
);
has to_version => (
- isa => 'Int',
+ isa => Int,
is => 'ro',
- lazy_build => 1,
+ lazy => 1,
+ builder => '_build_to_version',
);
sub _build_to_version { $_[0]->schema_version }
has _version => (
is => 'rw',
- isa => 'Int',
- lazy_build => 1,
+ isa => Int,
+ lazy => 1,
+ builder => '_build__version',
);
sub _inc_version { $_[0]->_version($_[0]->_version + 1 ) }
}
}
-__PACKAGE__->meta->make_immutable;
-
1;
# vim: ts=2 sw=2 expandtab
package DBIx::Class::DeploymentHandler::VersionStorage::Deprecated;
-use Moose;
+use Moo;
+use Sub::Quote 'quote_sub';
use DBIx::Class::DeploymentHandler::LogImporter ':log';
-
+use DBIx::Class::DeploymentHandler::Types 'ResultSet';
# ABSTRACT: (DEPRECATED) Use this if you are stuck in the past
);
has version_rs => (
- isa => 'DBIx::Class::ResultSet',
+ isa => ResultSet,
is => 'ro',
builder => '_build_version_rs',
handles => [qw( database_version version_storage_is_installed )],
$_[0]->version_rs->search({ version => $version})->delete
}
-__PACKAGE__->meta->make_immutable;
-
1;
# vim: ts=2 sw=2 expandtab
package DBIx::Class::DeploymentHandler::VersionStorage::Standard;
-use Moose;
+use Moo;
use DBIx::Class::DeploymentHandler::LogImporter ':log';
+use DBIx::Class::DeploymentHandler::Types 'ResultSet';
# ABSTRACT: Version storage that does the normal stuff
);
has version_rs => (
- isa => 'DBIx::Class::ResultSet',
+ isa => ResultSet,
is => 'ro',
builder => '_build_version_rs',
handles => [qw( database_version version_storage_is_installed )],
$_[0]->version_rs->search({ version => $version})->delete
}
-__PACKAGE__->meta->make_immutable;
-
1;
# vim: ts=2 sw=2 expandtab
--- /dev/null
+package DBIx::Class::DeploymentHandler::WithApplicatorDumple2;
+
+use strict;
+use warnings;
+
+use Package::Variant
+ importing => {
+ 'Module::Runtime' => ['require_module'],
+ 'Moose::Role' => [],
+ },
+ subs => [qw(has require_module)];
+
+sub make_variant {
+ my ($class, $target, %args) = @_;
+
+ my $interface_role = $args{interface_role}
+ or die 'interface_role is required!';
+
+ my $class_name = $args{class_name}
+ or die 'class_name is required!';
+
+ my $delegate_name = $args{delegate_name}
+ or die 'delegate_name is required!';
+
+ my $attributes_to_copy = $args{attributes_to_copy} || [];
+ my $attributes_to_assume = $args{attributes_to_assume} || [];
+
+ require_module($class_name);
+
+ my $meta = Class::MOP::class_of($class_name);
+
+ has($_->name => %{ $_->clone })
+ for grep { $_ } map $meta->find_attribute_by_name($_), @{ $attributes_to_copy };
+
+ has($delegate_name => (
+ is => 'ro',
+ lazy_build => 1,
+ does => $interface_role,
+ handles => $interface_role,
+ ));
+
+ install '_build_'.$delegate_name => sub {
+ my $self = shift;
+
+ $class_name->new({
+ map { $_ => $self->$_ }
+ @{ $attributes_to_assume },
+ @{ $attributes_to_copy },
+ })
+ };
+};
+
+1;
+
+# vim: ts=2 sw=2 expandtab
+
+__END__
package DBIx::Class::DeploymentHandler::WithReasonableDefaults;
-use Moose::Role;
+use Moo::Role;
# ABSTRACT: Make default arguments to a few methods sensible