« blib/lib/Rose/HTML/Form/Field/CheckboxGroup.pm
↑ Summary
blib/lib/Rose/HTML/Form/Field/Submit.pm »
| 1 | package Rose::HTML::Form::Field::DateTime; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Rose::HTML::Object::Errors qw(:field :date); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Rose::DateTime::Util(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Rose::DateTime::Parser; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use base 'Rose::HTML::Form::Field::Text'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | our $VERSION = '0.606'; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | use Rose::Object::MakeMethods::Generic | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | 'scalar --get_set_init' => | |||||||||||||||||||||||||||||||||||||||||
| 17 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 'date_parser', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 'output_format', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | __PACKAGE__->add_required_html_attr( | |||||||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | size => 25, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 18 | ▶ | sub init_date_parser { Rose::DateTime::Parser->new() } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_date_parser: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | sub time_zone | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
time_zone: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | my($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | my $parser = $self->date_parser; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | return $parser->time_zone(@_) if($parser->can('time_zone')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | sub inflate_value | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 348 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inflate_value: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 348 | my($self, $date) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 348 | ▶ | return undef unless(ref $date || (defined $date && length $date)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $date or defined $date and length $date
defined $date and length $date
MC/DC66%2/3
ref $date or defined $date and length $date
ref $date
defined $date
length $date
Truth table75%3/4
A or B and C
A= ref $dateB= defined $dateC= length $date
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 178 | my $dt; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 178 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 178 | eval { $dt = $self->date_parser->parse_datetime($date) }; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 178 | return $dt; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | ▶ | sub init_output_format { '%Y-%m-%d %I:%M:%S %p' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_output_format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | sub deflate_value | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 32 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deflate_value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 32 | my($self, $date) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 32 | ▶ | return $self->input_value_filtered unless($date); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 23 | return Rose::DateTime::Util::format_date($date, $self->output_format); | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | sub validate | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 33 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 33 | my($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 33 | ▶ | if($self->input_value !~ /\S/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 9 | my $ok = $self->SUPER::validate(@_); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 9 | ▶ | return $ok unless($ok); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 33 | my $date = $self->internal_value; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 33 | ▶ | if(UNIVERSAL::isa($date, 'DateTime')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 17 | ▶ | return $self->validate_with_validator($date) if($self->validator); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 17 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 16 | ▶ | if($self->has_partial_value) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | $self->add_error_id(FIELD_PARTIAL_VALUE); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 15 | my $input = $self->input_value_filtered; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 6 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 15 | ▶ | return 1 unless(length $input); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 7 | $date = $self->date_parser->parse_datetime($input); | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 7 | ▶ | unless(defined $date) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # XXX: Parser errors ar English-only right now... | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # XXX: ...but it produces some horribly ugly errors. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | #if($self->locale eq 'en') | ||||||||||||||||||||||||||||||||||||||||||
| 99 | #{ | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # $self->add_error($self->date_parser->error) | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # if($self->date_parser->can('error')); | ||||||||||||||||||||||||||||||||||||||||||
| 102 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 103 | #else | ||||||||||||||||||||||||||||||||||||||||||
| 104 | #{ | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 7 | $self->add_error_id(DATE_INVALID); | |||||||||||||||||||||||||||||||||||||||||
| 106 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | die "This should never be reached!"; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 6 | ▶ | if(__PACKAGE__->localizer->auto_load_messages) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | __PACKAGE__->localizer->load_all_messages; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 6 | ▶ | use utf8; # The __DATA__ section contains UTF-8 text | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||