line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Factory::Feature::Role::CustomControlMessage; |
2
|
|
|
|
|
|
|
$Form::Factory::Feature::Role::CustomControlMessage::VERSION = '0.022'; |
3
|
1
|
|
|
1
|
|
705
|
use Moose::Role; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
with qw( Form::Factory::Feature::Role::CustomMessage ); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: control features with custom messages |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub format_message { |
11
|
8
|
|
|
8
|
1
|
11
|
my $self = shift; |
12
|
8
|
|
33
|
|
|
290
|
my $message = $self->message || shift; |
13
|
8
|
|
|
|
|
360
|
my $control = $self->control; |
14
|
|
|
|
|
|
|
|
15
|
8
|
50
|
|
|
|
27
|
my $control_label |
16
|
|
|
|
|
|
|
= $control->does('Form::Factory::Control::Role::Labeled') ? $control->label |
17
|
|
|
|
|
|
|
: $control->name |
18
|
|
|
|
|
|
|
; |
19
|
|
|
|
|
|
|
|
20
|
8
|
|
|
|
|
38
|
sprintf $message, $control_label; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub control_info { |
25
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
26
|
0
|
|
|
|
|
0
|
my $message = $self->format_message(shift); |
27
|
0
|
|
|
|
|
0
|
$self->result->field_info($self->control->name, $message); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub control_warning { |
32
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
33
|
0
|
|
|
|
|
0
|
my $message = $self->format_message(shift); |
34
|
0
|
|
|
|
|
0
|
$self->result->field_warning($self->control->name, $message); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub control_error { |
39
|
8
|
|
|
8
|
1
|
14
|
my $self = shift; |
40
|
8
|
|
|
|
|
29
|
my $message = $self->format_message(shift); |
41
|
8
|
|
|
|
|
317
|
$self->result->field_error($self->control->name, $message); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=pod |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=encoding UTF-8 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Form::Factory::Feature::Role::CustomControlMessage - control features with custom messages |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 VERSION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
version 0.022 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SYNOPSIS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has_control foo => ( |
63
|
|
|
|
|
|
|
control => 'text', |
64
|
|
|
|
|
|
|
features => { |
65
|
|
|
|
|
|
|
match_code => { |
66
|
|
|
|
|
|
|
message => 'Foo values must be even', |
67
|
|
|
|
|
|
|
code => sub { $_[0] % 2 == 0 }, |
68
|
|
|
|
|
|
|
}, |
69
|
|
|
|
|
|
|
}, |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 DESCRIPTION |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
A control feature may consume this role in order to allow the user to specify a custom message on failure. This message may include a single "%s" placeholder, which will be filled in with the label or name of the control. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 METHODS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 format_message |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $formatted_message = $feature->format_message($unformatted_message); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Given a message containing a single C<%s> placeholder, it fills that placeholder with the control's label. If the control does not implement L<Form::Factory::Control::Role::Labeled>, the control's name is used instead. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 control_info |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Reports an informational message automatically filtered through L</format_message>. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 control_warning |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Reports a warning automatically filtered through L</format_message>. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 control_error |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Reports an error automatically filtered through L</format_error>. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 AUTHOR |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Andrew Sterling Hanenkamp <hanenkamp@cpan.org> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Qubling Software LLC. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
105
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |