line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Factory::Result::Single; |
2
|
|
|
|
|
|
|
$Form::Factory::Result::Single::VERSION = '0.022'; |
3
|
1
|
|
|
1
|
|
4
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
with qw( Form::Factory::Result ); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Form result class representing a single result |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has is_valid => ( |
11
|
|
|
|
|
|
|
is => 'rw', |
12
|
|
|
|
|
|
|
isa => 'Bool', |
13
|
|
|
|
|
|
|
predicate => 'is_validated', |
14
|
|
|
|
|
|
|
clearer => 'clear_validation', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has is_success => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
isa => 'Bool', |
21
|
|
|
|
|
|
|
predicate => 'is_outcome_known', |
22
|
|
|
|
|
|
|
clearer => 'clear_outcome', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has messages => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
isa => 'ArrayRef[Form::Factory::Message]', |
29
|
|
|
|
|
|
|
required => 1, |
30
|
|
|
|
|
|
|
default => sub { [] }, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has content => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
isa => 'HashRef', |
37
|
|
|
|
|
|
|
required => 1, |
38
|
|
|
|
|
|
|
default => sub { {} }, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub add_message { |
43
|
24
|
|
|
24
|
1
|
85
|
my ($self, %params) = @_; |
44
|
24
|
|
|
|
|
31
|
push @{ $self->messages }, Form::Factory::Message->new( %params ); |
|
24
|
|
|
|
|
789
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub clear_state { |
49
|
114
|
|
|
114
|
1
|
140
|
my $self = shift; |
50
|
114
|
|
|
|
|
4020
|
$self->clear_validation; |
51
|
114
|
|
|
|
|
3741
|
$self->clear_outcome; |
52
|
114
|
|
|
|
|
3144
|
$self->content({}); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub clear_messages { |
57
|
114
|
|
|
114
|
1
|
111
|
my $self = shift; |
58
|
114
|
|
|
|
|
92
|
@{ $self->messages } = (); |
|
114
|
|
|
|
|
3225
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub clear_messages_for_field { |
63
|
0
|
|
|
0
|
1
|
0
|
my ($self, $field) = @_; |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
0
|
my @messages = grep { $_->is_tied_to_field and $_->field eq $field } |
|
0
|
|
|
|
|
0
|
|
66
|
0
|
|
|
|
|
0
|
@{ $self->messages }; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
@{ $self->messages } = @messages; |
|
0
|
|
|
|
|
0
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub info { |
73
|
0
|
|
|
0
|
1
|
0
|
my ($self, $message) = @_; |
74
|
0
|
|
|
|
|
0
|
$self->add_message( message => $message ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub field_info { |
79
|
0
|
|
|
0
|
1
|
0
|
my ($self, $field, $message) = @_; |
80
|
0
|
|
|
|
|
0
|
$self->add_message( field => $field, message => $message ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub warning { |
85
|
0
|
|
|
0
|
1
|
0
|
my ($self, $message) = @_; |
86
|
0
|
|
|
|
|
0
|
$self->add_message( type => 'warning', message => $message ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub field_warning { |
91
|
0
|
|
|
0
|
1
|
0
|
my ($self, $field, $message) = @_; |
92
|
0
|
|
|
|
|
0
|
$self->add_message( type => 'warning', field => $field, message => $message ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub error { |
97
|
15
|
|
|
15
|
1
|
366
|
my ($self, $message) = @_; |
98
|
15
|
|
|
|
|
50
|
$self->add_message( type => 'error', message => $message ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub field_error { |
103
|
8
|
|
|
8
|
1
|
17
|
my ($self, $field, $message) = @_; |
104
|
8
|
|
|
|
|
37
|
$self->add_message( type => 'error', field => $field, message => $message ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub success { |
109
|
1
|
|
|
1
|
1
|
12
|
my ($self, $message) = @_; |
110
|
1
|
|
|
|
|
28
|
$self->is_success(1); |
111
|
1
|
|
|
|
|
4
|
$self->add_message( type => 'info', message => $message); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub failure { |
116
|
0
|
|
|
0
|
1
|
|
my ($self, $message) = @_; |
117
|
0
|
|
|
|
|
|
$self->is_success(0); |
118
|
0
|
|
|
|
|
|
$self->add_message( type => 'error', message => $message); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=pod |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=encoding UTF-8 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 NAME |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Form::Factory::Result::Single - Form result class representing a single result |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 VERSION |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
version 0.022 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SYNOPSIS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my $result = Form::Factory::Result::Single->new; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$result->is_valid(1); |
142
|
|
|
|
|
|
|
$result->is_success(1); |
143
|
|
|
|
|
|
|
$result->success('success! Hurray! Yippee! Woohoo!'); |
144
|
|
|
|
|
|
|
$result->failure('failure! Shucks! Bummer! Glurgh!'); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
$result->info('something happened'); |
147
|
|
|
|
|
|
|
$result->warning('something happened, beware!'); |
148
|
|
|
|
|
|
|
$result->error('nothing happened. Ohnoes!'); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$result->field_info(foo => 'consider this info about foo'); |
151
|
|
|
|
|
|
|
$result->field_warning(bar => 'bar worked, but you should check it again'); |
152
|
|
|
|
|
|
|
$result->field_error(baz => 'baz is wrong'); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$result->clear_messages_for_field('foo'); |
155
|
|
|
|
|
|
|
$result->clear_messages; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 DESCRIPTION |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This class provides an individual L<Form::Factory::Result>. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 is_valid |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
A boolean value indicating whether the action checked out okay. When set, the C<is_validated> predicate is set to true. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 is_success |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
A boolean value indicating whether the action ran okay. When set, the C<is_outcome_known> predicate is set to true. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 messages |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This is the array of L<Form::Factory::Message> objects attached to this result. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 content |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This is a hash of other information to attach to the result. This can be anything the action needs to output to the caller. This can be useful for returning references to newly created objects, automatically assigned IDs, etc. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 METHODS |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 add_message |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
$result->add_message(%options); |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
The C<%options> are passed to the constructor of L<Form::Factory::Message>. The new message object is added to the end of L</messages>. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 clear_state |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Clears the C<is_valid> and C<is_success> flags (which also clears C<is_failure>, C<is_validated>, and C<is_outcome_known>). This also resets C<content> to an empty hash. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 clear_messages |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Empties the list of messages in L</messages>. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 clear_messages_for_field |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
$result->clear_messages_for_field($field); |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Clears all messages that are tied to the named field. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 info |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
$result->info($message); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Adds a new regular info message. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 field_info |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
$result->field_info($field, $message); |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Adds a new info message tied to the named field. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 warning |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
$result->warning($message); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Adds a new regular warning messages. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head2 field_warning |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
$result->field_warning($field, $message); |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Adds a new warning message tied to the named field. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head2 error |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
$result->error($message); |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Adds a new regular error message. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 field_error |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
$result->field_error($field, $message); |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Adds a new error message tied to the named field. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head2 success |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
$result->success($message); |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
This is shorthand for: |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
$result->is_success(1); |
244
|
|
|
|
|
|
|
$result->info($message); |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head2 failure |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
$result->failure($message); |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
This is shorthand for: |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
$result->is_success(0); |
253
|
|
|
|
|
|
|
$result->error($message); |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head1 AUTHOR |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Andrew Sterling Hanenkamp <hanenkamp@cpan.org> |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Qubling Software LLC. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
264
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=cut |