CRUDController syntax changed to be less retarded and Reflector::DBIC fixed to use...
[catagits/Reaction.git] / lib / Reaction / InterfaceModel / Reflector / DBIC.pm
index 70b65b7..326770f 100644 (file)
@@ -1,6 +1,7 @@
 package Reaction::InterfaceModel::Reflector::DBIC;
 
 use aliased 'Reaction::InterfaceModel::Action::DBIC::ResultSet::Create';
+use aliased 'Reaction::InterfaceModel::Action::DBIC::ResultSet::DeleteAll';
 use aliased 'Reaction::InterfaceModel::Action::DBIC::Result::Update';
 use aliased 'Reaction::InterfaceModel::Action::DBIC::Result::Delete';
 
@@ -14,6 +15,8 @@ use Catalyst::Utils;
 
 class DBIC, which {
 
+  has make_classes_immutable => (isa => "Bool", is => "rw", required => 1, default => sub{ 1 });
+
   #user defined actions and prototypes
   has object_actions     => (isa => "HashRef", is => "rw", lazy_build => 1);
   has collection_actions => (isa => "HashRef", is => "rw", lazy_build => 1);
@@ -40,7 +43,10 @@ class DBIC, which {
   };
 
   implements build_builtin_collection_actions => as {
-    { Create => {name => 'Create', base => Create } };
+    {
+      Create    => {name => 'Create',    base => Create    },
+      DeleteAll => {name => 'DeleteAll', base => DeleteAll }
+    };
   };
 
   implements _all_object_actions => as {
@@ -178,7 +184,7 @@ class DBIC, which {
 
     my $sources = $self->parse_reflect_rules($rules, $haystack);
 
-    my $make_immutable = $meta->is_immutable;
+    my $make_immutable = $meta->is_immutable || $self->make_classes_immutable;
     $meta->make_mutable if $meta->is_immutable;
 
     $meta->add_domain_model
@@ -295,7 +301,7 @@ class DBIC, which {
     unless( $reader ){
       $reader = $source;
       $reader =~ s/([a-z0-9])([A-Z])/${1}_${2}/g ;
-      $reader = lc($reader) . "_collection";
+      $reader = lc($reader) . "_collection"; #XXX change to not use  _collection ?
     }
     unless( $dm_name ){
       my @haystack = $meta->domain_models;
@@ -372,7 +378,7 @@ class DBIC, which {
     my $meta = eval { Class::MOP::load_class($class) } ?
       $class->meta : $base->meta->create( $class, superclasses => [ $base ]);
 
-    my $make_immutable = $meta->is_immutable;
+    my $make_immutable = $meta->is_immutable || $self->make_classes_immutable;;
     $meta->make_mutable if $meta->is_immutable;
     $meta->add_method(_build_im_class => sub{ $object } );
     #XXX as a default pass the domain model as a target_model until i come up with something
@@ -467,7 +473,7 @@ class DBIC, which {
     $dm_opts->{is}       ||= 'rw';
     $dm_opts->{required} ||= 1;
 
-    my $make_immutable = $meta->is_immutable;
+    my $make_immutable = $meta->is_immutable || $self->make_classes_immutable;;
     $meta->make_mutable if $meta->is_immutable;
 
     my $dm_attr   = $meta->add_domain_model($dm_name, %$dm_opts);
@@ -753,7 +759,7 @@ class DBIC, which {
     #create the class
     my $meta = eval { Class::MOP::load_class($class) } ?
       $class->meta : $base->meta->create($class, superclasses => [$base]);
-    my $make_immutable = $meta->is_immutable;
+    my $make_immutable = $meta->is_immutable || $self->make_classes_immutable;
     $meta->make_mutable if $meta->is_immutable;
 
     for my $attr_name (keys %$attributes){