| 1 | package Reaction::UI::ViewPort::Action; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use Reaction::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 4 | ▶ | use MooseX::Types::URI qw/Uri/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use MooseX::Types::Moose qw/Int Str/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 4 | ▶ | use namespace::clean -except => [ qw(meta) ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 4 | extends 'Reaction::UI::ViewPort::Object::Mutable'; | |||||||||
| 12 | 4 | with 'Reaction::UI::ViewPort::Action::Role::OK'; | |||||||||
| 13 | |||||||||||
| 14 | 4 | has message => (is => 'rw', isa => Str); | |||||||||
| 15 | 4 | has '+model' => (handles => [qw/error_message has_error_message/]); | |||||||||
| 16 | |||||||||||
| 17 | #this has to fucking go. it BLOWS. | ||||||||||
| 18 | has method => ( | ||||||||||
| 19 | is => 'rw', | ||||||||||
| 20 | isa => NonEmptySimpleStr, | ||||||||||
| 21 | 3 | ▶ | default => sub { 'post' } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 4 | ); | |||||||||
| 23 | |||||||||||
| 24 | 4 | has action => ( is => 'rw', isa => Uri ); | |||||||||
| 25 | |||||||||||
| 26 | has changed => ( | ||||||||||
| 27 | is => 'rw', | ||||||||||
| 28 | isa => Int, | ||||||||||
| 29 | reader => 'is_changed', | ||||||||||
| 30 | 3 | ▶ | default => sub{0} | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 4 | ); | |||||||||
| 32 | |||||||||||
| 33 | 2 | ▶ | sub can_apply { | ||||||||
|
Subroutine
can_apply: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 34 | 2 | my ($self) = @_; | |||||||||
| 35 | 2 | foreach my $field ( @{ $self->fields } ) { | |||||||||
| 36 | 8 | ▶ | return 0 if $field->needs_sync; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | # if e.g. a datetime field has an invalid value that can't be re-assembled | ||||||||||
| 38 | # into a datetime object, the action may be in a consistent state but | ||||||||||
| 39 | # not synchronized from the fields; in this case, we must not apply | ||||||||||
| 40 | } | ||||||||||
| 41 | 2 | return $self->model->can_apply; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 2 | ▶ | sub do_apply { | ||||||||
|
Subroutine
do_apply: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 45 | 2 | shift->model->do_apply; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 2 | ▶ | after apply_child_events => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 49 | # interrupt here because fields will have been updated | ||||||||||
| 50 | 2 | my ($self) = @_; | |||||||||
| 51 | 2 | $self->sync_action_from_fields; | |||||||||
| 52 | 4 | }; | |||||||||
| 53 | |||||||||||
| 54 | 2 | ▶ | sub sync_action_from_fields { | ||||||||
|
Subroutine
sync_action_from_fields: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 55 | 2 | my ($self) = @_; | |||||||||
| 56 | 2 | foreach my $field (@{$self->fields}) { | |||||||||
| 57 | 8 | $field->sync_to_action; # get the field to populate the $action if possible | |||||||||
| 58 | } | ||||||||||
| 59 | 2 | $self->model->sync_all; | |||||||||
| 60 | 2 | foreach my $field (@{$self->fields}) { | |||||||||
| 61 | 8 | $field->sync_from_action; # get errors from $action if applicable | |||||||||
| 62 | } | ||||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 66 | |||||||||||
| 67 | 4 | 1; | |||||||||
| 68 | |||||||||||
| 69 | __END__; | ||||||||||