diff options
author | groditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2008-02-26 02:47:19 +0000 |
---|---|---|
committer | groditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2008-02-26 02:47:19 +0000 |
commit | 5ea9eefdd87a42d5c5e5d03f9a50abedab954276 (patch) | |
tree | 73d75c4fcdf8c4701ad72cab8daba4e8f7486c62 /lib/Reaction/UI/ViewPort/Field | |
parent | 74e1591d0d3d9fa6b2544964c61815d926eb6689 (diff) | |
download | reaction-5ea9eefdd87a42d5c5e5d03f9a50abedab954276.tar.gz reaction-5ea9eefdd87a42d5c5e5d03f9a50abedab954276.zip |
split out can_sync_to_action from sync_to_action in anticipation of new password check stuff
Diffstat (limited to 'lib/Reaction/UI/ViewPort/Field')
-rw-r--r-- | lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm b/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm index 42899c0..0d39eec 100644 --- a/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm +++ b/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm @@ -14,33 +14,54 @@ role Mutable, which { clearer => 'clear_value', ); has needs_sync => (is => 'rw', isa => 'Int', default => 0); - has message => (is => 'rw', isa => 'Str'); + #predicates are autmagically generated for lazy and non-required attrs + has message => (is => 'rw', isa => 'Str', clearer => 'clear_message'); after clear_value => sub { - shift->needs_sync(1); + my $self = shift; + $self->clear_message if $self->has_message; + $self->needs_sync(1); }; implements adopt_value => as { my ($self) = @_; + $self->clear_message if $self->has_message; $self->needs_sync(1); # if $self->has_attribute; }; - implements sync_to_action => as { - my ($self) = @_; - return unless $self->needs_sync; + implements can_sync_to_action => as { + my $self = shift; + return 1 unless $self->needs_sync; my $attr = $self->attribute; if ($self->has_value) { my $value = $self->value; if (my $tc = $attr->type_constraint) { $value = $tc->coercion->coerce($value) if ($tc->has_coercion); - #my $error = $tc->validate($self->value); # should we be checking against $value? - my $error = $tc->validate($value); - if (defined $error) { + if (defined (my $error = $tc->validate($value))) { $self->message($error); return; } } + } else { + return if $attr->is_required; + } + return 1; + }; + + implements sync_to_action => as { + my ($self) = @_; + return unless $self->needs_sync; + return unless $self->can_sync_to_action; + + my $attr = $self->attribute; + + if ($self->has_value) { + my $value = $self->value; + if (my $tc = $attr->type_constraint) { + #this will go away when we have moose dbic. until then though... + $value = $tc->coercion->coerce($value) if ($tc->has_coercion); + } my $writer = $attr->get_write_method; confess "No writer for attribute" unless defined($writer); $self->model->$writer($value); |