line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
381
|
|
|
381
|
|
212157
|
use strict; |
|
381
|
|
|
|
|
998
|
|
|
381
|
|
|
|
|
20835
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Role::Element::Coercible; |
4
|
|
|
|
|
|
|
# ABSTRACT: coercible element role |
5
|
|
|
|
|
|
|
$HTML::FormFu::Role::Element::Coercible::VERSION = '2.07'; |
6
|
381
|
|
|
381
|
|
2444
|
use Moose::Role; |
|
381
|
|
|
|
|
884
|
|
|
381
|
|
|
|
|
2687
|
|
7
|
|
|
|
|
|
|
|
8
|
381
|
|
|
381
|
|
2016845
|
use Carp qw( croak ); |
|
381
|
|
|
|
|
1115
|
|
|
381
|
|
|
|
|
22178
|
|
9
|
381
|
|
|
381
|
|
2682
|
use HTML::FormFu::Util qw( require_class ); |
|
381
|
|
|
|
|
941
|
|
|
381
|
|
|
|
|
224597
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub as { |
12
|
2
|
|
|
2
|
0
|
10
|
my ( $self, $type, %attrs ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
|
|
70
|
return $self->_coerce( |
15
|
|
|
|
|
|
|
type => $type, |
16
|
|
|
|
|
|
|
attributes => \%attrs, |
17
|
|
|
|
|
|
|
errors => $self->_errors, |
18
|
|
|
|
|
|
|
package => __PACKAGE__, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _coerce { |
23
|
2
|
|
|
2
|
|
12
|
my ( $self, %args ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
7
|
for (qw( type attributes package )) { |
26
|
6
|
50
|
|
|
|
16
|
croak "$_ argument required" if !defined $args{$_}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
5
|
my $class = $args{type}; |
30
|
2
|
50
|
|
|
|
8
|
if ( $class !~ m/^\+/ ) { |
31
|
2
|
|
|
|
|
15
|
$class = "HTML::FormFu::Element::$class"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
10
|
require_class($class); |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
74
|
my $element = $class->new( { type => $args{type}, } ); |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
9
|
for my $method ( qw( |
39
|
|
|
|
|
|
|
name |
40
|
|
|
|
|
|
|
attributes comment |
41
|
|
|
|
|
|
|
comment_attributes label |
42
|
|
|
|
|
|
|
label_attributes label_filename |
43
|
|
|
|
|
|
|
render_method parent |
44
|
|
|
|
|
|
|
) ) |
45
|
|
|
|
|
|
|
{ |
46
|
18
|
|
|
|
|
140
|
$element->$method( $self->$method ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
14
|
_coerce_processors_and_errors( $self, $element, %args ); |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
9
|
$element->attributes( $args{attributes} ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
croak "element cannot be coerced to type '$args{type}'" |
54
|
|
|
|
|
|
|
unless $element->isa( $args{package} ) |
55
|
2
|
50
|
33
|
|
|
67
|
|| $element->does( $args{package} ); |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
1791
|
$element->value( $self->value ); |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
19
|
return $element; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _coerce_processors_and_errors { |
63
|
2
|
|
|
2
|
|
9
|
my ( $self, $element, %args ) = @_; |
64
|
|
|
|
|
|
|
|
65
|
2
|
100
|
66
|
|
|
9
|
if ( $args{errors} && @{ $args{errors} } > 0 ) { |
|
2
|
|
|
|
|
10
|
|
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
3
|
my @errors = @{ $args{errors} }; |
|
1
|
|
|
|
|
3
|
|
68
|
1
|
|
|
|
|
3
|
my @new_errors; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
3
|
for my $list ( qw( |
71
|
|
|
|
|
|
|
_filters _constraints |
72
|
|
|
|
|
|
|
_inflators _validators |
73
|
|
|
|
|
|
|
_transformers _deflators |
74
|
|
|
|
|
|
|
) ) |
75
|
|
|
|
|
|
|
{ |
76
|
6
|
|
|
|
|
204
|
$element->$list( [] ); |
77
|
|
|
|
|
|
|
|
78
|
6
|
|
|
|
|
10
|
for my $processor ( @{ $self->$list } ) { |
|
6
|
|
|
|
|
184
|
|
79
|
1
|
|
|
|
|
8
|
my @errors_to_copy = map { $_->clone } |
80
|
1
|
|
|
|
|
4
|
grep { $_->processor == $processor } @errors; |
|
1
|
|
|
|
|
30
|
|
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
10
|
my $processor_clone = $processor->clone; |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
6
|
$processor_clone->parent($element); |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
2
|
map { $_->processor($processor_clone) } @errors_to_copy; |
|
1
|
|
|
|
|
31
|
|
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
3
|
push @{ $element->$list }, $processor_clone; |
|
1
|
|
|
|
|
44
|
|
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
4
|
push @new_errors, @errors_to_copy; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
1
|
|
|
|
|
30
|
$element->_errors( \@new_errors ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else { |
96
|
1
|
|
|
|
|
32
|
$element->_errors( [] ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
7
|
return; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=encoding UTF-8 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
HTML::FormFu::Role::Element::Coercible - coercible element role |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 VERSION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
version 2.07 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
127
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |