1 package Reaction::InterfaceModel::Object;
3 use metaclass 'Reaction::Meta::InterfaceModel::Object::Class';
4 use Reaction::Meta::Attribute;
9 has _action_class_map =>
10 (is => 'rw', isa => 'HashRef', required => 1, default => sub{ {} },
11 metaclass => 'Reaction::Meta::Attribute');
13 has _default_action_class_prefix =>
18 metaclass => 'Reaction::Meta::Attribute',
21 #DBIC::Collection would override this to use result_class for example
22 implements _build__default_action_class_prefix => as {
27 #just a little convenience
28 implements parameter_attributes => as {
29 shift->meta->parameter_attributes;
32 #just a little convenience
33 implements domain_models => as {
34 shift->meta->domain_models;
37 implements '_default_action_class_for' => as {
38 my ($self, $action) = @_;
39 confess("Wrong arguments") unless $action;
40 #little trick in case we call it in class context!
41 my $prefix = ref $self ?
42 $self->_default_action_class_prefix :
43 $self->_build__default_action_class_prefix;
45 return join "::", $prefix, 'Action', $action;
48 implements '_action_class_for' => as {
49 my ($self, $action) = @_;
50 confess("Wrong arguments") unless $action;
51 if (defined (my $class = $self->_action_class_map->{$action})) {
54 return $self->_default_action_class_for($action);
57 implements 'action_for' => as {
58 my ($self, $action, %args) = @_;
59 confess("Wrong arguments") unless $action;
60 my $class = $self->_action_class_for($action);
62 %{$self->_default_action_args_for($action)},
64 %{$self->_override_action_args_for($action)},
66 return $class->new(%args);
69 #this really needs to be smarter, fine for CRUD, shit for anything else
70 # massive fucking reworking needed here, really
71 implements _default_action_args_for => as { {} };
72 implements _override_action_args_for => as { {} };
83 Reaction::Class::InterfaceModel::Object
89 InterfaceModel Object base class.
93 =head2 _action_class_map
95 RW, isa HashRef - Returns an empty hashref by default. It will hold a series of actions
96 as keys with their corresponding action classes as values.
98 =head2 _default_action_class_prefix
100 RO, isa Str - Default action class prefix. Lazy build by default to the value
101 returned by C<_build_default_action_class_prefix> which is C<ref $self || $self>.
105 =head2 parameter_attributes
109 Shortcuts for these same subs in meta. They will return attribute objects that are of
110 the correct type, L<Reaction::Meta::InterfaceModel::Object::ParameterAttribute> and
111 L<Reaction::Meta::InterfaceModel::Object::DomainModelAttribute>
113 =head2 _default_action_class_for $action
115 Provides the default package name for the C<$action> action-class.
116 It defaults to the value of C<_default_action_class_prefix> followed by
119 #for MyApp::Foo, returns MyApp::Foo::Action::Create
120 $obj->_default_action_class_for('Create');
122 =head2 _action_class_for $action
124 Return the action class for an action name. Will search
125 C<_action_class_map> or, if not found, use the value of
126 C<_default_action_class_for>
128 =head2 action_for $action, %args
130 Will return a new instance of C<$action>. If specified,
131 %args will be passed through to C<new> as is.
133 =head2 _default_action_args_for
135 By default will return an empty hashref
137 =head2 _override_action_args_for
139 Returns empty hashref by default.
143 L<Reaction::InterfaceModel::ObjectClass>
147 See L<Reaction::Class> for authors.
151 See L<Reaction::Class> for the license.