initial parameterised role to get rid of WithFoos
Arthur Axel 'fREW' Schmidt [Thu, 6 May 2010 01:12:35 +0000 (20:12 -0500)]
lib/DBIx/Class/DeploymentHandler.pm
lib/DBIx/Class/DeploymentHandler/WithApplicatorDumple.pm [new file with mode: 0644]

index 2a37231..d7583c1 100644 (file)
@@ -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 (file)
index 0000000..971c994
--- /dev/null
@@ -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__