Commit | Line | Data |
7adfd53f |
1 | package Reaction::InterfaceModel::Action::DBIC::Result::Update; |
2 | |
07890ce0 |
3 | use aliased 'Reaction::InterfaceModel::Action::DBIC::Result'; |
e739c9a2 |
4 | use Reaction::Types::DBIC 'Row'; |
7adfd53f |
5 | use Reaction::Class; |
6 | |
07890ce0 |
7 | class Update is Result, which { |
7adfd53f |
8 | |
9 | does 'Reaction::InterfaceModel::Action::DBIC::Role::CheckUniques'; |
10 | |
7adfd53f |
11 | implements BUILD => as { |
12 | my ($self) = @_; |
13 | my $tm = $self->target_model; |
14 | foreach my $attr ($self->parameter_attributes) { |
15 | my $writer = $attr->get_write_method; |
16 | my $name = $attr->name; |
17 | my $tm_attr = $tm->meta->find_attribute_by_name($name); |
18 | next unless ref $tm_attr; |
19 | my $tm_reader = $tm_attr->get_read_method; |
f6ec638f |
20 | $self->$writer($tm->$tm_reader) if defined($tm->$tm_reader); |
7adfd53f |
21 | } |
22 | }; |
23 | |
24 | implements do_apply => as { |
25 | my $self = shift; |
26 | my $args = $self->parameter_hashref; |
27 | my $model = $self->target_model; |
28 | foreach my $name (keys %$args) { |
29 | my $tm_attr = $model->meta->find_attribute_by_name($name); |
30 | next unless ref $tm_attr; |
31 | my $tm_writer = $tm_attr->get_write_method; |
32 | $model->$tm_writer($args->{$name}); |
33 | } |
34 | $model->update; |
35 | return $model; |
36 | }; |
37 | |
38 | }; |
39 | |
40 | 1; |
41 | |
42 | =head1 NAME |
43 | |
44 | Reaction::InterfaceModel::Action::DBIC::Result::Update |
45 | |
46 | =head1 DESCRIPTION |
47 | |
48 | =head2 target_model |
49 | |
50 | =head2 error_for_attribute |
51 | |
52 | =head2 sync_all |
53 | |
54 | =head2 BUILD |
55 | |
56 | =head1 AUTHORS |
57 | |
58 | See L<Reaction::Class> for authors. |
59 | |
60 | =head1 LICENSE |
61 | |
62 | See L<Reaction::Class> for the license. |
63 | |
64 | =cut |