checking in more pod, some fixes for weird bugs, a manual for migration, an extra...
[catagits/Reaction.git] / lib / Reaction / InterfaceModel / Action / DBIC / ResultSet / Create.pm
CommitLineData
7adfd53f 1package Reaction::InterfaceModel::Action::DBIC::ResultSet::Create;
2
e739c9a2 3use Reaction::Types::DBIC 'ResultSet';
7adfd53f 4use Reaction::Class;
5use Reaction::InterfaceModel::Action;
6use Reaction::InterfaceModel::Action::DBIC::Role::CheckUniques;
7
81393881 8use namespace::clean -except => [ qw(meta) ];
336b3bb0 9extends 'Reaction::InterfaceModel::Action::DBIC::ResultSet';
81393881 10
11with 'Reaction::InterfaceModel::Action::DBIC::Role::CheckUniques';
12
81393881 13sub do_apply {
14 my $self = shift;
15 my $args = $self->parameter_hashref;
16 my $new = $self->target_model->new({});
17 my @delay;
18 foreach my $name (keys %$args) {
d98c38f8 19 my $tm_attr = $new->meta->find_attribute_by_name($name) or next;
81393881 20 my $tm_writer = $tm_attr->get_write_method;
21 unless ($tm_writer) {
22 warn "Unable to find writer for ${name}";
23 next;
7adfd53f 24 }
81393881 25 if ($tm_attr->type_constraint->name eq 'ArrayRef'
26 || $tm_attr->type_constraint->is_subtype_of('ArrayRef')) {
27 push(@delay, [ $tm_writer, $args->{$name} ]);
28 } else {
29 $new->$tm_writer($args->{$name});
30 }
31 }
32 $new->insert;
33 foreach my $d (@delay) {
34 my ($meth, $val) = @$d;
35 $new->$meth($val);
36 }
37 return $new;
7adfd53f 38};
39
81393881 40__PACKAGE__->meta->make_immutable;
41
7adfd53f 421;
43
1c601a76 44__END__;
45
7adfd53f 46=head1 NAME
47
48Reaction::InterfaceModel::Action::DBIC::ResultSet::Create
49
50=head1 DESCRIPTION
51
1c601a76 52Create a new object.
53
54C<Update> is a subclass of
55L<Action::DBIC::ResultSet|Reaction::InterfaceModel::Action::DBIC::ResultSet>
56that cponsumes L<Role::CheckUniques|'Reaction::InterfaceModel::Action::DBIC::Role::CheckUniques>
57
58=head2 do_apply
59
60Create a C<new_result> for the C<target_model>, sync it to the action's
61C<parameter_attributes> and C<insert> it into the database. Returns the newly
62inserted object
7adfd53f 63
1c601a76 64=head1 SEE ALSO
7adfd53f 65
1c601a76 66L<DeleteAll|Reaction::InterfaceModel::Action::DBIC::ResultSet::DeleteAll>,
67L<Update|Reaction::InterfaceModel::Action::DBIC::Result::Update>,
68L<Delete|Reaction::InterfaceModel::Action::DBIC::Result::Delete>,
7adfd53f 69
70=head1 AUTHORS
71
72See L<Reaction::Class> for authors.
73
74=head1 LICENSE
75
76See L<Reaction::Class> for the license.
77
78=cut