Zapp/Type/SelectBox.pm

filter: Statementstmt 36.6% 11 / 30 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 23.0% 3 / 13 Podpod 100% 4 / 4 totaltotal 28.1% 18 / 64 CC 5 SCAR 15.0
CC
5
Cov
27%
_check_value
12.0
_value_label
6.0
_field_values
6.0
CRAP 4.5
« Zapp/Type.pm ↑ Summary Zapp/Task/Action/Confirm.pm »
1 package Zapp::Type::SelectBox;
2 3 ▶use Mojo::Base 'Zapp::Type', -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use List::Util qw( any first );
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Mojo::Loader qw( data_section );
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # XXX: This cannot be used as task output without default options!
7 # Should we have a way to configure options in task output, or should we
8 # have a way to disable types for output?
9  
10 0 ▶has default_options => sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=1.2
11  
12 ▶sub _value_label( $self, $config, $value ) {
Subroutine _value_label: not called CC=2 SCAR=17.9
13 0 ▶ my $option = first { $_->{value} eq $value } $config->{options}->@*;
Subroutine __ANON__: not called CC=1 SCAR=6.9
14 0 ▶ return $option->{label} // $value;
Condition0%0/3
$option->{"label"} // $value
l!l&&r!l&&!r
000
MC/DC0%0/2
$option->{"label"} // $value
$option->{"label"} $value
Truth table0%0/3
A // B
A= $option->{"label"}B= $value
ABresult
1X1
011
000
15 }
16  
17 ▶sub _field_values( $self, $config, $selected_value ) {
Subroutine _field_values: not called CC=2 SCAR=17.9
18 0 ▶ $selected_value //= $config->{options}[ $config->{selected_index} ]{value};
Condition0%0/3
$selected_value //= $config->{"options"}[$config->{"selected_index"}]{"value"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$selected_value //= $config->{"options"}[$config->{"selected_index"}]{"value"}
$selected_value $config->{"options"}[$config->{"selected_index"}]{"value"}
Truth table0%0/3
A //= B
A= $selected_valueB= $config->{"options"}[$config->{"selected_index"}]{"value"}
ABresult
1X1
011
000
19 return [
20 map {
21 [
22 $_->{label}, $_->{value},
23 0 ( selected => 'selected' )x!!( $_->{value} eq $selected_value ),
24 ]
25 0 } @{ $config->{options} }
26 ];
27 }
28  
29 ▶sub _check_value( $self, $options, $value ) {
Subroutine _check_value: not called CC=3 SCAR=24.8
30 0 ▶ $options //= $self->default_options;
Condition0%0/3
$options //= $self->default_options
l!l&&r!l&&!r
000
MC/DC0%0/2
$options //= $self->default_options
$options $self->default_options
Truth table0%0/3
A //= B
A= $optionsB= $self->default_options
ABresult
1X1
011
000
31 die "Invalid value for selectbox: $value"
32 0 ▶ unless any { $_->{value} eq $value } @{$options};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $_->{"value"} eq $value; } , @{$options;}) 0 0 0
33 }
34  
35 # Form value -> Type value
36 ▶sub process_config( $self, $c, $form_value ) {
Subroutine process_config: not called CC=1 SCAR=6.9
Pod documented
37 0 return $form_value;
38 }
39  
40 ▶sub process_input( $self, $c, $config_value, $form_value ) {
Subroutine process_input: not called CC=1 SCAR=6.9
Pod documented
41 0 $self->_check_value( $config_value->{options}, $form_value );
42 0 return $form_value;
43 }
44  
45 # Type value -> Task value
46 ▶sub task_input( $self, $config_value, $input_value ) {
Subroutine task_input: not called CC=1 SCAR=6.9
Pod documented
47 0 $self->_check_value( $config_value->{options}, $input_value );
48 0 return $input_value;
49 }
50  
51 # Task value -> Type value
52 ▶sub task_output( $self, $config_value, $task_value ) {
Subroutine task_output: not called CC=1 SCAR=6.9
Pod documented
53 0 $self->_check_value( $config_value->{options}, $task_value );
54 0 return $task_value;
55 }
56  
57 3 1;
58  
59 =pod
60  
61 =head1 NAME
62  
63 Zapp::Type::SelectBox
64  
65 =head1 VERSION
66  
67 version 0.001
68  
69 =head1 AUTHOR
70  
71 Doug Bell <preaction@cpan.org>
72  
73 =head1 COPYRIGHT AND LICENSE
74  
75 This software is copyright (c) 2020 by Doug Bell.
76  
77 This is free software; you can redistribute it and/or modify it under
78 the same terms as the Perl 5 programming language system itself.
79  
80 =cut
81  
82 __DATA__
« Zapp/Type.pm ↑ Summary Zapp/Task/Action/Confirm.pm »