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=f792e5c0be14bd58200c8a2f935687230d1fe283;hpb=ddccc6a29affc90888a59f14d698fd3afb2757dc;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 f792e5c..27181f5 100644 --- a/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm +++ b/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm @@ -4,34 +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); - } - }; - - override accept_events => sub { - ('value_string', super()); - }; - +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;