line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Factory::Feature::Role::ControlValueConverter; |
2
|
|
|
|
|
|
|
$Form::Factory::Feature::Role::ControlValueConverter::VERSION = '0.022'; |
3
|
1
|
|
|
1
|
|
9949
|
use Moose::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
with qw( Form::Factory::Feature::Role::Control ); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
requires qw( value_to_control control_to_value ); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: form features that convert values |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
1; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__END__ |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=pod |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=encoding UTF-8 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Form::Factory::Feature::Role::ControlValueConverter - form features that convert values |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 VERSION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
version 0.022 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package MyApp::Feature::Control::Integer; |
32
|
|
|
|
|
|
|
use Moose; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
with qw( |
35
|
|
|
|
|
|
|
Form::Factory::Feature |
36
|
|
|
|
|
|
|
Form::Factory::Feature::Role::ControlValueConverter |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub check_control { |
40
|
|
|
|
|
|
|
my ($self, $cotnrol) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
die "not a scalar valued control" |
43
|
|
|
|
|
|
|
unless $control->does('Form::Factory::Control::Role::ScalarValue'); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub control_to_value { |
47
|
|
|
|
|
|
|
my ($self, $value) = @_; |
48
|
|
|
|
|
|
|
return int($value); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub value_to_control { |
52
|
|
|
|
|
|
|
my ($self, $value) = @_; |
53
|
|
|
|
|
|
|
return ''.$value; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 DESCRIPTION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This role is used to provide standard value convertions between control values and action attributes. This allows you to reuse a common conversion by creating a feature to handle it. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Use of this role implies L<Form::Factory::Feature::Role::Control>. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 ROLE METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The feature implementing this role must provide these methods. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 control_to_value |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This method is used to convert a value on a control for use in assignment to the action attribute to which it is attached. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This method should be defined like so: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub control_to_value { |
73
|
|
|
|
|
|
|
my ($self, $value) = @_; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return # ... converted value ... |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The C<$value> here will be teh value to convert. This is usually going to be the C<current_value> of the control, but might be something else, so make sure you use the given value for conversion. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 value_to_control |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This method does the reverse of C<control_to_value> and is used to convert the action attribute to the control value. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
It is defined like this: |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub value_to_control { |
87
|
|
|
|
|
|
|
my ($self, $value) = @_; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
return # ... converted value ... |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The C<$value> here will be a value from the action attribute (or something of the same type) and the value returned should be appropriate for assigning to the control value. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 AUTHOR |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Andrew Sterling Hanenkamp <hanenkamp@cpan.org> |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Qubling Software LLC. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
103
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |