File Coverage

blib/lib/Form/Factory/Feature/Role/InitializeControl.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::InitializeControl;
2             $Form::Factory::Feature::Role::InitializeControl::VERSION = '0.022';
3 1     1   439 use Moose::Role;
  1         1  
  1         7  
4              
5             requires qw( initialize_control );
6              
7             # ABSTRACT: control features that work on just constructed controls
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::InitializeControl - control features that work on just constructed controls
21              
22             =head1 VERSION
23              
24             version 0.022
25              
26             =head1 SYNOPSIS
27              
28             package MyApp::Feature::Control::LoadDBValue;
29             use Moose;
30              
31             with qw(
32             Form::Factory::Feature
33             Form::Factory::Feature::Role::Control
34             Form::Factory::Feature::Role::InitializeControl
35             );
36              
37             sub check_control {
38             my ($self, $control) = @_;
39              
40             # nasty ducks and they typings
41             die "control action has no record"
42             unless $control->action->can('record');
43             }
44              
45             sub initialize_control {
46             my $self = shift;
47             my $action = $self->action;
48             my $control = $self->control;
49              
50             my $name = $control->name;
51             my $record = $action->record;
52              
53             # Set the default value from the record value
54             $control->default_value( $record->$name );
55             }
56              
57             package Form::Factory::Feature::Control::Custom::LoadDatabaseValue;
58             sub register_implementation { 'MyApp::Feature::Control::LoadDBValue' }
59              
60             =head1 DESCRIPTION
61              
62             This role may be implemented by a control feature that needs to access a control and do something with it immediately after the control has been completely constructed.
63              
64             The feature must implement the C<initialize_control> method.
65              
66             =head1 ROLE METHODS
67              
68             =head2 initialize_control
69              
70             This method is called on the feature immediately after the control has been completely constructed. This method is called with no arguments and the return value is ignored.
71              
72             =head1 AUTHOR
73              
74             Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
75              
76             =head1 COPYRIGHT AND LICENSE
77              
78             This software is copyright (c) 2015 by Qubling Software LLC.
79              
80             This is free software; you can redistribute it and/or modify it under
81             the same terms as the Perl 5 programming language system itself.
82              
83             =cut