line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Role::Element::Coercible; |
2
|
|
|
|
|
|
|
|
3
|
380
|
|
|
380
|
|
170880
|
use strict; |
|
380
|
|
|
|
|
596
|
|
|
380
|
|
|
|
|
14879
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
380
|
|
|
380
|
|
1476
|
use Moose::Role; |
|
380
|
|
|
|
|
503
|
|
|
380
|
|
|
|
|
2183
|
|
7
|
|
|
|
|
|
|
|
8
|
380
|
|
|
380
|
|
1275429
|
use Carp qw( croak ); |
|
380
|
|
|
|
|
602
|
|
|
380
|
|
|
|
|
17246
|
|
9
|
380
|
|
|
380
|
|
1584
|
use HTML::FormFu::Util qw( require_class ); |
|
380
|
|
|
|
|
492
|
|
|
380
|
|
|
|
|
169632
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub as { |
12
|
2
|
|
|
2
|
0
|
10
|
my ( $self, $type, %attrs ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
|
|
67
|
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
|
|
9
|
my ( $self, %args ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
6
|
for (qw( type attributes package )) { |
26
|
6
|
50
|
|
|
|
14
|
croak "$_ argument required" if !defined $args{$_}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
4
|
my $class = $args{type}; |
30
|
2
|
50
|
|
|
|
7
|
if ( $class !~ m/^\+/ ) { |
31
|
2
|
|
|
|
|
4
|
$class = "HTML::FormFu::Element::$class"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
7
|
require_class($class); |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
63
|
my $element = $class->new( { type => $args{type}, } ); |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
7
|
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
|
|
|
|
|
113
|
$element->$method( $self->$method ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
10
|
_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
|
|
|
33
|
|| $element->does( $args{package} ); |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
1258
|
$element->value( $self->value ); |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
19
|
return $element; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _coerce_processors_and_errors { |
63
|
2
|
|
|
2
|
|
6
|
my ( $self, $element, %args ) = @_; |
64
|
|
|
|
|
|
|
|
65
|
2
|
100
|
66
|
|
|
9
|
if ( $args{errors} && @{ $args{errors} } > 0 ) { |
|
2
|
|
|
|
|
9
|
|
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
2
|
my @errors = @{ $args{errors} }; |
|
1
|
|
|
|
|
4
|
|
68
|
1
|
|
|
|
|
1
|
my @new_errors; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
3
|
for my $list ( qw( |
71
|
|
|
|
|
|
|
_filters _constraints |
72
|
|
|
|
|
|
|
_inflators _validators |
73
|
|
|
|
|
|
|
_transformers _deflators |
74
|
|
|
|
|
|
|
) ) |
75
|
|
|
|
|
|
|
{ |
76
|
6
|
|
|
|
|
153
|
$element->$list( [] ); |
77
|
|
|
|
|
|
|
|
78
|
6
|
|
|
|
|
4
|
for my $processor ( @{ $self->$list } ) { |
|
6
|
|
|
|
|
150
|
|
79
|
1
|
|
|
|
|
7
|
my @errors_to_copy = map { $_->clone } |
80
|
1
|
|
|
|
|
3
|
grep { $_->processor == $processor } @errors; |
|
1
|
|
|
|
|
24
|
|
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
10
|
my $processor_clone = $processor->clone; |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
3
|
$processor_clone->parent($element); |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
1
|
map { $_->processor($processor_clone) } @errors_to_copy; |
|
1
|
|
|
|
|
32
|
|
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
2
|
push @{ $element->$list }, $processor_clone; |
|
1
|
|
|
|
|
26
|
|
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
3
|
push @new_errors, @errors_to_copy; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
1
|
|
|
|
|
25
|
$element->_errors( \@new_errors ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else { |
96
|
1
|
|
|
|
|
26
|
$element->_errors( [] ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
4
|
return; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |