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