aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm')
-rw-r--r--lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm b/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm
new file mode 100644
index 0000000..66fa464
--- /dev/null
+++ b/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm
@@ -0,0 +1,36 @@
+package Reaction::UI::ViewPort::Field::Role::Mutable::Simple;
+
+use Reaction::Role;
+
+use aliased 'Reaction::UI::ViewPort::Field::Role::Mutable';
+
+role Simple which {
+
+ does Mutable;
+
+ has value_string => (
+ is => 'rw', lazy_build => 1, trigger_adopt('value_string'),
+ clearer => 'clear_value',
+ );
+
+ around value_string => sub {
+ my $orig = shift;
+ my $self = shift;
+ if (@_ && defined($_[0]) && !ref($_[0]) && $_[0] eq ''
+ && !$self->value_is_required) {
+ $self->clear_value;
+ return undef;
+ }
+ return $self->$orig(@_);
+ };
+
+ # the user needs to implement this because, honestly, you're always going
+ # to need to do something custom and the only common thing really is
+ # "you probably set $self->value at the end"
+ requires 'adopt_value_string';
+
+ around accept_events => sub { ('value_string', shift->(@_)) };
+
+};
+
+1;