| Reaction documentation | Contained in the Reaction distribution. |
Reaction::InterfaceModel::Object
InterfaceModel Object base class.
RW, isa HashRef - Returns an empty hashref by default. It will hold a series of actions as keys with their corresponding action classes as values.
RO, isa Str - Default action class prefix. Lazy build by default to the value
returned by _build_default_action_class_prefix which is ref $self || $self.
Shortcuts for these same subs in meta. They will return attribute objects that are of the correct type, Reaction::Meta::InterfaceModel::Object::ParameterAttribute and Reaction::Meta::InterfaceModel::Object::DomainModelAttribute
Provides the default package name for the $action action-class.
It defaults to the value of _default_action_class_prefix followed by
::Action::$action
#for MyApp::Foo, returns MyApp::Foo::Action::Create
$obj->_default_action_class_for('Create');
Return the action class for an action name. Will search
_action_class_map or, if not found, use the value of
_default_action_class_for
Will return a new instance of $action. If specified,
%args will be passed through to new as is.
By default will return an empty hashref
Returns empty hashref by default.
See Reaction::Class for authors.
See Reaction::Class for the license.
| Reaction documentation | Contained in the Reaction distribution. |
package Reaction::InterfaceModel::Object; use metaclass 'Reaction::Meta::InterfaceModel::Object::Class'; use Reaction::Meta::Attribute; use Reaction::Class; 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; __END__;