1 package Reaction::UI::ViewPort::Field::Role::Mutable;
5 use aliased 'Reaction::InterfaceModel::Action';
6 use aliased 'Reaction::Meta::InterfaceModel::Action::ParameterAttribute';
9 has model => (is => 'ro', isa => Action, required => 1);
10 has attribute => (is => 'ro', isa => ParameterAttribute, required => 1);
12 has value => (is => 'rw', lazy_build => 1, trigger_adopt('value'));
13 has needs_sync => (is => 'rw', isa => 'Int', default => 0);
14 has message => (is => 'rw', isa => 'Str');
16 implements adopt_value => as {
18 $self->needs_sync(1); # if $self->has_attribute;
21 implements sync_to_action => as {
23 return unless $self->needs_sync && $self->has_value;
24 my $attr = $self->attribute;
25 if (my $tc = $attr->type_constraint) {
26 my $value = $self->value;
27 $value = $tc->coercion->coerce($value) if ($tc->has_coercion);
28 my $error = $tc->validate($self->value); # should we be checking against $value?
30 $self->message($error);
34 my $writer = $attr->get_write_method;
35 confess "No writer for attribute" unless defined($writer);
36 my $value = $self->value;
37 $self->model->$writer($self->value); #should we be passing $value ?
41 implements sync_from_action => as {
43 return unless !$self->needs_sync; # && $self->has_attribute;
44 $self->message($self->model->error_for($self->attribute) || '');
47 around accept_events => sub { ('value', shift->(@_)) };
55 Reaction::UI::ViewPort::Role::Actions
59 A role to ease attaching actions to L<Reaction::InterfaceModel::Object>s
77 =head2 sync_from_action
85 See L<Reaction::Class> for authors.
89 See L<Reaction::Class> for the license.