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=8139388160b0a38002b22ff95c3fee3d8380f156;hp=71428e5918d0dff27b38f2ab666304069c248fde;hpb=36d54b146cfba17f5c7757eced453429ee31c780;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 71428e5..27181f5 100644 --- a/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm +++ b/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm @@ -4,32 +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') ); - - 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"); - $self->clear_value; - $self->needs_sync(1); - } - }; - - 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;