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 SCAR 20.8
CC
8
Cov
93%
populate
7.0
__ANON__
2.0
BEGIN
1.0
CRAP 8.0
« lib/HTML/FormFu/Element/Label.pm ↑ Summary lib/HTML/FormFu/Role/ContainsElementsSharedWithField.pm »
1 404 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Role::Populate;
4 404 $HTML::FormFu::Role::Populate::VERSION = '2.06';
5 404 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 404 ▶use Scalar::Util qw( reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 404 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 after BUILD => sub {
11 4371 ▶ my ( $self, $args ) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
12  
13 4371 ▶ $args ||= {};
Condition50%1/2
$args ||= {}
l!l
43710
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
14  
15 # get args handled by Moose so they aren't set twice
16 127987 my %init_args = map { $_->{init_arg} => 1 }
17 4371 grep { defined $_->{init_arg} } $self->meta->get_all_attributes;
18  
19 # remove defaults set in HTML::FormFu::BUILD because they need to be set for a third time
20 4371 delete @init_args{ keys %{$HTML::FormFu::build_defaults} };
21 my %args
22 4371 = map { $_ => $args->{$_} } grep { !exists $init_args{$_} } keys %$args;
23 4371 $self->populate( \%args );
24  
25 4371 return;
26 404 };
27  
28 sub populate {
29 6830 ▶ my ( $self, $arg_ref ) = @_;
Subroutine populate: called CC=7 SCAR=19.5
Pod undocumented
30  
31 6830 ▶ croak "argument to populate() must be a hash-ref"
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($arg_ref) ne "HASH" 0 6830 6830
32 if reftype($arg_ref) ne 'HASH';
33  
34 # shallow clone the args so we don't stomp on them
35 6830 my %args = %$arg_ref;
36  
37 # we have to handle element_defaults seperately, as it is no longer a
38 # simple hash key
39  
40 6830 ▶ if ( exists $args{element_defaults} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"element_defaults"}) 0 6830 6830
41 0 $self->element_defaults( delete $args{element_defaults} );
42 }
43  
44 # handle any 'roles' first
45 6830 my $roles = delete $args{roles};
46  
47 # notes for @defer_keys...
48 # 'options', 'values', 'value_range' is for _Group elements,
49 # to ensure any 'empty_first' value gets set first
50  
51 6830 my @defer_keys = qw(
52 default_args
53 auto_fieldset
54 load_config_file
55 element elements
56 default_values
57 constraints_from_dbic
58 filter filters
59 constraint constraints
60 inflator inflators
61 deflator deflators
62 query
63 validator validators
64 transformer transformers
65 plugins
66 options
67 values
68 value_range
69 );
70  
71 6830 my %defer;
72 6830 for (@defer_keys) {
73 163920 ▶ $defer{$_} = delete $args{$_} if exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$_} 604 163316 163920
74 }
75  
76 6830 eval {
77 6830 ▶ if ($roles) {
Branch: 1 branch
BranchTrueFalseTotal
if ($roles) 3 6827 6830
78 3 $self->roles($roles);
79 }
80  
81 6830 map { $self->$_( delete $args{$_} ) } keys %args;
82  
83 604 map { $self->$_( $defer{$_} ) }
84 6829 grep { exists $defer{$_} } @defer_keys;
85 };
86 6830 ▶ croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 6829 6830
87  
88 6829 return $self;
89 }
90  
91 404 1;
92  
93 __END__
94  
95 =pod
96  
97 =encoding UTF-8
98  
99 =head1 NAME
100  
101 HTML::FormFu::Role::Populate
102  
103 =head1 VERSION
104  
105 version 2.06
106  
107 =head1 AUTHOR
108  
109 Carl Franks <cpan@fireartist.com>
110  
111 =head1 COPYRIGHT AND LICENSE
112  
113 This software is copyright (c) 2018 by Carl Franks.
114  
115 This is free software; you can redistribute it and/or modify it under
116 the same terms as the Perl 5 programming language system itself.
117  
118 =cut
« lib/HTML/FormFu/Element/Label.pm ↑ Summary lib/HTML/FormFu/Role/ContainsElementsSharedWithField.pm »