[Bast-commits] r3453 - in trunk/Anything/lib/Anything: Controller/Test InterfaceModel/Items/Action InterfaceModel/Items/Role

castaway at dev.catalyst.perl.org castaway at dev.catalyst.perl.org
Fri Jun 1 00:18:12 GMT 2007


Author: castaway
Date: 2007-06-01 00:18:11 +0100 (Fri, 01 Jun 2007)
New Revision: 3453

Added:
   trunk/Anything/lib/Anything/InterfaceModel/Items/Action/Update.pm
Modified:
   trunk/Anything/lib/Anything/Controller/Test/Item.pm
   trunk/Anything/lib/Anything/InterfaceModel/Items/Role/Typefields.pm
Log:
Make sure action has the values of the attributes set


Modified: trunk/Anything/lib/Anything/Controller/Test/Item.pm
===================================================================
--- trunk/Anything/lib/Anything/Controller/Test/Item.pm	2007-05-31 23:13:06 UTC (rev 3452)
+++ trunk/Anything/lib/Anything/Controller/Test/Item.pm	2007-05-31 23:18:11 UTC (rev 3453)
@@ -86,10 +86,6 @@
 
 sub create :Chained('type') :PathPart('create') :Args() {
   my ($self, $c, $typeid) = @_;
-## Atempt to use an empty Item object for create instead of the collection, fails as Anything::InterfaceModel::Items cant be instantiated with no _items_store attribute. 
-#  my $coll = $self->get_collection($c);
-#  my $new_object = $coll->new_result({_items_store => $coll->_items_store});
-#  my $action = $self->get_model_action($c, 'Create', $new_object, $typeid);
   my $action = $self->get_model_action($c, 'Create', $self->get_collection($c), $typeid);
 #  print STDERR $action->dump, "\n";
 #  print STDERR $_->blessed for $action->meta->compute_all_applicable_attributes;

Added: trunk/Anything/lib/Anything/InterfaceModel/Items/Action/Update.pm
===================================================================
--- trunk/Anything/lib/Anything/InterfaceModel/Items/Action/Update.pm	                        (rev 0)
+++ trunk/Anything/lib/Anything/InterfaceModel/Items/Action/Update.pm	2007-05-31 23:18:11 UTC (rev 3453)
@@ -0,0 +1,46 @@
+package Anything::InterfaceModel::Items::Action::Update;
+
+use Reaction::Class;
+use aliased 'Reaction::InterfaceModel::Action::DBIC::Result::Update' => 'DBIC_Update';
+use Anything::InterfaceModel::Items::Role::Typefields;
+use Anything::Types;
+
+class Update is DBIC_Update, which {
+
+  does 'Anything::InterfaceModel::Items::Role::Typefields';
+
+  implements BUILD => as {
+      my ($self) = @_;
+      my $fields = $self->delayed_fields();
+      my $tm = $self->target_model;
+
+      print STDERR "Set fields:", Data::Dumper::Dumper($fields);
+      foreach my $field (keys %$fields)
+      {
+          my $has = "has_field_$field";
+          my $val = $tm->value($fields->{$field})->Value;
+          print STDERR "Setting: $field $val\n";
+          $self->$field($val) unless $self->$has;
+          print STDERR "Set field $field to " . $self->$field . "\n";
+      }
+  };
+
+  around do_apply => sub {
+    my $super = shift;
+    my $row = $super->(@_);
+    my $self = shift;
+
+    for my $name (keys %{ $self->delayed_fields }) {
+      my $attr = $self->meta->find_attribute_by_name($name);
+      my $reader = $attr->reader;
+      my $predicate = $attr->predicate;
+      next if defined($predicate) && !$self->$predicate;
+      my $field = $self->delayed_fields->{$name};
+      $row->value($field->Name, $self->$reader);
+    }
+
+    return $row;
+  };
+};
+
+1;

Modified: trunk/Anything/lib/Anything/InterfaceModel/Items/Role/Typefields.pm
===================================================================
--- trunk/Anything/lib/Anything/InterfaceModel/Items/Role/Typefields.pm	2007-05-31 23:13:06 UTC (rev 3452)
+++ trunk/Anything/lib/Anything/InterfaceModel/Items/Role/Typefields.pm	2007-05-31 23:18:11 UTC (rev 3453)
@@ -41,6 +41,7 @@
 
     my $obj = $action_meta->new_object(@_, delayed_fields => \%delayed_fields);
     $obj->{__keep_metaclass_alive__} = $action_meta;
+    $obj->BUILDALL(\%args);
     return $obj;
   };
 




More information about the Bast-commits mailing list