lib/Form/Sensible/Field/Text.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 10 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 96.3% 52 / 54 CC 7 SCAR 10.4
CC
7
Cov
98%
__ANON__
4.0
__ANON__
3.0
get_additional_configuration
2.0
CRAP 2.8
« lib/Form/Sensible.pm ↑ Summary lib/Form/Sensible/Field/Toggle.pm »
1 package Form::Sensible::Field::Text;
2  
3 16 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 extends 'Form::Sensible::Field';
6  
7 ## provides a plain text field
8  
9 16 has 'maximum_length' => (
10 is => 'rw',
11 isa => 'Int',
12 required => 1,
13 default => 256,
14 );
15  
16 16 has 'minimum_length' => (
17 is => 'rw',
18 isa => 'Int',
19 required => 0,
20 );
21  
22 16 has 'should_truncate' => (
23 is => 'rw',
24 isa => 'Bool',
25 required => 1,
26 default => 0,
27 );
28  
29 ## does truncation if should_truncate is set.
30 194 ▶around 'value' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
31 194 my $orig = shift;
32 194 my $self = shift;
33  
34 194 ▶ return $self->$orig() if ! @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 154 40 194
35  
36 40 my $value = shift;
37 40 ▶ if ($self->should_truncate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->should_truncate) 3 37 40
38 3 return $self->$orig(substr($value,0,$self->maximum_length));
39 }
40 37 return $self->$orig($value);
41 16 };
42  
43 1 ▶sub get_additional_configuration {
Subroutine get_additional_configuration: called CC=2 SCAR=6.9
Pod documented
44 1 my ($self) = @_;
45  
46 1 ▶ return { map { defined( $self->$_ ) ? ( $_ => $self->$_ ) : () }
Branch: 1 branch
BranchTrueFalseTotal
defined $self->$_ ? : 2 1 3
47 qw/maximum_length minimum_length should_truncate/
48 };
49 }
50  
51 27 ▶around 'validate' => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
52 27 my $orig = shift;
53 27 my $self = shift;
54  
55 27 my @errors;
56 27 push @errors, $self->$orig(@_);
57 27 ▶ if (length($self->value) > $self->maximum_length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->value > $self->maximum_length) 4 23 27
58 4 push @errors, "_FIELDNAME_ is too long";
59 }
60 27 ▶ if ($self->minimum_length && (length($self->value) < $self->minimum_length)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->minimum_length and length $self->value < $self->minimum_length) 1 26 27
Condition66%2/3
$self->minimum_length and length $self->value < $self->minimum_length
!ll&&!rl&&r
2601
MC/DC50%1/2
$self->minimum_length and length $self->value < $self->minimum_length
$self->minimum_length length $self->value < $self->minimum_length
Truth table66%2/3
A and B
A= $self->minimum_lengthB= length $self->value < $self->minimum_length
ABresult
0X0
100
111
61 1 push @errors, "_FIELDNAME_ is too short";
62 }
63  
64 27 return @errors;
65 16 };
66  
67 16 __PACKAGE__->meta->make_immutable;
68 16 1;
69  
70 __END__
« lib/Form/Sensible.pm ↑ Summary lib/Form/Sensible/Field/Toggle.pm »