CGI::Ex::Fill - Yet another form filler
use CGI::Ex::Fill qw(form_fill); my $text = my_own_template_from_somewhere(); my $form = CGI->new; # OR # my $form = {key => 'value'} # OR # my $form = [CGI->new, CGI->new, {key1 => 'val1'}, CGI->new]; form_fill(\$text, $form); # modifies $text # OR # my $copy = form_fill($text, $form); # copies $text ALSO my $formname = 'formname'; # table to parse (undef = anytable) my $fp = 0; # fill_passwords ? default is true my $ignore = ['key1', 'key2']; # OR {key1 => 1, key2 => 1}; form_fill(\$text, $form, $formname, $fp, $ignore); ALSO ### delay getting the value until we find an element that needs it my $form = {key => sub {my $key = shift; # get and return value}};
form_fill is directly comparable to HTML::FillInForm. It will pass the same suite of tests (actually - it is a little bit kinder on the parse as it won't change case, reorder your attributes, or miscellaneous spaces).
HTML::FillInForm both benefits and suffers from being based on HTML::Parser. It is good for standards and poor for performance. Testing the form_fill module against HTML::FillInForm gave some surprising results. On tiny forms (< 1 k) form_fill was ~ 17% faster than FillInForm. If the html document incorporated very many entities at all, the performace of FillInForm goes down (and down). However, if you are only filling in one form every so often, then it shouldn't matter - but form_fill will be nicer on the tags and won't balk at ugly html. See the benchmarks in the t/samples directory for more information (ALL BENCHMARKS SHOULD BE TAKEN WITH A GRAIN OF SALT).
Because there are too many problems that could occur with html comments and javascript, form_fill temporarily removes them during the fill. You may disable this behavior by setting $REMOVE_COMMENT and $REMOVE_SCRIPT to 0 before calling form_fill. The main reason for doing this would be if you wanted to have form elments inside the javascript and comments get filled. Disabling the removal only results in a speed increase of 5%. The function uses \0COMMENT\0 and \0SCRIPT\0 as placeholders so i'd avoid these in your text (Actually they may be reset to whatever you'd like via $MARKER_COMMENT and $MARKER_SCRIPT).
Paul Seamons
This module may distributed under the same terms as Perl itself.
To install CGI::Ex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::Ex
CPAN shell
perl -MCPAN -e shell install CGI::Ex
For more information on module installation, please visit the detailed CPAN module installation guide.