File Coverage

blib/lib/Form/Factory/Feature/Role/BuildControl.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package Form::Factory::Feature::Role::BuildControl;
2             $Form::Factory::Feature::Role::BuildControl::VERSION = '0.022';
3 1     1   7329 use Moose::Role;
  1         3  
  1         5  
4              
5             requires qw( build_control );
6              
7             # ABSTRACT: control features that modify control construction
8              
9              
10             1;
11              
12             __END__
13              
14             =pod
15              
16             =encoding UTF-8
17              
18             =head1 NAME
19              
20             Form::Factory::Feature::Role::BuildControl - control features that modify control construction
21              
22             =head1 VERSION
23              
24             version 0.022
25              
26             =head1 SYNOPSIS
27              
28             package MyApp::Feature::Control::CapitalizeLabel;
29             use Moose;
30              
31             with qw(
32             Form::Fctory::Feature
33             Form::Factory::Feature::Role::BuildControl
34             Form::Factory::Feature::Role::Control
35             );
36              
37             sub build_control {
38             my ($class, $options, $action, $name, $control) = @_;
39              
40             # could modify the control type too:
41             # $control->{control} = 'full_text';
42              
43             $control->{options}{label} = uc $control->{options}{label};
44             }
45              
46             package Form::Factory::Feature::Control::Custom::CapitalizeLabel;
47             sub register_implementation { 'MyApp::Feature::Control::CapitalizeLabel' }
48              
49             =head1 DESCRIPTION
50              
51             Control features that do this role are given the opportunity to modify how the control is build for the attribute. Any modifications to the C<$options> hash given, whether to the control or to the options themselves will be passed on when creating the control.
52              
53             In the life cycle of actions, this happens immediately before the control is created, but after any deferred values are evaluated. This means that the given hash should now look exactly as it will before being passed to the C<new_control> method of the interface.
54              
55             =head1 ROLE METHODS
56              
57             =head2 build_control
58              
59             A feature implementing this role must provide this method. It is defined as follows:
60              
61             sub build_control {
62             my ($class, $options, $action, $name, $control) = @_;
63            
64             # do something...
65             }
66              
67             This is called in by the action class immediately before the control is instantiated and gives the feature the opportunity to modify how the control is created.
68              
69             The C<$class> argument is the name of the feature class. The feature will not have been constructed yet.
70              
71             The C<$options> argument is the hash of options passed to C<has_control> for this feature. For example, if your feature is named "foo_bar" and you used your feature like this:
72              
73             has_control foo_bar => (
74             features => {
75             foo_bar => {
76             framiss_size => 12,
77             trunnion_speed => 42,
78             },
79             },
80             );
81              
82             The C<$options> would be passed as:
83              
84             $options = { framiss_size => 12, trunnion_speed => 42 };
85              
86             If the feature is just "turned on" with a 1 passed, then the hash reference will be empty (but still passed as a hash reference).
87              
88             The C<$action> argument is the current action object as of the moment the control is being created.
89              
90             The C<$name> argument is the name of the control (and action attribute) that this feature is attached to.
91              
92             The C<$control> argument is a hash reference containing two keys. The "control" key will name the type of control this is. The "options" contains a copy of the options that are about to be passed to the control's constructor. You may modify either of these to modify which control class is constructed (by modifying "control") or the options passed to that constructor (by modifying the "options").
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