aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm
diff options
context:
space:
mode:
authormatthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-02-03 14:03:21 +0000
committermatthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-02-03 14:03:21 +0000
commit62ffa273e3c709800ea7f4a19f9f28e9b1da5867 (patch)
tree46eb7f6d32b731382e6f21312a48f697cbc2260c /lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm
parent2490a71f2c09f04beefe516528c92274f6d06592 (diff)
downloadreaction-62ffa273e3c709800ea7f4a19f9f28e9b1da5867.tar.gz
reaction-62ffa273e3c709800ea7f4a19f9f28e9b1da5867.zip
simple mutable fields now use value_string (ChooseMany unconverted)
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;