1 package Reaction::InterfaceModel::Object;
3 use metaclass 'Reaction::Meta::InterfaceModel::Object::Class';
4 use Reaction::Meta::Attribute;
7 use namespace::clean -except => [ qw(meta) ];
10 has _action_class_map =>
11 (is => 'rw', isa => 'HashRef', required => 1, default => sub{ {} },
12 metaclass => 'Reaction::Meta::Attribute');
14 has _default_action_class_prefix =>
19 metaclass => 'Reaction::Meta::Attribute',
22 #DBIC::Collection would override this to use result_class for example
23 sub _build__default_action_class_prefix {
28 #just a little convenience
29 sub parameter_attributes {
30 shift->meta->parameter_attributes;
33 #just a little convenience
35 shift->meta->domain_models;
37 sub _default_action_class_for {
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;
47 sub _action_class_for {
48 my ($self, $action) = @_;
49 confess("Wrong arguments") unless $action;
50 if (defined (my $class = $self->_action_class_map->{$action})) {
53 return $self->_default_action_class_for($action);
56 my ($self, $action, %args) = @_;
57 confess("Wrong arguments") unless $action;
58 my $class = $self->_action_class_for($action);
60 %{$self->_default_action_args_for($action)},
62 %{$self->_override_action_args_for($action)},
64 return $class->new(%args);
67 #this really needs to be smarter, fine for CRUD, shit for anything else
68 # massive fucking reworking needed here, really
69 sub _default_action_args_for { {} };
70 sub _override_action_args_for { {} };
72 __PACKAGE__->meta->make_immutable;
82 Reaction::InterfaceModel::Object
88 InterfaceModel Object base class.
92 =head2 _action_class_map
94 RW, isa HashRef - Returns an empty hashref by default. It will hold a series of actions
95 as keys with their corresponding action classes as values.
97 =head2 _default_action_class_prefix
99 RO, isa Str - Default action class prefix. Lazy build by default to the value
100 returned by C<_build_default_action_class_prefix> which is C<ref $self || $self>.
104 =head2 parameter_attributes
108 Shortcuts for these same subs in meta. They will return attribute objects that are of
109 the correct type, L<Reaction::Meta::InterfaceModel::Object::ParameterAttribute> and
110 L<Reaction::Meta::InterfaceModel::Object::DomainModelAttribute>
112 =head2 _default_action_class_for $action
114 Provides the default package name for the C<$action> action-class.
115 It defaults to the value of C<_default_action_class_prefix> followed by
118 #for MyApp::Foo, returns MyApp::Foo::Action::Create
119 $obj->_default_action_class_for('Create');
121 =head2 _action_class_for $action
123 Return the action class for an action name. Will search
124 C<_action_class_map> or, if not found, use the value of
125 C<_default_action_class_for>
127 =head2 action_for $action, %args
129 Will return a new instance of C<$action>. If specified,
130 %args will be passed through to C<new> as is.
132 =head2 _default_action_args_for
134 By default will return an empty hashref
136 =head2 _override_action_args_for
138 Returns empty hashref by default.
142 L<Reaction::InterfaceModel::ObjectClass>
146 See L<Reaction::Class> for authors.
150 See L<Reaction::Class> for the license.