MuForm/Field/Text.pm

filter: Statementstmt 87.1% 34 / 39 Branchbran 68.1% 15 / 22 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 7 / 8 Podpod 20.0% 1 / 5 totaltotal 74.6% 59 / 79 SCAR 26.7
CC
13
Cov
80%
normalize_input
11.8
validate
6.0
base_render_args
4.0
CRAP 14.4
« MuForm/Field/CompoundDateTime.pm ↑ Summary MuForm/Field/List.pm »
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
BranchTrueFalseTotal
if $self->size 7 39 46
32 46 ▶ $args->{element_attr}->{maxlength} = $self->maxlength if $self->maxlength;
Branch: 1 branch
BranchTrueFalseTotal
if $self->maxlength 7 39 46
33 46 ▶ $args->{element_attr}->{minlength} = $self->minlenght if $self->minlength;
Branch: 1 branch
BranchTrueFalseTotal
if $self->minlength 0 46 46
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
BranchTrueFalseTotal
if (ref $input eq "ARRAY" and not $self->multiple) 0 383 383
Condition66%2/3
ref $input eq "ARRAY" and not $self->multiple
!ll&&!rl&&r
37940
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
ABresult
0X0
100
111
42 0 ▶ if ( scalar @$input == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$input == 0) { } 0 0 0
elsif (&all(sub { $_ eq $input->[0]; } , @$input)) { } 0 0 0
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
BranchTrueFalseTotal
unless $self->next::method 0 301 301
58 301 my $value = $self->value;
59 # Check for max length
60 301 ▶ if ( my $maxlength = $self->maxlength ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $maxlength = $self->maxlength) 11 290 301
61 11 ▶ return $self->add_error( $self->get_message('text_maxlength'),
Branch: 1 branch
BranchTrueFalseTotal
if length $value > $maxlength 3 8 11
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
BranchTrueFalseTotal
if (my $minlength = $self->minlength) 6 292 298
68 6 ▶ return $self->add_error(
Branch: 1 branch
BranchTrueFalseTotal
if length $value < $minlength 2 4 6
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
« MuForm/Field/CompoundDateTime.pm ↑ Summary MuForm/Field/List.pm »