| 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
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 40 | my $value = shift; | |||||||||||||||||||||||||||
| 37 | 40 | ▶ | if ($self->should_truncate) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 58 | 4 | push @errors, "_FIELDNAME_ is too long"; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 27 | ▶ | if ($self->minimum_length && (length($self->value) < $self->minimum_length)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->minimum_length and length $self->value < $self->minimum_length
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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||