Diva.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 4 / 4 Conditioncond 81.8% 9 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 93.6% 74 / 79 CC 8 SCAR 14.2
CC
8
Cov
97%
_build_diva
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.1
↑ Summary Diva/Adapter.pm »
1 package Form::Tiny::Plugin::Diva;
2 4 $Form::Tiny::Plugin::Diva::VERSION = '1.03';
3 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Form::Tiny::Plugin::Diva::Adapter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Form::Tiny::Plugin::Diva::MetaRole;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use parent 'Form::Tiny::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub plugin
13 4 ▶{
Subroutine plugin: called CC=1 SCAR=0.0
Pod documented
14 4 my ($self, $caller, $context) = @_;
15  
16 return {
17 subs => {
18 2 ▶ diva_config => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
19 2 $$context = undef;
20 2 $caller->form_meta->add_diva_config(@_);
21 },
22 },
23  
24 4 roles => [__PACKAGE__],
25 meta_roles => ['Form::Tiny::Plugin::Diva::MetaRole'],
26 };
27 }
28  
29 4 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 4 has 'diva' => (
33 is => 'ro',
34 builder => '_build_diva',
35 lazy => 1,
36 init_arg => undef,
37 );
38  
39 sub _build_diva
40 4 ▶{
Subroutine _build_diva: called CC=8 SCAR=20.8
41 4 my ($self) = @_;
42 4 my %config = %{$self->form_meta->diva_config};
43  
44 4 my @fields;
45 my @hidden;
46  
47 4 for my $field (@{$self->field_defs}) {
48 my %field_data = (
49 12 ▶ %{$field->data // {type => 'hidden'}},
Condition100%2/2
$field->data // {"type", "hidden"}
l!l
93
MC/DC100%1/1
$field->data // {"type", "hidden"}
$field->data
Truth table100%2/2
A
A= $field->data
Aresult
11
00
50 name => $field->name,
51 );
52  
53 12 ▶ if ($field->has_default && !exists $field_data{d} && !exists $field_data{default}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->has_default and not exists $field_data{"d"} and not exists $field_data{"default"}) 2 10 12
Condition83%5/6
$field->has_default and not exists $field_data{"d"} and not exists $field_data{"default"}
!ll&&!rl&&r
1002
$field->has_default and not exists $field_data{"d"}
!ll&&!rl&&r
912
MC/DC66%2/3
$field->has_default and not exists $field_data{"d"} and not exists $field_data{"default"}
$field->has_default not exists $field_data{"d"} not exists $field_data{"default"}
Truth table75%3/4
A and not(B) and not(C)
A= $field->has_defaultB= not exists $field_data{"d"}C= not exists $field_data{"default"}
ABCresult
0XX0
10X0
1100
1111
54 2 $field_data{default} = $field->default->($self);
55 }
56  
57 12 ▶ my $type = $field_data{type} // $field_data{t};
Condition66%2/3
$field_data{"type"} // $field_data{"t"}
l!l&&r!l&&!r
1110
MC/DC0%0/2
$field_data{"type"} // $field_data{"t"}
$field_data{"type"} $field_data{"t"}
Truth table66%2/3
A // B
A= $field_data{"type"}B= $field_data{"t"}
ABresult
1X1
011
000
58 12 ▶ my $push_to = lc $type eq 'hidden' ? \@hidden : \@fields;
Branch: 1 branch
BranchTrueFalseTotal
lc $type eq 'hidden' ? : 5 7 12
59 12 push @$push_to, {%field_data, comment => \%field_data};
60 }
61  
62 4 my $obj = Form::Tiny::Plugin::Diva::Adapter->new(
63 %config,
64 form => \@fields,
65 hidden => \@hidden,
66  
67 form_instance => $self,
68 );
69  
70 4 weaken $obj->{form_instance};
71 4 return $obj;
72 }
73  
74 4 1;
75  
76 __END__
↑ Summary Diva/Adapter.pm »