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 | |
81393881 |
7 | use namespace::clean -except => [ qw(meta) ]; |
8 | with Mutable; |
9 | |
10 | has value_string => ( |
11 | is => 'rw', lazy_build => 1, trigger_adopt('value_string'), |
12 | clearer => 'clear_value', |
13 | ); |
14 | |
15 | around 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" |
29 | requires 'adopt_value_string'; |
62ffa273 |
30 | |
81393881 |
31 | around accept_events => sub { ('value_string', shift->(@_)) }; |
62ffa273 |
32 | |
81393881 |
33 | around force_events => sub { (value_string => '', shift->(@_)) }; |
62ffa273 |
34 | |
881dd557 |
35 | |
62ffa273 |
36 | |
37 | 1; |