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';
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);
has builtin_object_actions => (isa => "HashRef", is => "rw", lazy_build => 1);
has builtin_collection_actions => (isa => "HashRef", is => "rw", lazy_build => 1);
- implements build_object_actions => as { {} };
- implements build_collection_actions => as { {} };
+ implements _build_object_actions => as { {} };
+ implements _build_collection_actions => as { {} };
- implements build_default_object_actions => as { [ qw/Update Delete/ ] };
- implements build_default_collection_actions => as { [ 'Create' ] };
+ implements _build_default_object_actions => as { [ qw/Update Delete/ ] };
+ implements _build_default_collection_actions => as { [ qw/Create DeleteAll/ ] };
- implements build_builtin_object_actions => as {
+ implements _build_builtin_object_actions => as {
{
- Update => { base => Update },
- Delete => { base => Delete, attributes => [] },
+ Update => { name => 'Update', base => Update },
+ Delete => { name => 'Delete', base => Delete, attributes => [] },
};
};
- implements build_builtin_collection_actions => as {
- { Create => {base => Create } };
+ implements _build_builtin_collection_actions => as {
+ {
+ Create => {name => 'Create', base => Create },
+ DeleteAll => {name => 'DeleteAll', base => DeleteAll, attributes => [] }
+ };
};
implements _all_object_actions => as {
- my $self = shift;
+ my $self = shift;
return $self->merge_hashes
($self->builtin_object_actions, $self->object_actions);
};
unless($model && $schema);
Class::MOP::load_class( $base );
Class::MOP::load_class( $schema );
- my $meta = eval {Class::MOP::load_class($model); } ?
+ my $meta = eval { Class::MOP::load_class($model); } ?
$model->meta : $base->meta->create($model, superclasses => [ $base ]);
# sources => undef, #default to qr/./
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
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;
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 } );
+ $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
#better through the coercion method
my $def_act_args = sub {
for my $action (keys %$actions){
my $action_opts = $self->merge_hashes
($all_actions->{$action} || {}, $actions->{$action} || {});
+
+ #NOTE: If the name of the action is not specified in the prototype then use it's
+ #hash key as the name. I think this is sane beahvior, but I've actually been thinking
+ #of making Action prototypes their own separate objects
$self->reflect_source_action(
name => $action,
object_class => $object,
$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);
for my $action (keys %$actions){
my $action_opts = $self->merge_hashes
($all_actions->{$action} || {}, $actions->{$action} || {});
+
+ #NOTE: If the name of the action is not specified in the prototype then use it's
+ #hash key as the name. I think this is sane beahvior, but I've actually been thinking
+ #of making Action prototypes their own separate objects
$self->reflect_source_action(
name => $action,
object_class => $class,
#proper collections will remove the result_class uglyness.
$attr_opts{default} = sub {
- my $rs = shift->$dm_name->result_source->related_source($link_table)
- ->related_source($mm_name)->resultset;
+ my $rs = shift->$dm_name->related_resultset($link_table)->related_resultset($mm_name);
return $attr_opts{isa}->new(_source_resultset => $rs);
};
} else {
#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){
};
}
#use Data::Dumper;
+ #print STDERR "\n" .$attr_name ." - ". $object . "\n";
#print STDERR Dumper(\%attr_opts);
return \%attr_opts;
};