File Coverage

blib/lib/Form/Factory/Interface/HTML/Widget.pm
Criterion Covered Total %
statement 9 11 81.8
branch 2 4 50.0
condition n/a
subroutine 3 3 100.0
pod 2 2 100.0
total 16 20 80.0


line stmt bran cond sub pod time code
1             package Form::Factory::Interface::HTML::Widget;
2             $Form::Factory::Interface::HTML::Widget::VERSION = '0.022';
3 1     1   456 use Moose::Role;
  1         2  
  1         6  
4              
5             requires qw( render_control consume_control );
6              
7             # ABSTRACT: rendering/consuming HTML controls
8              
9              
10             has alternate_renderer => (
11             is => 'rw',
12             isa => 'CodeRef',
13             predicate => 'has_alternate_renderer',
14             );
15              
16              
17             has alternate_consumer => (
18             is => 'rw',
19             isa => 'CodeRef',
20             predicate => 'has_alternate_consumer',
21             );
22              
23              
24             sub render {
25 6     6 1 10 my $self = shift;
26              
27 6 50       262 if ($self->has_alternate_renderer) {
28 0         0 return $self->alternate_renderer->($self, @_);
29             }
30             else {
31 6         30 return $self->render_control(@_);
32             }
33             }
34              
35              
36             sub consume {
37 528     528 1 501 my $self = shift;
38              
39 528 50       21713 if ($self->has_alternate_consumer) {
40 0         0 $self->alternate_consumer->($self, @_);
41             }
42             else {
43 528         1591 $self->consume_control(@_);
44             }
45             }
46              
47              
48             1;
49              
50             __END__
51              
52             =pod
53              
54             =encoding UTF-8
55              
56             =head1 NAME
57              
58             Form::Factory::Interface::HTML::Widget - rendering/consuming HTML controls
59              
60             =head1 VERSION
61              
62             version 0.022
63              
64             =head1 DESCRIPTION
65              
66             Widget is the low-level API for rendering and processing HTML/HTTP form elements.
67              
68             =head1 ATTRIBUTES
69              
70             =head2 alternate_renderer
71              
72             If the renderer needs to be customized, provide a custom renderer here. This is a code reference that is passed the control and options like the usual renderer method.
73              
74             =head2 alternate_consumer
75              
76             If the control needes to be consumed in a custom way, you can add that here. This is a code reference that is passed the control and options like the usual consumer method.
77              
78             =head1 METHODS
79              
80             =head2 render
81              
82             Renders the HTML required to use this method.
83              
84             =head2 consume
85              
86             Consumes the value from the request.
87              
88             =head1 ROLE METHODS
89              
90             These methods must be implemented by role implementers.
91              
92             =head2 render_control
93              
94             Return HTML to render the control.
95              
96             =head2 consume_control
97              
98             Given consumer options, process the input.
99              
100             =head1 AUTHOR
101              
102             Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
103              
104             =head1 COPYRIGHT AND LICENSE
105              
106             This software is copyright (c) 2015 by Qubling Software LLC.
107              
108             This is free software; you can redistribute it and/or modify it under
109             the same terms as the Perl 5 programming language system itself.
110              
111             =cut