proper fix for can_sync_to_action
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field / Role / Mutable / Simple.pm
CommitLineData
62ffa273 1package Reaction::UI::ViewPort::Field::Role::Mutable::Simple;
2
3use Reaction::Role;
4
5use aliased 'Reaction::UI::ViewPort::Field::Role::Mutable';
6
81393881 7use namespace::clean -except => [ qw(meta) ];
8with Mutable;
9
10has value_string => (
11 is => 'rw', lazy_build => 1, trigger_adopt('value_string'),
12 clearer => 'clear_value',
13);
14
15around value_string => sub {
16 my $orig = shift;
17 my $self = shift;
18 if (@_ && defined($_[0]) && !ref($_[0]) && $_[0] eq ''
19 && !$self->value_is_required) {
20 $self->clear_value;
21 return undef;
22 }
23 return $self->$orig(@_);
24};
62ffa273 25
81393881 26# the user needs to implement this because, honestly, you're always going
27# to need to do something custom and the only common thing really is
28# "you probably set $self->value at the end"
29requires 'adopt_value_string';
62ffa273 30
81393881 31around accept_events => sub { ('value_string', shift->(@_)) };
62ffa273 32
81393881 33around force_events => sub { (value_string => '', shift->(@_)) };
62ffa273 34
881dd557 35
62ffa273 36
371;