| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::FormHandler::Result::Role; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: role with common code for form & field results |
|
3
|
|
|
|
|
|
|
$HTML::FormHandler::Result::Role::VERSION = '0.40068'; |
|
4
|
145
|
|
|
145
|
|
92920
|
use Moose::Role; |
|
|
145
|
|
|
|
|
9600
|
|
|
|
145
|
|
|
|
|
1247
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has 'name' => ( isa => 'Str', is => 'rw', required => 1 ); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# do we need 'accessor' ? |
|
10
|
|
|
|
|
|
|
has 'parent' => ( is => 'rw', weak_ref => 1 ); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'input' => ( |
|
13
|
|
|
|
|
|
|
is => 'ro', |
|
14
|
|
|
|
|
|
|
clearer => '_clear_input', |
|
15
|
|
|
|
|
|
|
writer => '_set_input', |
|
16
|
|
|
|
|
|
|
predicate => 'has_input', |
|
17
|
|
|
|
|
|
|
); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has '_results' => ( |
|
20
|
|
|
|
|
|
|
traits => ['Array'], |
|
21
|
|
|
|
|
|
|
isa => 'ArrayRef[HTML::FormHandler::Field::Result]', |
|
22
|
|
|
|
|
|
|
is => 'rw', |
|
23
|
|
|
|
|
|
|
default => sub { [] }, |
|
24
|
|
|
|
|
|
|
handles => { |
|
25
|
|
|
|
|
|
|
results => 'elements', |
|
26
|
|
|
|
|
|
|
add_result => 'push', |
|
27
|
|
|
|
|
|
|
num_results => 'count', |
|
28
|
|
|
|
|
|
|
has_results => 'count', |
|
29
|
|
|
|
|
|
|
clear_results => 'clear', |
|
30
|
|
|
|
|
|
|
find_result_index => 'first_index', |
|
31
|
|
|
|
|
|
|
set_result_at_index => 'set', |
|
32
|
|
|
|
|
|
|
_pop_result => 'pop', |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has 'error_results' => ( |
|
37
|
|
|
|
|
|
|
traits => ['Array'], |
|
38
|
|
|
|
|
|
|
isa => 'ArrayRef', # for HFH::Result and HFH::Field::Result |
|
39
|
|
|
|
|
|
|
is => 'rw', |
|
40
|
|
|
|
|
|
|
default => sub { [] }, |
|
41
|
|
|
|
|
|
|
handles => { |
|
42
|
|
|
|
|
|
|
has_error_results => 'count', |
|
43
|
|
|
|
|
|
|
num_error_results => 'count', |
|
44
|
|
|
|
|
|
|
clear_error_results => 'clear', |
|
45
|
|
|
|
|
|
|
add_error_result => 'push', |
|
46
|
|
|
|
|
|
|
all_error_results => 'elements', |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub errors_by_id { |
|
51
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
52
|
0
|
|
|
|
|
0
|
my %errors; |
|
53
|
0
|
|
|
|
|
0
|
$errors{$_->field_def->id} = [$_->all_errors] for $self->all_error_results; |
|
54
|
0
|
|
|
|
|
0
|
return \%errors; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub errors_by_name { |
|
58
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
|
59
|
1
|
|
|
|
|
3
|
my %errors; |
|
60
|
1
|
|
|
|
|
40
|
$errors{$_->field_def->html_name} = [$_->all_errors] for $self->all_error_results; |
|
61
|
1
|
|
|
|
|
11
|
return \%errors; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has 'errors' => ( |
|
65
|
|
|
|
|
|
|
traits => ['Array'], |
|
66
|
|
|
|
|
|
|
is => 'rw', |
|
67
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
|
68
|
|
|
|
|
|
|
default => sub { [] }, |
|
69
|
|
|
|
|
|
|
handles => { |
|
70
|
|
|
|
|
|
|
all_errors => 'elements', |
|
71
|
|
|
|
|
|
|
_push_errors => 'push', |
|
72
|
|
|
|
|
|
|
num_errors => 'count', |
|
73
|
|
|
|
|
|
|
has_errors => 'count', |
|
74
|
|
|
|
|
|
|
clear_errors => 'clear', |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has 'warnings' => ( |
|
79
|
|
|
|
|
|
|
traits => ['Array'], |
|
80
|
|
|
|
|
|
|
is => 'rw', |
|
81
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
|
82
|
|
|
|
|
|
|
default => sub { [] }, |
|
83
|
|
|
|
|
|
|
handles => { |
|
84
|
|
|
|
|
|
|
all_warnings => 'elements', |
|
85
|
|
|
|
|
|
|
add_warning => 'push', |
|
86
|
|
|
|
|
|
|
num_warnings => 'count', |
|
87
|
|
|
|
|
|
|
has_warnings => 'count', |
|
88
|
|
|
|
|
|
|
clear_warnings => 'clear', |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
|
|
92
|
9
|
50
|
|
9
|
0
|
387
|
sub validated { !$_[0]->has_error_results && $_[0]->has_input } |
|
93
|
0
|
|
|
0
|
0
|
0
|
sub is_valid { shift->validated } |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# this ought to be named 'result' for consistency, |
|
96
|
|
|
|
|
|
|
# but the result objects are named 'result'. |
|
97
|
|
|
|
|
|
|
# also providing 'field' method for compatibility |
|
98
|
|
|
|
|
|
|
sub get_result { |
|
99
|
251
|
|
|
251
|
0
|
711
|
my ( $self, $name, $die ) = @_; |
|
100
|
|
|
|
|
|
|
|
|
101
|
251
|
|
|
|
|
472
|
my $index; |
|
102
|
|
|
|
|
|
|
# if this is a full_name for a compound field |
|
103
|
|
|
|
|
|
|
# walk through the fields to get to it |
|
104
|
251
|
100
|
|
|
|
827
|
if ( $name =~ /\./ ) { |
|
105
|
5
|
|
|
|
|
24
|
my @names = split /\./, $name; |
|
106
|
5
|
|
|
|
|
12
|
my $result = $self; |
|
107
|
5
|
|
|
|
|
12
|
foreach my $rname (@names) { |
|
108
|
10
|
|
|
|
|
35
|
$result = $result->get_result($rname); |
|
109
|
10
|
50
|
|
|
|
43
|
return unless $result |
|
110
|
|
|
|
|
|
|
} |
|
111
|
5
|
|
|
|
|
34
|
return $result; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
else # not a compound name |
|
114
|
|
|
|
|
|
|
{ |
|
115
|
246
|
|
|
|
|
8634
|
for my $result ( $self->results ) { |
|
116
|
588
|
100
|
|
|
|
15236
|
return $result if ( $result->name eq $name ); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} |
|
119
|
0
|
0
|
|
|
|
0
|
return unless $die; |
|
120
|
0
|
|
|
|
|
0
|
die "Field '$name' not found in '$self'"; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
202
|
|
|
202
|
0
|
1632
|
sub field { shift->get_result(@_) } |
|
123
|
|
|
|
|
|
|
|
|
124
|
145
|
|
|
145
|
|
849853
|
use namespace::autoclean; |
|
|
145
|
|
|
|
|
435
|
|
|
|
145
|
|
|
|
|
1287
|
|
|
125
|
|
|
|
|
|
|
1; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=pod |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=encoding UTF-8 |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 NAME |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
HTML::FormHandler::Result::Role - role with common code for form & field results |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 VERSION |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
version 0.40068 |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Role to hold common result attributes for L<HTML::FormHandler::Result> |
|
144
|
|
|
|
|
|
|
and L<HTML::FormHandler::Result::Field>. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 NAME |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
HTML::FormHandler::Result::Role - common code for form & field results |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 AUTHOR |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Gerda Shank. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
159
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |