X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FViewPort%2FField%2FDateTime.pm;h=46fbb60ac4e1502eeb5b46d8ca1625095d71ca34;hb=7ea45b2aff36dd61953b1517a1cfb079dcea230c;hp=51232cf93bc76d5a683b768efeb38cfc9464c33e;hpb=1734a92a996a20dd6d292fc4aea58e876c24249b;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/ViewPort/Field/DateTime.pm b/lib/Reaction/UI/ViewPort/Field/DateTime.pm index 51232cf..46fbb60 100644 --- a/lib/Reaction/UI/ViewPort/Field/DateTime.pm +++ b/lib/Reaction/UI/ViewPort/Field/DateTime.pm @@ -2,31 +2,27 @@ package Reaction::UI::ViewPort::Field::DateTime; use Scalar::Util 'blessed'; use Reaction::Class; -use Reaction::Types::DateTime; +use Reaction::Types::DateTime (); use aliased 'Reaction::UI::ViewPort::Field'; -class DateTime is Field, which { - has '+value' => (isa => 'DateTime'); +use namespace::clean -except => [ qw(meta) ]; +extends Field; - has value_string_default_format => ( - isa => 'Str', is => 'rw', required => 1, default => sub { "%F %H:%M:%S" } - ); - implements _build_value_string => as { - my $self = shift; - # XXX - # aha, I know why the fucker's lazy - # it's because if value's calculated - # it needs to be possible to clear it - # eval { $self->value } ... is probably the best solution atm - my $value = $self->value; - return '' unless blessed $value; - my $format = $self->value_string_default_format; - return $value->strftime($format); - }; +has '+value' => (isa => Reaction::Types::DateTime::DateTime()); - implements _empty_value => as { undef }; +has value_string_default_format => ( + isa => 'Str', is => 'rw', required => 1, default => sub { "%F %H:%M:%S" } +); +around _value_string_from_value => sub { + my $orig = shift; + my $self = shift; + my $format = $self->value_string_default_format; + return $self->$orig(@_)->strftime($format); }; +__PACKAGE__->meta->make_immutable; + + 1;