| 1 | package HTML::FormHandler::Field::Duration; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: DateTime::Duration from HTML form values | ||||||||||||||||||||||||||||
| 3 | 2 | $HTML::FormHandler::Field::Duration::VERSION = '0.410002'; | |||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | extends 'HTML::FormHandler::Field::Compound'; | |||||||||||||||||||||||||||
| 6 | 2 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | our $class_messages = { | |||||||||||||||||||||||||||
| 10 | 'duration_invalid' => 'Invalid value for [_1]: [_2]', | ||||||||||||||||||||||||||||
| 11 | }; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | sub get_class_messages { | ||||||||||||||||||||||||||
|
Subroutine
get_class_messages: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 15 | return { | ||||||||||||||||||||||||||||
| 16 | 2 | %{ $self->next::method }, | |||||||||||||||||||||||||||
| 17 | %$class_messages, | ||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 4 | ▶ | sub validate { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 4 | my @dur_parms; | |||||||||||||||||||||||||||
| 26 | 4 | foreach my $child ( $self->all_fields ) { | |||||||||||||||||||||||||||
| 27 | 8 | ▶ | unless ( $child->has_value && $child->value =~ /^\d+$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$child->has_value and $child->value =~ /^\d+$/
MC/DC50%1/2
$child->has_value and $child->value =~ /^\d+$/
$child->has_value
$child->value =~ /^\d+$/
Truth table66%2/3
A and B
A= $child->has_valueB= $child->value =~ /^\d+$/
| |||||||||||||||||||||||||||||
| 28 | 2 | $self->add_error( $self->get_message('duration_invalid'), $self->loc_label, $child->loc_label ); | |||||||||||||||||||||||||||
| 29 | 2 | next; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 6 | push @dur_parms, ( $child->accessor => $child->value ); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # set the value | ||||||||||||||||||||||||||||
| 35 | 4 | my $duration = DateTime::Duration->new(@dur_parms); | |||||||||||||||||||||||||||
| 36 | 4 | $self->_set_value($duration); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 40 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 2 | 1; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | __END__ | ||||||||||||||||||||||||||||