line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
404
|
|
|
404
|
|
212929
|
use strict; |
|
404
|
|
|
|
|
1149
|
|
|
404
|
|
|
|
|
21787
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Role::ContainsElements; |
4
|
|
|
|
|
|
|
# ABSTRACT: Role for contained elements and fields |
5
|
|
|
|
|
|
|
$HTML::FormFu::Role::ContainsElements::VERSION = '2.07'; |
6
|
404
|
|
|
404
|
|
2520
|
use Moose::Role; |
|
404
|
|
|
|
|
950
|
|
|
404
|
|
|
|
|
2670
|
|
7
|
|
|
|
|
|
|
|
8
|
404
|
|
|
|
|
24994
|
use HTML::FormFu::Util qw( |
9
|
|
|
|
|
|
|
_parse_args |
10
|
|
|
|
|
|
|
_get_elements |
11
|
|
|
|
|
|
|
_filter_components |
12
|
404
|
|
|
404
|
|
2093179
|
); |
|
404
|
|
|
|
|
1031
|
|
13
|
404
|
|
|
404
|
|
2801
|
use Carp qw( croak ); |
|
404
|
|
|
|
|
895
|
|
|
404
|
|
|
|
|
20339
|
|
14
|
404
|
|
|
404
|
|
2693
|
use Scalar::Util qw( refaddr weaken ); |
|
404
|
|
|
|
|
1005
|
|
|
404
|
|
|
|
|
454773
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub get_elements { |
17
|
2328
|
|
|
2328
|
0
|
8482
|
my $self = shift; |
18
|
2328
|
|
|
|
|
8134
|
my %args = _parse_args(@_); |
19
|
|
|
|
|
|
|
|
20
|
2328
|
|
|
|
|
4343
|
my @elements = @{ $self->_elements }; |
|
2328
|
|
|
|
|
64808
|
|
21
|
|
|
|
|
|
|
|
22
|
2328
|
|
|
|
|
8549
|
return _get_elements( \%args, \@elements ); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get_element { |
26
|
110
|
|
|
110
|
0
|
3266
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
110
|
|
|
|
|
451
|
my $e = $self->get_elements(@_); |
29
|
|
|
|
|
|
|
|
30
|
110
|
50
|
|
|
|
943
|
return @$e ? $e->[0] : (); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get_all_elements { |
34
|
470
|
|
|
470
|
0
|
3071
|
my $self = shift; |
35
|
470
|
|
|
|
|
1582
|
my %args = _parse_args(@_); |
36
|
|
|
|
|
|
|
|
37
|
470
|
|
|
|
|
826
|
my @e = map { $_, @{ $_->get_all_elements } } @{ $self->_elements }; |
|
1068
|
|
|
|
|
1574
|
|
|
1068
|
|
|
|
|
3360
|
|
|
470
|
|
|
|
|
13378
|
|
38
|
|
|
|
|
|
|
|
39
|
470
|
|
|
|
|
1338
|
return _get_elements( \%args, \@e ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_all_element { |
43
|
15
|
|
|
15
|
0
|
91
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
15
|
|
|
|
|
66
|
my $e = $self->get_all_elements(@_); |
46
|
|
|
|
|
|
|
|
47
|
15
|
50
|
|
|
|
150
|
return @$e ? $e->[0] : (); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_fields { |
51
|
8587
|
|
|
8587
|
0
|
60181
|
my $self = shift; |
52
|
8587
|
|
|
|
|
22740
|
my %args = _parse_args(@_); |
53
|
|
|
|
|
|
|
|
54
|
19105
|
100
|
100
|
|
|
483345
|
my @e = map { $_->is_field && !$_->is_block ? $_ : @{ $_->get_fields } } |
|
3588
|
|
|
|
|
10098
|
|
55
|
8587
|
|
|
|
|
13562
|
@{ $self->_elements }; |
|
8587
|
|
|
|
|
233155
|
|
56
|
|
|
|
|
|
|
|
57
|
8587
|
|
|
|
|
25848
|
return _get_elements( \%args, \@e ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub get_field { |
61
|
414
|
|
|
414
|
0
|
21260
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
414
|
|
|
|
|
1690
|
my $f = $self->get_fields(@_); |
64
|
|
|
|
|
|
|
|
65
|
414
|
100
|
|
|
|
4353
|
return @$f ? $f->[0] : (); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get_errors { |
69
|
1913
|
|
|
1913
|
0
|
6669
|
my $self = shift; |
70
|
1913
|
|
|
|
|
5387
|
my %args = _parse_args(@_); |
71
|
|
|
|
|
|
|
|
72
|
1913
|
50
|
|
|
|
6291
|
return [] if !$self->form->submitted; |
73
|
|
|
|
|
|
|
|
74
|
1913
|
|
|
|
|
3696
|
my @x = map { @{ $_->get_errors(@_) } } @{ $self->_elements }; |
|
4098
|
|
|
|
|
6821
|
|
|
4098
|
|
|
|
|
12190
|
|
|
1913
|
|
|
|
|
47436
|
|
75
|
|
|
|
|
|
|
|
76
|
1913
|
|
|
|
|
6512
|
_filter_components( \%args, \@x ); |
77
|
|
|
|
|
|
|
|
78
|
1913
|
100
|
|
|
|
5537
|
if ( !$args{forced} ) { |
79
|
1869
|
|
|
|
|
4259
|
@x = grep { !$_->forced } @x; |
|
710
|
|
|
|
|
20035
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
1913
|
|
|
|
|
12030
|
return \@x; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub clear_errors { |
86
|
672
|
|
|
672
|
0
|
1866
|
my ($self) = @_; |
87
|
|
|
|
|
|
|
|
88
|
672
|
|
|
|
|
1344
|
map { $_->clear_errors } @{ $self->_elements }; |
|
1386
|
|
|
|
|
5666
|
|
|
672
|
|
|
|
|
18530
|
|
89
|
|
|
|
|
|
|
|
90
|
672
|
|
|
|
|
1698
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub insert_before { |
94
|
4
|
|
|
4
|
0
|
37
|
my ( $self, $object, $position ) = @_; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# if $position is already a child of $object, remove it first |
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
|
|
8
|
for my $i ( 0 .. $#{ $self->_elements } ) { |
|
4
|
|
|
|
|
118
|
|
99
|
8
|
100
|
|
|
|
203
|
if ( refaddr( $self->_elements->[$i] ) eq refaddr($object) ) { |
100
|
2
|
|
|
|
|
7
|
splice @{ $self->_elements }, $i, 1; |
|
2
|
|
|
|
|
53
|
|
101
|
2
|
|
|
|
|
6
|
last; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
4
|
|
|
|
|
8
|
for my $i ( 0 .. $#{ $self->_elements } ) { |
|
4
|
|
|
|
|
101
|
|
106
|
4
|
50
|
|
|
|
103
|
if ( refaddr( $self->_elements->[$i] ) eq refaddr($position) ) { |
107
|
4
|
|
|
|
|
10
|
splice @{ $self->_elements }, $i, 0, $object; |
|
4
|
|
|
|
|
125
|
|
108
|
4
|
|
|
|
|
11
|
$object->{parent} = $position->{parent}; |
109
|
4
|
|
|
|
|
14
|
weaken $object->{parent}; |
110
|
4
|
|
|
|
|
10
|
return $object; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
0
|
croak 'position element not found'; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub insert_after { |
118
|
4
|
|
|
4
|
0
|
44
|
my ( $self, $object, $position ) = @_; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# if $position is already a child of $object, remove it first |
121
|
|
|
|
|
|
|
|
122
|
4
|
|
|
|
|
9
|
for my $i ( 0 .. $#{ $self->_elements } ) { |
|
4
|
|
|
|
|
113
|
|
123
|
6
|
100
|
|
|
|
162
|
if ( refaddr( $self->_elements->[$i] ) eq refaddr($object) ) { |
124
|
2
|
|
|
|
|
7
|
splice @{ $self->_elements }, $i, 1; |
|
2
|
|
|
|
|
55
|
|
125
|
2
|
|
|
|
|
7
|
last; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
4
|
|
|
|
|
10
|
for my $i ( 0 .. $#{ $self->_elements } ) { |
|
4
|
|
|
|
|
104
|
|
130
|
4
|
50
|
|
|
|
136
|
if ( refaddr( $self->_elements->[$i] ) eq refaddr($position) ) { |
131
|
4
|
|
|
|
|
17
|
splice @{ $self->_elements }, $i + 1, 0, $object; |
|
4
|
|
|
|
|
133
|
|
132
|
4
|
|
|
|
|
12
|
$object->{parent} = $position->{parent}; |
133
|
4
|
|
|
|
|
18
|
weaken $object->{parent}; |
134
|
4
|
|
|
|
|
12
|
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
|
|
|
|
|
3
|
for my $i ( 0 .. $#{ $self->_elements } ) { |
|
1
|
|
|
|
|
25
|
|
145
|
3
|
100
|
|
|
|
66
|
if ( refaddr( $self->_elements->[$i] ) eq refaddr($object) ) { |
146
|
1
|
|
|
|
|
2
|
splice @{ $self->_elements }, $i, 1; |
|
1
|
|
|
|
|
23
|
|
147
|
1
|
|
|
|
|
3
|
undef $object->{parent}; |
148
|
1
|
|
|
|
|
3
|
return $object; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
croak 'element not found'; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
__END__ |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=pod |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=encoding UTF-8 |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 NAME |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
HTML::FormFu::Role::ContainsElements - Role for contained elements and fields |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 VERSION |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
version 2.07 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 AUTHOR |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
180
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |