line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Role::ContainsElements; |
2
|
|
|
|
|
|
|
|
3
|
400
|
|
|
400
|
|
159182
|
use strict; |
|
400
|
|
|
|
|
572
|
|
|
400
|
|
|
|
|
14888
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
400
|
|
|
400
|
|
1559
|
use Moose::Role; |
|
400
|
|
|
|
|
473
|
|
|
400
|
|
|
|
|
2064
|
|
7
|
|
|
|
|
|
|
|
8
|
400
|
|
|
|
|
19002
|
use HTML::FormFu::Util qw( |
9
|
|
|
|
|
|
|
_parse_args |
10
|
|
|
|
|
|
|
_get_elements |
11
|
|
|
|
|
|
|
_filter_components |
12
|
400
|
|
|
400
|
|
1311817
|
); |
|
400
|
|
|
|
|
642
|
|
13
|
400
|
|
|
400
|
|
1553
|
use Carp qw( croak ); |
|
400
|
|
|
|
|
493
|
|
|
400
|
|
|
|
|
15421
|
|
14
|
400
|
|
|
400
|
|
1492
|
use Scalar::Util qw( refaddr weaken ); |
|
400
|
|
|
|
|
498
|
|
|
400
|
|
|
|
|
312931
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub get_elements { |
17
|
2322
|
|
|
2322
|
0
|
5378
|
my $self = shift; |
18
|
2322
|
|
|
|
|
5887
|
my %args = _parse_args(@_); |
19
|
|
|
|
|
|
|
|
20
|
2322
|
|
|
|
|
2311
|
my @elements = @{ $self->_elements }; |
|
2322
|
|
|
|
|
52034
|
|
21
|
|
|
|
|
|
|
|
22
|
2322
|
|
|
|
|
6647
|
return _get_elements( \%args, \@elements ); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get_element { |
26
|
110
|
|
|
110
|
0
|
2398
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
110
|
|
|
|
|
314
|
my $e = $self->get_elements(@_); |
29
|
|
|
|
|
|
|
|
30
|
110
|
50
|
|
|
|
842
|
return @$e ? $e->[0] : (); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get_all_elements { |
34
|
468
|
|
|
468
|
0
|
2419
|
my $self = shift; |
35
|
468
|
|
|
|
|
917
|
my %args = _parse_args(@_); |
36
|
|
|
|
|
|
|
|
37
|
468
|
|
|
|
|
429
|
my @e = map { $_, @{ $_->get_all_elements } } @{ $self->_elements }; |
|
1066
|
|
|
|
|
745
|
|
|
1066
|
|
|
|
|
2338
|
|
|
468
|
|
|
|
|
10817
|
|
38
|
|
|
|
|
|
|
|
39
|
468
|
|
|
|
|
1001
|
return _get_elements( \%args, \@e ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_all_element { |
43
|
15
|
|
|
15
|
0
|
63
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
15
|
|
|
|
|
63
|
my $e = $self->get_all_elements(@_); |
46
|
|
|
|
|
|
|
|
47
|
15
|
50
|
|
|
|
143
|
return @$e ? $e->[0] : (); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_fields { |
51
|
8604
|
|
|
8604
|
0
|
37360
|
my $self = shift; |
52
|
8604
|
|
|
|
|
15883
|
my %args = _parse_args(@_); |
53
|
|
|
|
|
|
|
|
54
|
19526
|
100
|
100
|
|
|
404743
|
my @e = map { $_->is_field && !$_->is_block ? $_ : @{ $_->get_fields } } |
|
3556
|
|
|
|
|
5942
|
|
55
|
8604
|
|
|
|
|
6630
|
@{ $self->_elements }; |
|
8604
|
|
|
|
|
187404
|
|
56
|
|
|
|
|
|
|
|
57
|
8604
|
|
|
|
|
18682
|
return _get_elements( \%args, \@e ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub get_field { |
61
|
426
|
|
|
426
|
0
|
15173
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
426
|
|
|
|
|
1168
|
my $f = $self->get_fields(@_); |
64
|
|
|
|
|
|
|
|
65
|
426
|
100
|
|
|
|
3743
|
return @$f ? $f->[0] : (); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get_errors { |
69
|
1901
|
|
|
1901
|
0
|
4020
|
my $self = shift; |
70
|
1901
|
|
|
|
|
3455
|
my %args = _parse_args(@_); |
71
|
|
|
|
|
|
|
|
72
|
1901
|
50
|
|
|
|
4263
|
return [] if !$self->form->submitted; |
73
|
|
|
|
|
|
|
|
74
|
1901
|
|
|
|
|
1778
|
my @x = map { @{ $_->get_errors(@_) } } @{ $self->_elements }; |
|
4161
|
|
|
|
|
3417
|
|
|
4161
|
|
|
|
|
8866
|
|
|
1901
|
|
|
|
|
38762
|
|
75
|
|
|
|
|
|
|
|
76
|
1901
|
|
|
|
|
3502
|
_filter_components( \%args, \@x ); |
77
|
|
|
|
|
|
|
|
78
|
1901
|
100
|
|
|
|
4757
|
if ( !$args{forced} ) { |
79
|
1857
|
|
|
|
|
1838
|
@x = grep { !$_->forced } @x; |
|
704
|
|
|
|
|
16716
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
1901
|
|
|
|
|
7318
|
return \@x; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub clear_errors { |
86
|
670
|
|
|
670
|
0
|
874
|
my ($self) = @_; |
87
|
|
|
|
|
|
|
|
88
|
670
|
|
|
|
|
783
|
map { $_->clear_errors } @{ $self->_elements }; |
|
1411
|
|
|
|
|
4479
|
|
|
670
|
|
|
|
|
14843
|
|
89
|
|
|
|
|
|
|
|
90
|
670
|
|
|
|
|
1084
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub insert_before { |
94
|
4
|
|
|
4
|
0
|
31
|
my ( $self, $object, $position ) = @_; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# if $position is already a child of $object, remove it first |
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
|
|
7
|
for my $i ( 0 .. $#{ $self->_elements } ) { |
|
4
|
|
|
|
|
103
|
|
99
|
8
|
100
|
|
|
|
197
|
if ( refaddr( $self->_elements->[$i] ) eq refaddr($object) ) { |
100
|
2
|
|
|
|
|
4
|
splice @{ $self->_elements }, $i, 1; |
|
2
|
|
|
|
|
42
|
|
101
|
2
|
|
|
|
|
5
|
last; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
4
|
|
|
|
|
8
|
for my $i ( 0 .. $#{ $self->_elements } ) { |
|
4
|
|
|
|
|
97
|
|
106
|
4
|
50
|
|
|
|
97
|
if ( refaddr( $self->_elements->[$i] ) eq refaddr($position) ) { |
107
|
4
|
|
|
|
|
6
|
splice @{ $self->_elements }, $i, 0, $object; |
|
4
|
|
|
|
|
96
|
|
108
|
4
|
|
|
|
|
8
|
$object->{parent} = $position->{parent}; |
109
|
4
|
|
|
|
|
10
|
weaken $object->{parent}; |
110
|
4
|
|
|
|
|
9
|
return $object; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
0
|
croak 'position element not found'; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub insert_after { |
118
|
4
|
|
|
4
|
0
|
52
|
my ( $self, $object, $position ) = @_; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# if $position is already a child of $object, remove it first |
121
|
|
|
|
|
|
|
|
122
|
4
|
|
|
|
|
11
|
for my $i ( 0 .. $#{ $self->_elements } ) { |
|
4
|
|
|
|
|
93
|
|
123
|
6
|
100
|
|
|
|
122
|
if ( refaddr( $self->_elements->[$i] ) eq refaddr($object) ) { |
124
|
2
|
|
|
|
|
3
|
splice @{ $self->_elements }, $i, 1; |
|
2
|
|
|
|
|
42
|
|
125
|
2
|
|
|
|
|
5
|
last; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
4
|
|
|
|
|
8
|
for my $i ( 0 .. $#{ $self->_elements } ) { |
|
4
|
|
|
|
|
82
|
|
130
|
4
|
50
|
|
|
|
82
|
if ( refaddr( $self->_elements->[$i] ) eq refaddr($position) ) { |
131
|
4
|
|
|
|
|
5
|
splice @{ $self->_elements }, $i + 1, 0, $object; |
|
4
|
|
|
|
|
84
|
|
132
|
4
|
|
|
|
|
7
|
$object->{parent} = $position->{parent}; |
133
|
4
|
|
|
|
|
10
|
weaken $object->{parent}; |
134
|
4
|
|
|
|
|
8
|
return $object; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
0
|
croak 'position element not found'; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub remove_element { |
142
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $object ) = @_; |
143
|
|
|
|
|
|
|
|
144
|
1
|
|
|
|
|
2
|
for my $i ( 0 .. $#{ $self->_elements } ) { |
|
1
|
|
|
|
|
34
|
|
145
|
3
|
100
|
|
|
|
66
|
if ( refaddr( $self->_elements->[$i] ) eq refaddr($object) ) { |
146
|
1
|
|
|
|
|
1
|
splice @{ $self->_elements }, $i, 1; |
|
1
|
|
|
|
|
30
|
|
147
|
1
|
|
|
|
|
3
|
undef $object->{parent}; |
148
|
1
|
|
|
|
|
2
|
return $object; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
croak 'element not found'; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |