line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Factory::Result; |
2
|
|
|
|
|
|
|
$Form::Factory::Result::VERSION = '0.022'; |
3
|
1
|
|
|
1
|
|
443
|
use Moose::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
4168
|
use Form::Factory::Message; |
|
1
|
|
|
|
|
269
|
|
|
1
|
|
|
|
|
595
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Interface for the result classes |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# requires qw( |
11
|
|
|
|
|
|
|
# is_valid is_validated |
12
|
|
|
|
|
|
|
# is_success is_outcome_known |
13
|
|
|
|
|
|
|
# content |
14
|
|
|
|
|
|
|
# messages |
15
|
|
|
|
|
|
|
# ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub is_failure { |
18
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
19
|
0
|
|
|
|
|
0
|
return not $self->is_success; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _return(&@) { |
24
|
23
|
|
|
23
|
|
45
|
my ($filter, @messages) = @_; |
25
|
|
|
|
|
|
|
|
26
|
23
|
|
|
|
|
50
|
my @filtered = grep { $filter->() } @messages; |
|
20
|
|
|
|
|
34
|
|
27
|
23
|
100
|
|
|
|
125
|
return wantarray ? @filtered : join "\n", map { $_->message } @filtered; |
|
9
|
|
|
|
|
302
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub all_messages { |
31
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
32
|
0
|
|
|
0
|
|
0
|
return _return { 1 } @{ $self->messages }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub info_messages { |
37
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
38
|
0
|
|
|
0
|
|
0
|
return _return { $_->type eq 'info' } @{ $self->messages }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub warning_messages { |
43
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
44
|
0
|
|
|
0
|
|
0
|
return _return { $_->type eq 'warning' } @{ $self->messages }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub error_messages { |
49
|
14
|
|
|
14
|
1
|
93
|
my $self = shift; |
50
|
14
|
|
|
10
|
|
83
|
return _return { $_->type eq 'error' } @{ $self->messages }; |
|
10
|
|
|
|
|
315
|
|
|
14
|
|
|
|
|
70
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub regular_messages { |
55
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
56
|
0
|
|
|
0
|
|
0
|
return _return { not $_->is_tied_to_field } @{ $self->messages }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub regular_info_messages { |
61
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
62
|
0
|
0
|
|
0
|
|
0
|
return _return { not $_->is_tied_to_field and $_->type eq 'info' } |
63
|
0
|
|
|
|
|
0
|
@{ $self->messages }; |
|
0
|
|
|
|
|
0
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub regular_warning_messages { |
68
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
69
|
0
|
0
|
|
0
|
|
0
|
return _return { not $_->is_tied_to_field and $_->type eq 'warning' } |
70
|
0
|
|
|
|
|
0
|
@{ $self->messages }; |
|
0
|
|
|
|
|
0
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub regular_error_messages { |
75
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
76
|
3
|
50
|
|
3
|
|
81
|
return _return { not $_->is_tied_to_field and $_->type eq 'error' } |
77
|
1
|
|
|
|
|
5
|
@{ $self->messages }; |
|
1
|
|
|
|
|
4
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub field_messages { |
82
|
1
|
|
|
1
|
1
|
2
|
my ($self, $field) = @_; |
83
|
0
|
0
|
|
0
|
|
0
|
return _return { $_->is_tied_to_field and $_->field eq $field } |
84
|
1
|
|
|
|
|
10
|
@{ $self->messages }; |
|
1
|
|
|
|
|
8
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub field_info_messages { |
89
|
0
|
|
|
0
|
1
|
0
|
my ($self, $field) = @_; |
90
|
0
|
0
|
0
|
0
|
|
0
|
return _return { $_->is_tied_to_field and $_->field eq $field and $_->type eq 'info'} |
91
|
0
|
|
|
|
|
0
|
@{ $self->messages }; |
|
0
|
|
|
|
|
0
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub field_warning_messages { |
96
|
0
|
|
|
0
|
1
|
0
|
my ($self, $field) = @_; |
97
|
0
|
0
|
0
|
0
|
|
0
|
return _return { $_->is_tied_to_field and $_->field eq $field and $_->type eq 'warning'} |
98
|
0
|
|
|
|
|
0
|
@{ $self->messages }; |
|
0
|
|
|
|
|
0
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub field_error_messages { |
103
|
7
|
|
|
7
|
1
|
89
|
my ($self, $field) = @_; |
104
|
7
|
50
|
33
|
7
|
|
242
|
return _return { $_->is_tied_to_field and $_->field eq $field and $_->type eq 'error'} |
105
|
7
|
|
|
|
|
33
|
@{ $self->messages }; |
|
7
|
|
|
|
|
27
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=pod |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=encoding UTF-8 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 NAME |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Form::Factory::Result - Interface for the result classes |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 VERSION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
version 0.022 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SYNOPSIS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $result = $action->results; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
if ($result->is_validated and $result->is_valid) { |
129
|
|
|
|
|
|
|
print "Action passed validation.\n"; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
if ($result->is_outcome_known and $result->is_success) { |
133
|
|
|
|
|
|
|
print "Action successfully processed.\n"; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
print "EXTRA INFO: ", $result->content->{extra_info}, "\n"; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
print "Messages: ", $result->all_messages, "\n"; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 DESCRIPTION |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
After an action has run in part or in whole, a result class will contain the current state of that sucess or failure. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 METHODS |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 is_failure |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
The opposite of L</is_success>. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 all_messages |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my $messages = $result->all_messages; |
153
|
|
|
|
|
|
|
my @messages = $result->all_messages; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Returns all messages. When a scalar is expected, it returns all messages concatenated with a newline between each. When a list is expected, it returns a list of L<Form::Factory::Message> objects. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 info_messages |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $messages = $result->info_messages; |
160
|
|
|
|
|
|
|
my @messages = $result->info_messages; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Returns all mesages with type info. Handles context the same as L</all_messages>. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 warning_messages |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my $messages = $result->warning_messages; |
167
|
|
|
|
|
|
|
my @messages = $result->warning_messages; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Returns all messages with type warning. Handles context the same as L</all_messages>. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 error_messages |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my $messages = $result->error_messages; |
174
|
|
|
|
|
|
|
my @messages = $result->error_messages; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Returns all messages with type error. Handles context the same as L</all_messages>. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 regular_messages |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
my $messages = $result->regular_messages; |
181
|
|
|
|
|
|
|
my @messages = $result->regular_messages; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Returns all messages that are not tied to a field. Handles context the same as L</all_messages>. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 regular_info_messages |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
my $messages = $result->regular_info_messages; |
188
|
|
|
|
|
|
|
my @messages = $result->regular_info_messages; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Returns all messages with type info that are not tied to a field. Handles context the same as L</all_messages>. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 regular_warning_messages |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
my $messages = $result->regular_warning_messages; |
195
|
|
|
|
|
|
|
my @messages = $result->regular_warning_messages; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Returns all messages with type warning that are not tied to a feild. Handles context the same as L</all_messages>. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head2 regular_error_messages |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
my $messages = $result->regular_error_messages; |
202
|
|
|
|
|
|
|
my @messages = $result->regular_error_messages; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Returns all messages with type error that are not tied to a field. Handles context the same as L</all_messages>. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 field_messages |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
my $messages = $result->field_messages($field); |
209
|
|
|
|
|
|
|
my @messages = $result->field_messages($field); |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Returns all messages that are tied to a particular field. Handles context the same as L</all_messages>. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 field_info_messages |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my $messages = $result->field_info_messages($field); |
216
|
|
|
|
|
|
|
my @messages = $result->field_info_messages($field); |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Returns all messages with type info that are tied to a particular field. Handles context the same as L</all_messages>. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 field_warning_messages |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my $messages = $result->field_warning_messages($field); |
223
|
|
|
|
|
|
|
my @messages = $result->field_warning_messages($field); |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Returns all messages with type warning tied to a particular field. Handles context the same as L</all_messages>. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 field_error_messages |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
my $messages = $result->field_error_messages($field); |
230
|
|
|
|
|
|
|
my @messages = $result->field_error_messages($field); |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Returns all messages with type error tied to a particular field. Handles context the same as L</all_messages>. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 AUTHOR |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Andrew Sterling Hanenkamp <hanenkamp@cpan.org> |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Qubling Software LLC. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
243
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |