X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FViewPort%2FField%2FMutable%2FDateTime.pm;h=27181f5369032541653d32d8ce252c151dc3e74b;hb=d4667bef2fd27182a34a72d368090a3c26e2bd45;hp=8bde97f3de707cea12ff51e19a2835d22557f766;hpb=6a531d965cddbd184768ec04f65339b359652eb1;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm b/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm index 8bde97f..27181f5 100644 --- a/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm +++ b/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm @@ -4,41 +4,25 @@ use Reaction::Class; use Time::ParseDate; use DateTime; -class 'Reaction::UI::ViewPort::Field::Mutable::DateTime', - is 'Reaction::UI::ViewPort::Field::DateTime', which { - - does 'Reaction::UI::ViewPort::Field::Role::Mutable'; - - has value_string => - ( is => 'rw', isa => 'Str', lazy_build => 1, trigger_adopt('value_string') ); - - 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(@_); - }; - - implements adopt_value_string => as { - my ($self) = @_; - my $value = $self->value_string; - my ($epoch) = Time::ParseDate::parsedate($value); - if (defined $epoch) { - my $dt = 'DateTime'->from_epoch( epoch => $epoch ); - $self->value($dt); - } else { - $self->message("Could not parse date or time"); - } - }; - - around accept_events => sub { ('value_string', shift->(@_)) }; - +use namespace::clean -except => [ qw(meta) ]; +extends 'Reaction::UI::ViewPort::Field::DateTime'; + +with 'Reaction::UI::ViewPort::Field::Role::Mutable::Simple'; +sub adopt_value_string { + my ($self) = @_; + my $value = $self->value_string; + my ($epoch) = Time::ParseDate::parsedate($value); + if (defined $epoch) { + my $dt = 'DateTime'->from_epoch( epoch => $epoch ); + $self->value($dt); + } else { + $self->value($self->value_string); + } }; +__PACKAGE__->meta->make_immutable; + + 1;