File Coverage

lib/Egg/Plugin/FillInForm.pm
Criterion Covered Total %
statement 12 36 33.3
branch 0 14 0.0
condition 0 12 0.0
subroutine 4 10 40.0
pod 2 2 100.0
total 18 74 24.3


line stmt bran cond sub pod time code
1             package Egg::Plugin::FillInForm;
2             #
3             # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4             #
5             # $Id: FillInForm.pm 337 2008-05-14 12:30:09Z lushe $
6             #
7 1     1   463 use strict;
  1         3  
  1         43  
8 1     1   5 use warnings;
  1         2  
  1         30  
9 1     1   2685 use HTML::FillInForm;
  1         6594  
  1         21  
10              
11             our $VERSION = '3.00';
12              
13             sub _setup {
14 0     0     my($e)= @_;
15 0           $e->mk_accessors('fillin_ok');
16 0   0       $e->config->{plugin_fillinform} ||= {};
17 0 0         if ($e->isa('Egg::Plugin::FormValidator::Simple')) {
18 1     1   110 no warnings 'redefine';
  1         3  
  1         501  
19             *_valid_error= sub {
20 0     0     my($egg)= @_;
21 0 0 0       return ( $egg->stash->{error}
22             || $egg->form->has_missing
23             || $egg->form->has_invalid ) ? 1: 0;
24 0           };
25             } else {
26 0     0     *_valid_error= sub { 0 };
  0            
27             }
28 0           $e->next::method;
29             }
30             sub fillform_render {
31 0     0 1   my $e = shift;
32 0   0       my $body= shift || $e->response->body || return 0;
33 0 0         $body= \$body unless ref($body);
34 0 0         my $fdat= $_[0] ? ($_[1] ? {@_}: $_[0]): $e->request->params;
    0          
35 0 0         return 0 unless %$fdat;
36 0           $$body= HTML::FillInForm->new->fill(
37             scalarref => $body, fdat => $fdat,
38 0           %{$e->config->{plugin_fillinform}},
39             );
40 0           $body;
41             }
42             sub fillform {
43 0     0 1   my $e= shift;
44 0   0       my $body= $e->fillform_render(@_) || return 0;
45 0           $e->response->body($body);
46             }
47             sub _finalize {
48 0     0     my($e)= @_;
49 0 0 0       $e->fillform if ( $e->fillin_ok or $e->_valid_error );
50 0           $e->next::method;
51             }
52              
53             1;
54              
55             __END__
56              
57             =head1 NAME
58              
59             Egg::Plugin::FillInForm - HTML::FillInForm for Egg.
60              
61             =head1 SYNOPSIS
62              
63             use Egg qw/ FillInForm /;
64            
65             __PACKAGE__->egg_startup(
66            
67             plugin_fillinform => {
68             fill_password => 0,
69             ignore_fields => [qw{ param1 param2 }],
70             ...
71             },
72            
73             );
74            
75             $e->fillin_ok(1);
76            
77             my $output= $e->fillform_render(\$html, $hash);
78            
79             $e->fillform;
80              
81             =head1 DESCRIPTION
82              
83             L<HTML::FillInForm> It is a plugin to use.
84              
85             =head1 METHODS
86              
87             =head2 fillform_render ([HTML_TEXT], [HASH])
88              
89             It is L<HTML::FillInForm> as for the argument. Is passed and the result is
90             returned.
91              
92             When HTML_TEXT is omitted, $e->response->body is used.
93              
94             When HASH is omitted, $e-E<gt>request-E<gt>params is used.
95              
96             my $output= $e->fillform_render(\$html, $hash);
97              
98             =head2 fillform ([HTML_TAXT], [HASH])
99              
100             The result of 'fillform_render' is set in $e-E<gt>response-E<gt>body.
101              
102             $e->fillform_render(\$html, $hash);
103              
104             =head2 fillin_ok ( [BOOL] )
105              
106             Fillform comes to be done by '_finalize' when keeping effective.
107              
108             When the check error of this plugin occurs when L<Egg::Plugin::FormValidator::Simple>
109             is loaded, fillform is always done.
110              
111             $e->fillin_ok(1);
112              
113             =head1 SEE ALSO
114              
115             L<Egg::Release>,
116             L<HTML::FillInForm>,
117             L<Egg::Plugin::FormValidator::Simple>,
118             L<Catalyst::Plugin::FillInForm>,
119              
120             =head1 AUTHOR
121              
122             Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
123              
124             =head1 COPYRIGHT AND LICENSE
125              
126             Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>.
127              
128             This library is free software; you can redistribute it and/or modify
129             it under the same terms as Perl itself, either Perl version 5.8.6 or,
130             at your option, any later version of Perl 5 you may have available.
131              
132             =cut
133