MuForm/Field/List.pm

filter: Statementstmt 95.3% 41 / 43 Branchbran 66.6% 12 / 18 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 9 / 9 Podpod 25.0% 1 / 4 totaltotal 77.3% 65 / 84 SCAR 26.4
CC
13
Cov
82%
_trigger_value
5.2
_trigger_input
5.2
validate
4.0
CRAP 14.0
« MuForm/Field/Text.pm ↑ Summary MuForm/Field/Compound.pm »
1 package Data::MuForm::Field::List;
2 # ABSTRACT: List field
3 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 extends 'Data::MuForm::Field::Text';
5 2 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 4 ▶sub multiple {1}
Subroutine multiple: called CC=1 SCAR=0.0
Pod undocumented
9  
10 2 has 'size' => ( is => 'rw' );
11 2 has 'num_extra' => ( is => 'rw' );
12  
13 # add trigger to 'value' so we can enforce arrayref value for multiple
14 2 has '+value' => ( trigger => 1 );
15 sub _trigger_value {
16 8 ▶ my ( $self, $value ) = @_;
Subroutine _trigger_value: called CC=4 SCAR=16.4
17 8 ▶ if (!defined $value || $value eq ''){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or $value eq '') { } 0 8 8
Condition33%1/3
not defined $value or $value eq ""
l!l&&r!l&&!r
008
MC/DC0%0/2
not defined $value or $value eq ""
not defined $value $value eq ""
Truth table33%1/3
not(A) or B
A= not defined $valueB= $value eq ""
ABresult
1X1
011
000
18 0 $value = [];
19 }
20 else {
21 8 ▶ $value = ref $value eq 'ARRAY' ? $value : [$value];
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 8 0 8
22 }
23 8 $self->{value} = $value;
24 }
25  
26 2 has '+input' => ( trigger => 1 );
27 sub _trigger_input {
28 4 ▶ my ( $self, $input ) = @_;
Subroutine _trigger_input: called CC=4 SCAR=16.4
29 4 ▶ if (!defined $input || $input eq ''){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $input or $input eq '') { } 0 4 4
Condition33%1/3
not defined $input or $input eq ""
l!l&&r!l&&!r
004
MC/DC0%0/2
not defined $input or $input eq ""
not defined $input $input eq ""
Truth table33%1/3
not(A) or B
A= not defined $inputB= $input eq ""
ABresult
1X1
011
000
30 0 $input = [];
31 }
32 else {
33 4 ▶ $input = ref $input eq 'ARRAY' ? $input : [$input];
Branch: 1 branch
BranchTrueFalseTotal
ref $input eq 'ARRAY' ? : 4 0 4
34 }
35 4 $self->{input} = $input;
36 }
37  
38 2 ▶has 'valid' => ( is => 'rw', isa => ArrayRef, default => sub {[]} );
Subroutine __ANON__: called CC=1 SCAR=0.0
39 sub has_valid {
40 4 ▶ my $self = shift;
Subroutine has_valid: called CC=2 SCAR=6.9
Pod undocumented
41 4 ▶ return scalar @{$self->valid} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$self->valid;} ? : 2 2 4
42 }
43  
44 sub validate {
45 4 ▶ my $self = shift;
Subroutine validate: called CC=4 SCAR=13.9
Pod documented
46  
47 4 ▶ if ( $self->has_valid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_valid) 2 2 4
48 2 my %valid;
49 2 @valid{@{$self->valid}} = ();
50 2 foreach my $value ( @{$self->value} ) {
51 6 ▶ unless ( exists $valid{$value} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $valid{$value}) 2 4 6
52 2 $self->add_error("Invalid value: '{value}'", value => $value);
53 }
54 }
55 }
56 }
57  
58 sub base_render_args {
59 1 ▶ my $self = shift;
Subroutine base_render_args: called CC=3 SCAR=11.2
Pod undocumented
60 1 my $args = $self->next::method(@_);
61 1 $args->{layout_type} = 'list';
62 1 ▶ $args->{size} = $self->size if $self->size;
Branch: 1 branch
BranchTrueFalseTotal
if $self->size 0 1 1
63 1 ▶ $args->{num_extra} = $self->num_extra if $self->num_extra;
Branch: 1 branch
BranchTrueFalseTotal
if $self->num_extra 0 1 1
64 1 return $args;
65 }
66 2 1;
67  
68 __END__
69  
70 =pod
71  
72 =encoding UTF-8
73  
74 =head1 NAME
75  
76 Data::MuForm::Field::List - List field
77  
78 =head1 VERSION
79  
80 version 0.04
81  
82 =head2 NAME
83  
84 Data::MuForm::Field::List
85  
86 =head2 DESCRIPTION
87  
88 =head1 AUTHOR
89  
90 Gerda Shank
91  
92 =head1 COPYRIGHT AND LICENSE
93  
94 This software is copyright (c) 2017 by Gerda Shank.
95  
96 This is free software; you can redistribute it and/or modify it under
97 the same terms as the Perl 5 programming language system itself.
98  
99 =cut
« MuForm/Field/Text.pm ↑ Summary MuForm/Field/Compound.pm »