X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FInterfaceModel%2FObject.pm;h=cd3c3dbcdb1cb5660f3d3980fa112157e5967430;hb=09d2d18d3ee75780b3c7922bb0af004cf58b4be1;hp=48d46ca14452a4b65213e550679768fcd4a261f1;hpb=f670cfd0d1ce4753a2c76b27cdc01e8471e4cc4a;p=catagits%2FReaction.git diff --git a/lib/Reaction/InterfaceModel/Object.pm b/lib/Reaction/InterfaceModel/Object.pm index 48d46ca..cd3c3db 100644 --- a/lib/Reaction/InterfaceModel/Object.pm +++ b/lib/Reaction/InterfaceModel/Object.pm @@ -4,74 +4,73 @@ use metaclass 'Reaction::Meta::InterfaceModel::Object::Class'; use Reaction::Meta::Attribute; use Reaction::Class; -class Object which { - - has _action_class_map => - (is => 'rw', isa => 'HashRef', required => 1, default => sub{ {} }, - metaclass => 'Reaction::Meta::Attribute'); - - has _default_action_class_prefix => - ( - is => 'ro', - isa => 'Str', - lazy_build => 1, - metaclass => 'Reaction::Meta::Attribute', - ); - - #DBIC::Collection would override this to use result_class for example - implements _build_default_action_class_prefix => as { - my $self = shift; - ref $self || $self; - }; - - #just a little convenience - implements parameter_attributes => as { - shift->meta->parameter_attributes; - }; - - #just a little convenience - implements domain_models => as { - shift->meta->domain_models; - }; - - implements '_default_action_class_for' => as { - my ($self, $action) = @_; - confess("Wrong arguments") unless $action; - #little trick in case we call it in class context! - my $prefix = ref $self ? - $self->_default_action_class_prefix : - $self->_build_default_action_class_prefix; - - return join "::", $prefix, 'Action', $action; - }; - - implements '_action_class_for' => as { - my ($self, $action) = @_; - confess("Wrong arguments") unless $action; - if (defined (my $class = $self->_action_class_map->{$action})) { - return $class; - } - return $self->_default_action_class_for($action); - }; - - implements 'action_for' => as { - my ($self, $action, %args) = @_; - confess("Wrong arguments") unless $action; - my $class = $self->_action_class_for($action); - %args = ( - %{$self->_default_action_args_for($action)}, - %args, - %{$self->_override_action_args_for($action)}, - ); - return $class->new(%args); - }; - - #this really needs to be smarter, fine for CRUD, shit for anything else - # massive fucking reworking needed here, really - implements _default_action_args_for => as { {} }; - implements _override_action_args_for => as { {} }; +use namespace::clean -except => [ qw(meta) ]; + +has _action_class_map => + (is => 'rw', isa => 'HashRef', required => 1, default => sub{ {} }, + metaclass => 'Reaction::Meta::Attribute'); + +has _default_action_class_prefix => + ( + is => 'ro', + isa => 'Str', + lazy_build => 1, + metaclass => 'Reaction::Meta::Attribute', + ); + +#DBIC::Collection would override this to use result_class for example +sub _build__default_action_class_prefix { + my $self = shift; + ref $self || $self; +}; + +#just a little convenience +sub parameter_attributes { + shift->meta->parameter_attributes; +}; + +#just a little convenience +sub domain_models { + shift->meta->domain_models; }; +sub _default_action_class_for { + my ($self, $action) = @_; + confess("Wrong arguments") unless $action; + #little trick in case we call it in class context! + my $prefix = ref $self ? + $self->_default_action_class_prefix : + $self->_build__default_action_class_prefix; + + return join "::", $prefix, 'Action', $action; +}; +sub _action_class_for { + my ($self, $action) = @_; + confess("Wrong arguments") unless $action; + if (defined (my $class = $self->_action_class_map->{$action})) { + return $class; + } + return $self->_default_action_class_for($action); +}; +sub action_for { + my ($self, $action, %args) = @_; + confess("Wrong arguments") unless $action; + my $class = $self->_action_class_for($action); + %args = ( + %{$self->_default_action_args_for($action)}, + %args, + %{$self->_override_action_args_for($action)}, + ); + return $class->new(%args); +}; + +#this really needs to be smarter, fine for CRUD, shit for anything else +# massive fucking reworking needed here, really +sub _default_action_args_for { {} }; +sub _override_action_args_for { {} }; + +__PACKAGE__->meta->make_immutable; + 1;