Commit | Line | Data |
7adfd53f |
1 | package Reaction::InterfaceModel::Action::DBIC::Result::Update; |
2 | |
7adfd53f |
3 | use Reaction::Class; |
81393881 |
4 | use namespace::clean -except => [ qw(meta) ]; |
336b3bb0 |
5 | |
6 | extends 'Reaction::InterfaceModel::Action::DBIC::Result'; |
81393881 |
7 | with 'Reaction::InterfaceModel::Action::DBIC::Role::CheckUniques'; |
1c601a76 |
8 | |
81393881 |
9 | sub 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 |
22 | sub 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 |
38 | 1; |
39 | |
1c601a76 |
40 | __END__; |
41 | |
7adfd53f |
42 | =head1 NAME |
43 | |
44 | Reaction::InterfaceModel::Action::DBIC::Result::Update |
45 | |
46 | =head1 DESCRIPTION |
47 | |
1c601a76 |
48 | Update the target model and sync the Action's parameter attributes to |
49 | the target model. |
7adfd53f |
50 | |
1c601a76 |
51 | C<Update> is a subclass of |
52 | L<Action::DBIC::Result|Reaction::InterfaceModel::Action::DBIC::Result> that cponsumes |
53 | L<Role::CheckUniques|'Reaction::InterfaceModel::Action::DBIC::Role::CheckUniques> |
7adfd53f |
54 | |
55 | =head2 BUILD |
56 | |
1c601a76 |
57 | Sync the values from the target model's parameter attributes to the action's |
58 | parameter attributes |
59 | |
60 | =head2 do_apply |
61 | |
62 | Sync the target model's parameter attributes to the values returned by |
63 | C<parameter_hashref>, call C<update> and return the C<target_model>. |
64 | |
65 | =head1 SEE ALSO |
66 | |
67 | L<Create|Reaction::InterfaceModel::Action::DBIC::ResultSet::Create>, |
68 | L<DeleteAll|Reaction::InterfaceModel::Action::DBIC::ResultSet::DeleteAll>, |
69 | L<Delete|Reaction::InterfaceModel::Action::DBIC::Result::Delete>, |
70 | |
7adfd53f |
71 | =head1 AUTHORS |
72 | |
73 | See L<Reaction::Class> for authors. |
74 | |
75 | =head1 LICENSE |
76 | |
77 | See L<Reaction::Class> for the license. |
78 | |
79 | =cut |