File Coverage

blib/lib/Form/Factory/Feature/Role/BuildAttribute.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::BuildAttribute;
2             $Form::Factory::Feature::Role::BuildAttribute::VERSION = '0.022';
3 1     1   580 use Moose::Role;
  1         1  
  1         7  
4              
5             requires qw( build_attribute );
6              
7             # ABSTRACT: control features that modify the action attribute
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::BuildAttribute - control features that modify the action attribute
21              
22             =head1 VERSION
23              
24             version 0.022
25              
26             =head1 SYNOPSIS
27              
28             package MyApp::Feature::AddPredicate;
29             use Moose;
30              
31             with qw(
32             Form::Factory::Feature
33             Form::Factory::Feature::Role::BuildAttribute
34             Form::Factory::Feature::Role::Control
35             );
36              
37             sub build_attribute {
38             my ($class, $options, $meta, $name, $attr) = @_;
39             $attr->{predicate} = 'has_' . $name;
40             }
41              
42             package Form::Factory::Feature::Control::Custom::AddPredicate;
43             sub register_implementation { 'MyApp::Feature::FillFromRecord' }
44              
45             =head1 DESCRIPTION
46              
47             Control features that implement this role are given the opportunity to directly modify the action attribute just before it is added to the meta-class.
48              
49             This is done by implementing the C<build_attribute> class method. This method will be passed a hash representing the feature arguments for this feature (since the feature will not yet exist as an object). It will then be passed the meta-class object, the name of the attribute being added, and a normalized hash of attribute parameters.
50              
51             You may use these arguments to manipulate the attribute before it is created, create additional attributes, etc.
52              
53             =head1 ROLE METHODS
54              
55             =head2 build_attribute
56              
57             The C<build_attribute> method should be implemented something like this:
58              
59             sub build_attribute {
60             my ($class, $options, $meta, $name, $attr) = @_;
61              
62             # do something ...
63             }
64              
65             This method is called while the action class is being compiled. This method can be used to modify how the action attribute is created.
66              
67             The C<$class> is the feature class this subroutine belongs to. The feature will not have been created nearly this early.
68              
69             The C<$options> are the feature options passed to the C<has_control> statement.
70              
71             The C<$meta> is the metaclass object that the attribute is about to be added to.
72              
73             The C<$name> is the name of the attribute being added to the metaclass.
74              
75             The C<$attr> is the arguments that are about to be passed to the attribute constructor. This the hash of argumentst that will be passed to the attribute constructor shortly. Modifying this hash will change the attribute construction.
76              
77             =head1 AUTHOR
78              
79             Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
80              
81             =head1 COPYRIGHT AND LICENSE
82              
83             This software is copyright (c) 2015 by Qubling Software LLC.
84              
85             This is free software; you can redistribute it and/or modify it under
86             the same terms as the Perl 5 programming language system itself.
87              
88             =cut