| 1 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Constraint::DateTime; | ||||||||||||||||||||||||||||
| 4 | 4 | $HTML::FormFu::Constraint::DateTime::VERSION = '2.06'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: DateTime constraint | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | extends 'HTML::FormFu::Constraint'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use DateTime::Format::Builder; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | has _builder => ( | ||||||||||||||||||||||||||||
| 13 | is => 'rw', | ||||||||||||||||||||||||||||
| 14 | 3 | ▶ | default => sub { DateTime::Format::Builder->new }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 4 | lazy => 1, | |||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub parser { | ||||||||||||||||||||||||||||
| 19 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parser: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | $self->_builder->parser(@_); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | return $self; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub constrain_value { | ||||||||||||||||||||||||||||
| 27 | 3 | ▶ | my ( $self, $value ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
constrain_value: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 3 | ▶ | return 1 if !defined $value || $value eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $value or $value eq ""
MC/DC0%0/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table33%1/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 3 | my $dt = $self->_builder->parse_datetime($value); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | return 1; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub clone { | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | my $clone = $self->SUPER::clone(@_); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | $clone->_builder( $self->_builder->clone ); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | return $clone; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 4 | 1; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | __END__ | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =pod | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head1 NAME | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | HTML::FormFu::Constraint::DateTime - DateTime constraint | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head1 VERSION | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | version 2.06 | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | --- | ||||||||||||||||||||||||||||
| 67 | elements: | ||||||||||||||||||||||||||||
| 68 | - type: Text | ||||||||||||||||||||||||||||
| 69 | name: start_date | ||||||||||||||||||||||||||||
| 70 | constraints: | ||||||||||||||||||||||||||||
| 71 | - type: DateTime | ||||||||||||||||||||||||||||
| 72 | parser: | ||||||||||||||||||||||||||||
| 73 | strptime: '%d-%m-%Y' | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | - type: Text | ||||||||||||||||||||||||||||
| 76 | name: end_time | ||||||||||||||||||||||||||||
| 77 | constraints: | ||||||||||||||||||||||||||||
| 78 | - type: DateTime | ||||||||||||||||||||||||||||
| 79 | parser: | ||||||||||||||||||||||||||||
| 80 | regex: !!perl/regexp '^(\d{2}) - (\d{2}) - (\d{4})$' | ||||||||||||||||||||||||||||
| 81 | params: [day, month, year] | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | An example of using the same parser declaration for both a DateTime | ||||||||||||||||||||||||||||
| 84 | constraint and a DateTime inflator, using YAML references: | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | --- | ||||||||||||||||||||||||||||
| 87 | elements: | ||||||||||||||||||||||||||||
| 88 | - type: Text | ||||||||||||||||||||||||||||
| 89 | name: date | ||||||||||||||||||||||||||||
| 90 | constraints: | ||||||||||||||||||||||||||||
| 91 | - type: DateTime | ||||||||||||||||||||||||||||
| 92 | parser: &PARSER | ||||||||||||||||||||||||||||
| 93 | strptime: '%d-%m-%Y' | ||||||||||||||||||||||||||||
| 94 | inflators: | ||||||||||||||||||||||||||||
| 95 | - type: DateTime | ||||||||||||||||||||||||||||
| 96 | parser: *PARSER | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Ensure input can later be inflated to a DateTime object. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head1 METHODS | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head2 parser | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Arguments: \%args | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | Required. Define the expected input string, so L<DateTime::Format::Builder> | ||||||||||||||||||||||||||||
| 109 | knows how to turn it into a L<DateTime> object. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Accepts arguments to be passed to L<DateTime::Format::Builder/parser>. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | Carl Franks, C<cfranks@cpan.org> | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | This library is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 120 | the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | Carl Franks <cpan@fireartist.com> | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | This software is copyright (c) 2018 by Carl Franks. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 131 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =cut | ||||||||||||||||||||||||||||