package Egg::Plugin::FillInForm; # # Masatoshi Mizuno ElusheE<64>cpan.orgE # # $Id: FillInForm.pm 337 2008-05-14 12:30:09Z lushe $ # use strict; use warnings; use HTML::FillInForm; our $VERSION = '3.00'; sub _setup { my($e)= @_; $e->mk_accessors('fillin_ok'); $e->config->{plugin_fillinform} ||= {}; if ($e->isa('Egg::Plugin::FormValidator::Simple')) { no warnings 'redefine'; *_valid_error= sub { my($egg)= @_; return ( $egg->stash->{error} || $egg->form->has_missing || $egg->form->has_invalid ) ? 1: 0; }; } else { *_valid_error= sub { 0 }; } $e->next::method; } sub fillform_render { my $e = shift; my $body= shift || $e->response->body || return 0; $body= \$body unless ref($body); my $fdat= $_[0] ? ($_[1] ? {@_}: $_[0]): $e->request->params; return 0 unless %$fdat; $$body= HTML::FillInForm->new->fill( scalarref => $body, fdat => $fdat, %{$e->config->{plugin_fillinform}}, ); $body; } sub fillform { my $e= shift; my $body= $e->fillform_render(@_) || return 0; $e->response->body($body); } sub _finalize { my($e)= @_; $e->fillform if ( $e->fillin_ok or $e->_valid_error ); $e->next::method; } 1; __END__ =head1 NAME Egg::Plugin::FillInForm - HTML::FillInForm for Egg. =head1 SYNOPSIS use Egg qw/ FillInForm /; __PACKAGE__->egg_startup( plugin_fillinform => { fill_password => 0, ignore_fields => [qw{ param1 param2 }], ... }, ); $e->fillin_ok(1); my $output= $e->fillform_render(\$html, $hash); $e->fillform; =head1 DESCRIPTION L It is a plugin to use. =head1 METHODS =head2 fillform_render ([HTML_TEXT], [HASH]) It is L as for the argument. Is passed and the result is returned. When HTML_TEXT is omitted, $e->response->body is used. When HASH is omitted, $e-Erequest-Eparams is used. my $output= $e->fillform_render(\$html, $hash); =head2 fillform ([HTML_TAXT], [HASH]) The result of 'fillform_render' is set in $e-Eresponse-Ebody. $e->fillform_render(\$html, $hash); =head2 fillin_ok ( [BOOL] ) Fillform comes to be done by '_finalize' when keeping effective. When the check error of this plugin occurs when L is loaded, fillform is always done. $e->fillin_ok(1); =head1 SEE ALSO L, L, L, L, =head1 AUTHOR Masatoshi Mizuno ElusheE<64>cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright (C) 2008 Bee Flag, Corp. ELE. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available. =cut