| 1 | package Data::MuForm::Field::Text; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Text field | ||||||||||||||||||||||||||||
| 3 | 85 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 85 | extends 'Data::MuForm::Field'; | |||||||||||||||||||||||||||
| 5 | 85 | ▶ | use List::Util ('all'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 85 | has 'size' => ( is => 'rw', default => 0 ); | |||||||||||||||||||||||||||
| 8 | 85 | has 'maxlength' => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 9 | 85 | has 'minlength' => ( is => 'rw', default => '0' ); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 37 | ▶ | sub build_input_type { 'text' } | ||||||||||||||||||||||||||
|
Subroutine
build_input_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 85 | our $class_messages = { | |||||||||||||||||||||||||||
| 14 | 'text_maxlength' => 'Field should not exceed {maxlength} characters. You entered {length}', | ||||||||||||||||||||||||||||
| 15 | 'text_minlength' => 'Field must be at least {minlength} characters. You entered {length}', | ||||||||||||||||||||||||||||
| 16 | 'multiple_values_disallowed' => 'Field must contain a single value', | ||||||||||||||||||||||||||||
| 17 | }; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub get_class_messages { | ||||||||||||||||||||||||||||
| 20 | 42 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_class_messages: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | my $messages = { | ||||||||||||||||||||||||||||
| 22 | 42 | %{ $self->next::method }, | |||||||||||||||||||||||||||
| 23 | %$class_messages, | ||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||
| 25 | 42 | return $messages; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub base_render_args { | ||||||||||||||||||||||||||||
| 29 | 46 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
base_render_args: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 46 | my $args = $self->next::method(@_); | |||||||||||||||||||||||||||
| 31 | 46 | ▶ | $args->{element_attr}->{size} = $self->size if $self->size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 46 | ▶ | $args->{element_attr}->{maxlength} = $self->maxlength if $self->maxlength; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 46 | ▶ | $args->{element_attr}->{minlength} = $self->minlenght if $self->minlength; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 46 | return $args; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub normalize_input { | ||||||||||||||||||||||||||||
| 38 | 383 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
normalize_input: called CC=5 SCAR=24.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 383 | my $input = $self->input; | |||||||||||||||||||||||||||
| 41 | 383 | ▶ | if ( ref $input eq 'ARRAY' && ! $self->multiple ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $input eq "ARRAY" and not $self->multiple
MC/DC0%0/2
ref $input eq "ARRAY" and not $self->multiple
ref $input eq "ARRAY"
not $self->multiple
Truth table66%2/3
A and not(B)
A= ref $input eq "ARRAY"B= not $self->multiple
| |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ( scalar @$input == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 43 | 0 | $self->input(''); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | elsif ( all { $_ eq $input->[0] } @$input ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 46 | 0 | $self->input($input->[0]); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | else { | ||||||||||||||||||||||||||||
| 49 | 0 | $self->add_error( $self->get_message('multiple_values_disallowed') ); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub validate { | ||||||||||||||||||||||||||||
| 55 | 301 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 301 | ▶ | return unless $self->next::method; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 301 | my $value = $self->value; | |||||||||||||||||||||||||||
| 59 | # Check for max length | ||||||||||||||||||||||||||||
| 60 | 301 | ▶ | if ( my $maxlength = $self->maxlength ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 11 | ▶ | return $self->add_error( $self->get_message('text_maxlength'), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | maxlength => $maxlength, length => length $value, field_label =>$self->loc_label ) | ||||||||||||||||||||||||||||
| 63 | if length $value > $maxlength; | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # Check for min length | ||||||||||||||||||||||||||||
| 67 | 298 | ▶ | if ( my $minlength = $self->minlength ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 6 | ▶ | return $self->add_error( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | $self->get_message('text_minlength'), | ||||||||||||||||||||||||||||
| 70 | minlength => $minlength, length => length $value, field_label => $self->loc_label ) | ||||||||||||||||||||||||||||
| 71 | if length $value < $minlength; | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 296 | return 1; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 85 | 1; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =pod | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head1 NAME | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | Data::MuForm::Field::Text - Text field | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head1 VERSION | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | version 0.04 | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Gerda Shank | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | This software is copyright (c) 2017 by Gerda Shank. | ||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||