factor out DBIC::Result action base and SimpleMethodCall action role
matthewt [Fri, 7 Mar 2008 17:54:44 +0000 (17:54 +0000)]
lib/Reaction/InterfaceModel/Action/DBIC/Result.pm [new file with mode: 0644]
lib/Reaction/InterfaceModel/Action/DBIC/Result/Delete.pm
lib/Reaction/InterfaceModel/Action/DBIC/Result/Update.pm
lib/Reaction/InterfaceModel/Action/Role/SimpleMethodCall.pm [new file with mode: 0644]

diff --git a/lib/Reaction/InterfaceModel/Action/DBIC/Result.pm b/lib/Reaction/InterfaceModel/Action/DBIC/Result.pm
new file mode 100644 (file)
index 0000000..ad2f130
--- /dev/null
@@ -0,0 +1,13 @@
+package Reaction::InterfaceModel::Action::DBIC::Result;
+
+use Reaction::InterfaceModel::Action;
+use Reaction::Types::DBIC 'Row';
+use Reaction::Class;
+
+class Result is 'Reaction::InterfaceModel::Action', which {
+
+  has '+target_model' => (isa => Row);
+
+};
+
+1;
index 4d81486..c30b9f6 100644 (file)
@@ -1,17 +1,15 @@
 package Reaction::InterfaceModel::Action::DBIC::Result::Delete;
 
+use aliased 'Reaction::InterfaceModel::Action::DBIC::Result';
+use aliased 'Reaction::InterfaceModel::Action::Role::SimpleMethodCall';
 use Reaction::Types::DBIC 'Row';
 use Reaction::Class;
 
-class Delete is 'Reaction::InterfaceModel::Action', which {
-  has '+target_model' => (isa => Row);
+class Delete is Result, which {
+  does SimpleMethodCall;
 
-  sub can_apply { 1 }
-
-  implements do_apply => as {
-    my $self = shift;
-    return $self->target_model->delete;
-  };
+  implements _target_model_method => as { 'delete' };
 
 };
 
index 59591ad..3b4c776 100644 (file)
@@ -1,15 +1,13 @@
 package Reaction::InterfaceModel::Action::DBIC::Result::Update;
 
-use Reaction::InterfaceModel::Action;
+use aliased 'Reaction::InterfaceModel::Action::DBIC::Result';
 use Reaction::Types::DBIC 'Row';
 use Reaction::Class;
 
-class Update is 'Reaction::InterfaceModel::Action', which {
+class Update is Result, which {
 
   does 'Reaction::InterfaceModel::Action::DBIC::Role::CheckUniques';
 
-  has '+target_model' => (isa => Row);
-
   implements BUILD => as {
     my ($self) = @_;
     my $tm = $self->target_model;
diff --git a/lib/Reaction/InterfaceModel/Action/Role/SimpleMethodCall.pm b/lib/Reaction/InterfaceModel/Action/Role/SimpleMethodCall.pm
new file mode 100644 (file)
index 0000000..285ddb1
--- /dev/null
@@ -0,0 +1,14 @@
+package Reaction::InterfaceModel::Action::Role::SimpleMethodCall;
+
+use Reaction::Role;
+
+requires '_target_model_method';
+
+sub can_apply { 1; }
+
+sub do_apply {
+  my ($self) = @_;
+  $self->target_model->${\$self->_target_model_method};
+}
+
+1;