lib/HTML/FormFu/Role/Populate.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 80.0% 8 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 91.0% 61 / 67 CC 8 SCAR 14.8
CC
8
Cov
93%
populate
7.0
__ANON__
2.0
BEGIN
1.0
CRAP 4.4
« lib/HTML/FormFu/Element/Password.pm ↑ Summary lib/HTML/FormFu/Role/Element/FieldMethods.pm »
1 523 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Role::Populate;
4 # ABSTRACT: Populate role
5 523 $HTML::FormFu::Role::Populate::VERSION = '2.09';
6 523 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 523 ▶use Scalar::Util qw( reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 523 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5268 ▶after BUILD => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
12 5268 my ( $self, $args ) = @_;
13  
14 5268 ▶ $args ||= {};
Condition50%1/2
$args ||= {}
l!l
52680
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
15  
16 # get args handled by Moose so they aren't set twice
17 141269 my %init_args = map { $_->{init_arg} => 1 }
18 5268 grep { defined $_->{init_arg} } $self->meta->get_all_attributes;
19  
20 # remove defaults set in HTML::FormFu::BUILD because they need to be set for a third time
21 5268 delete @init_args{ keys %{$HTML::FormFu::build_defaults} };
22 my %args
23 5268 = map { $_ => $args->{$_} } grep { !exists $init_args{$_} } keys %$args;
24 5268 $self->populate( \%args );
25  
26 5268 return;
27 523 };
28  
29 8174 ▶sub populate {
Subroutine populate: called CC=7 SCAR=19.5
Pod undocumented
30 8174 my ( $self, $arg_ref ) = @_;
31  
32 8174 ▶ croak "argument to populate() must be a hash-ref"
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($arg_ref) ne "HASH" 0 8174 8174
33 if reftype($arg_ref) ne 'HASH';
34  
35 # shallow clone the args so we don't stomp on them
36 8174 my %args = %$arg_ref;
37  
38 # we have to handle element_defaults separately, as it is no longer a
39 # simple hash key
40  
41 8174 ▶ if ( exists $args{element_defaults} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"element_defaults"}) 0 8174 8174
42 0 $self->element_defaults( delete $args{element_defaults} );
43 }
44  
45 # handle any 'roles' first
46 8174 my $roles = delete $args{roles};
47  
48 # notes for @defer_keys...
49 # 'options', 'values', 'value_range' is for _Group elements,
50 # to ensure any 'empty_first' value gets set first
51  
52 8174 my @defer_keys = qw(
53 default_args
54 auto_fieldset
55 load_config_file
56 element elements
57 default_values
58 constraints_from_dbic
59 filter filters
60 constraint constraints
61 inflator inflators
62 deflator deflators
63 query
64 validator validators
65 transformer transformers
66 plugins
67 options
68 values
69 value_range
70 );
71  
72 8174 my %defer;
73 8174 for (@defer_keys) {
74 196176 ▶ $defer{$_} = delete $args{$_} if exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$_} 643 195533 196176
75 }
76  
77 8174 eval {
78 8174 ▶ if ($roles) {
Branch: 1 branch
BranchTrueFalseTotal
if ($roles) 3 8171 8174
79 3 $self->roles($roles);
80 }
81  
82 8174 map { $self->$_( delete $args{$_} ) } keys %args;
83  
84 643 map { $self->$_( $defer{$_} ) }
85 8173 grep { exists $defer{$_} } @defer_keys;
86 };
87 8174 ▶ croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 8173 8174
88  
89 8173 return $self;
90 }
91  
92 523 1;
93  
94 __END__
« lib/HTML/FormFu/Element/Password.pm ↑ Summary lib/HTML/FormFu/Role/Element/FieldMethods.pm »