do not include .git directory
[catagits/Reaction.git] / lib / Reaction / InterfaceModel / Action / DBIC / Result / Update.pm
CommitLineData
7adfd53f 1package Reaction::InterfaceModel::Action::DBIC::Result::Update;
2
7adfd53f 3use Reaction::Class;
81393881 4use namespace::clean -except => [ qw(meta) ];
336b3bb0 5
6extends 'Reaction::InterfaceModel::Action::DBIC::Result';
81393881 7with 'Reaction::InterfaceModel::Action::DBIC::Role::CheckUniques';
1c601a76 8
81393881 9sub BUILD {
10 my ($self) = @_;
11 my $tm = $self->target_model;
12 foreach my $attr ($self->parameter_attributes) {
13 my $writer = $attr->get_write_method;
14 my $name = $attr->name;
15 my $tm_attr = $tm->meta->find_attribute_by_name($name);
16 next unless ref $tm_attr;
17 my $tm_reader = $tm_attr->get_read_method;
18 $self->$writer($tm->$tm_reader) if defined($tm->$tm_reader);
19 }
1c601a76 20}
21
81393881 22sub do_apply {
23 my $self = shift;
24 my $args = $self->parameter_hashref;
25 my $model = $self->target_model;
26 foreach my $name (keys %$args) {
27 my $tm_attr = $model->meta->find_attribute_by_name($name);
28 next unless ref $tm_attr;
29 my $tm_writer = $tm_attr->get_write_method;
30 $model->$tm_writer($args->{$name});
31 }
32 $model->update;
33 return $model;
1c601a76 34}
7adfd53f 35
81393881 36__PACKAGE__->meta->make_immutable;
37
7adfd53f 381;
39
1c601a76 40__END__;
41
7adfd53f 42=head1 NAME
43
44Reaction::InterfaceModel::Action::DBIC::Result::Update
45
46=head1 DESCRIPTION
47
1c601a76 48Update the target model and sync the Action's parameter attributes to
49the target model.
7adfd53f 50
1c601a76 51C<Update> is a subclass of
52L<Action::DBIC::Result|Reaction::InterfaceModel::Action::DBIC::Result> that cponsumes
53L<Role::CheckUniques|'Reaction::InterfaceModel::Action::DBIC::Role::CheckUniques>
7adfd53f 54
55=head2 BUILD
56
1c601a76 57Sync the values from the target model's parameter attributes to the action's
58parameter attributes
59
60=head2 do_apply
61
62Sync the target model's parameter attributes to the values returned by
63C<parameter_hashref>, call C<update> and return the C<target_model>.
64
65=head1 SEE ALSO
66
67L<Create|Reaction::InterfaceModel::Action::DBIC::ResultSet::Create>,
68L<DeleteAll|Reaction::InterfaceModel::Action::DBIC::ResultSet::DeleteAll>,
69L<Delete|Reaction::InterfaceModel::Action::DBIC::Result::Delete>,
70
7adfd53f 71=head1 AUTHORS
72
73See L<Reaction::Class> for authors.
74
75=head1 LICENSE
76
77See L<Reaction::Class> for the license.
78
79=cut