| 1 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | |||||||||||
| 3 | package HTML::FormFu::Deflator::Strftime; | ||||||||||
| 4 | 9 | $HTML::FormFu::Deflator::Strftime::VERSION = '2.06'; | |||||||||
| 5 | # ABSTRACT: Strftime deflator | ||||||||||
| 6 | |||||||||||
| 7 | 9 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 9 | ▶ | use MooseX::Attribute::Chained; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 9 | extends 'HTML::FormFu::Deflator'; | |||||||||
| 10 | |||||||||||
| 11 | 9 | has strftime => ( is => 'rw', traits => ['Chained'] ); | |||||||||
| 12 | |||||||||||
| 13 | sub deflator { | ||||||||||
| 14 | 13 | ▶ | my ( $self, $value ) = @_; | ||||||||
|
Subroutine
deflator: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 15 | |||||||||||
| 16 | 13 | my $return; | |||||||||
| 17 | |||||||||||
| 18 | 13 | eval { | |||||||||
| 19 | 13 | my $locale = $self->locale; | |||||||||
| 20 | |||||||||||
| 21 | 13 | ▶ | $value->set_locale($locale) if defined $locale; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | }; | ||||||||||
| 23 | |||||||||||
| 24 | 13 | eval { $return = $value->strftime( $self->strftime ) }; | |||||||||
| 25 | |||||||||||
| 26 | 13 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 4 | $return = $value; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 13 | return $return; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 9 | __PACKAGE__->meta->make_immutable; | |||||||||
| 34 | |||||||||||
| 35 | 9 | 1; | |||||||||
| 36 | |||||||||||
| 37 | __END__ | ||||||||||
| 38 | |||||||||||
| 39 | =pod | ||||||||||
| 40 | |||||||||||
| 41 | =encoding UTF-8 | ||||||||||
| 42 | |||||||||||
| 43 | =head1 NAME | ||||||||||
| 44 | |||||||||||
| 45 | HTML::FormFu::Deflator::Strftime - Strftime deflator | ||||||||||
| 46 | |||||||||||
| 47 | =head1 VERSION | ||||||||||
| 48 | |||||||||||
| 49 | version 2.06 | ||||||||||
| 50 | |||||||||||
| 51 | =head1 SYNOPSIS | ||||||||||
| 52 | |||||||||||
| 53 | $form->deflator( Strftime => 'start_time' ) | ||||||||||
| 54 | ->strftime( '%d/%m/%Y' ); | ||||||||||
| 55 | |||||||||||
| 56 | --- | ||||||||||
| 57 | elements: | ||||||||||
| 58 | - type: Text | ||||||||||
| 59 | inflators: | ||||||||||
| 60 | - type: DateTime | ||||||||||
| 61 | parser: | ||||||||||
| 62 | strptime: "%Y/%m/%d" | ||||||||||
| 63 | deflator: | ||||||||||
| 64 | - type: Strftime | ||||||||||
| 65 | strftime: "%Y/%m/%d" | ||||||||||
| 66 | |||||||||||
| 67 | =head1 DESCRIPTION | ||||||||||
| 68 | |||||||||||
| 69 | Strftime deflator for L<DateTime> objects. | ||||||||||
| 70 | |||||||||||
| 71 | When you redisplay a form to the user following an invalid submission, | ||||||||||
| 72 | any fields with DateTime inflators will stringify to something like | ||||||||||
| 73 | '1970-01-01T00:00:00'. In most cases it makes more sense to use the same | ||||||||||
| 74 | format you've asked the user for. This deflator allows you to specify a | ||||||||||
| 75 | more suitable and user-friendly format. | ||||||||||
| 76 | |||||||||||
| 77 | This deflator calls L<DateTime>'s C<strftime> method. Possible values for | ||||||||||
| 78 | the format string are documented at | ||||||||||
| 79 | L<http://search.cpan.org/dist/DateTime/lib/DateTime.pm#strftime_Patterns>. | ||||||||||
| 80 | |||||||||||
| 81 | If you set the form's locale (see L<HTML::FormFu/locale>) this is set on the DateTime object. Now you can use C<%x> to get the default date or C<%X> for the default time for the object's locale. | ||||||||||
| 82 | |||||||||||
| 83 | =head1 AUTHOR | ||||||||||
| 84 | |||||||||||
| 85 | Carl Franks, C<cfranks@cpan.org> | ||||||||||
| 86 | |||||||||||
| 87 | =head1 LICENSE | ||||||||||
| 88 | |||||||||||
| 89 | This library is free software, you can redistribute it and/or modify it under | ||||||||||
| 90 | the same terms as Perl itself. | ||||||||||
| 91 | |||||||||||
| 92 | =head1 AUTHOR | ||||||||||
| 93 | |||||||||||
| 94 | Carl Franks <cpan@fireartist.com> | ||||||||||
| 95 | |||||||||||
| 96 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 97 | |||||||||||
| 98 | This software is copyright (c) 2018 by Carl Franks. | ||||||||||
| 99 | |||||||||||
| 100 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 101 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 102 | |||||||||||
| 103 | =cut | ||||||||||