From: Arthur Axel 'fREW' Schmidt Date: Thu, 6 May 2010 01:12:35 +0000 (-0500) Subject: initial parameterised role to get rid of WithFoos X-Git-Tag: v0.001000_07~22 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9f552252915d0b6cb4e369946aa6cb979990afe4;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git initial parameterised role to get rid of WithFoos --- diff --git a/lib/DBIx/Class/DeploymentHandler.pm b/lib/DBIx/Class/DeploymentHandler.pm index 2a37231..d7583c1 100644 --- a/lib/DBIx/Class/DeploymentHandler.pm +++ b/lib/DBIx/Class/DeploymentHandler.pm @@ -8,8 +8,25 @@ extends 'DBIx::Class::DeploymentHandler::Dad'; # 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::WithSqltDeployMethod', - 'DBIx::Class::DeploymentHandler::WithMonotonicVersions', - 'DBIx::Class::DeploymentHandler::WithStandardVersionStorage'; + #'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => { + #interface_role => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage', + #class_name => 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator', + #delegate_name => 'deploy_method', + #attributes_to_assume => ['schema'], + #attributes_to_copy => [qw( databases upgrade_directory sql_translator_args )], + #}, + 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => { + 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' => { + 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 { diff --git a/lib/DBIx/Class/DeploymentHandler/WithApplicatorDumple.pm b/lib/DBIx/Class/DeploymentHandler/WithApplicatorDumple.pm new file mode 100644 index 0000000..971c994 --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/WithApplicatorDumple.pm @@ -0,0 +1,69 @@ +package DBIx::Class::DeploymentHandler::WithApplicatorDumple; +use MooseX::Role::Parameterized; +use Class::MOP; +use namespace::autoclean; + +parameter interface_role => ( + isa => 'Str', + required => 1, +); + +parameter class_name => ( + isa => 'Str', + required => 1, +); + +parameter delegate_name => ( + isa => 'Str', + required => 1, +); + +parameter interface_role => ( + isa => 'Str', + required => 1, +); + +parameter attributes_to_copy => ( + isa => 'ArrayRef[Str]', + default => sub {[]}, +); + +parameter attributes_to_assume => ( + isa => 'ArrayRef[Str]', + default => sub {[]}, +); + +role { + my $p = shift; + + my $class_name = $p->class_name; + + Class::MOP::load_class($class_name); + + my $meta = Class::MOP::class_of($class_name); + + has [map %{$_->clone}, map $meta->get_attribute($_), @{ $p->attributes_to_copy }]; + + has $p->delegate_name => ( + is => 'ro', + lazy_build => 1, + does => $p->interface_role, + handles => $p->interface_role, + ); + + method '_build_'.$p->delegate_name => sub { + my $self = shift; + + $class_name->new({ + map { $_ => $self->$_ } + @{ $p->attributes_to_assume }, + @{ $p->attributes_to_copy }, + }) + }; +}; + +1; + +# vim: ts=2 sw=2 expandtab + +__END__