HTML-FillInForm-2.21/0000755000175100017510000000000012373152053012652 5ustar markmarkHTML-FillInForm-2.21/MANIFEST0000644000175100017510000000125412373152053014005 0ustar markmarkChanges MANIFEST Makefile.PL META.yml Module meta-data (added by MakeMaker) README lib/HTML/FillInForm.pm t/00_base.t t/01_form.t t/02_hidden.t t/03_checkbox.t t/04_select.t t/05_textarea.t t/06_radio.t t/07_reuse.t t/08_multiple_objects.t t/09_default_type.t t/10_escape.t t/11_target.t t/12_mult.t t/13_warning.t t/14_password.t t/15_multiple_fields.t t/16_ignore_fields.t t/17_xhtml.t t/18_ignore_fdat.t t/19_extra.t t/20_scalarref.t t/21_disable_fields.t t/22_undef.t t/23_absent_checkbox.t t/24_radio_absent_checkboxes.t t/25_select_absent_checkboxes.t t/26_invalid_fields.t t/data/form1.html META.json Module JSON meta-data (added by MakeMaker) HTML-FillInForm-2.21/README0000644000175100017510000000202412373151675013541 0ustar markmarkThis module automatically inserts data from a previous HTML form into the HTML input and select tags. It is a subclass of HTML::Parser and uses it to parse the HTML and insert the values into the form tags. One useful application is after a user submits an HTML form without filling out required field. HTML::FillInForm can be used to redisplay the HTML form with all the form elements containing the submitted info. Please note that this module requires HTML::Parser 3.26 or greater. HTML::FillInForm installed by default by several web hosting providers, including pair.com - see http://www.pair.com/pair/support/library/serverconfig/perlmods.html It is also available as a package for some Linux distribution, including Mandrake. See: http://rpmfind.net/linux/RPM/cooker/cooker/i586/Mandrake/RPMS/perl-HTML-FillInForm-0.29-2mdk.noarch.html Copyright (c) 2002-2007 Thomas J. Mather, tjmather@maxmind.com All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself. HTML-FillInForm-2.21/Changes0000644000175100017510000001547512373152001014152 0ustar markmark 2.21 - August 14th, 2014 - Declare CGI.pm as a testing dependency (RT #98012, thanks to Martin McGrath) 2.20 - August 10th, 2013 - Updated to support HTML5 (RT #75933, thanks to charsbar) 2.11 - June 3rd, 2013 Updated tests so that they pass with Perl 5.18 (Mark Stosberg) 2.1 - August 29th, 2011 Fixed disable_fields option (#52667 Dirk Braun, Goro Fuji) Add an option to clear absent checkboxes (#44101 Alex Kapranoff) Fix incorrectly multiple escaped data in list context (#34081 Miika Pekkarinen) Allow FIF to process the new field types (URL, email, and number) as defined in the HTML5 draft and already implemented by the iPhone. (Michael Fisher) Allow alternate parsing class (Mark Stosberg) mark invalid fields (Sam Tregar) 2.0 - September 11th, 2007 Allow passing an arrayref of hashrefs through fdat (Mark Stosberg, Michael Graham) Several new shortcuts: (Mark Stosberg) Allow calling fill() as a class method as a shortcut. Allow \$html as shortcut for scalarref => \$html Allow \@html as shortcut for arrayref => \@html Allow \*html as shortcut for file => \*html Allow 'html' as shortcut for file => 'html' Allow $q as shortcut for fobject => $q Allow \%fdat as shortcut for fdat => \%fdat In summary, instead of this: my $fif = HTML::FillInForm->new; $fif->fill( scalarref => \$html, fdat => \%data ); You can simply write: HTML::FillInForm->fill( \$html, \%data ); Fixed disable_fields bug (Boris Zentner) Add support for ID attribute on form tags (name attribute is deprecated in xhtml) [rt.cpan.org #27376] (Anthony Ettinger) 1.07 - August 2nd, 2007 Added 'disable_fields' method [rt.cpan.org #6342] (Trevor Schellhorn) Support IE down-level revealed HTML comments [rt.cpan.org #19468] (Michael Peters) hash is not reset before each() is called [rt.cpan.org #24980] (Simon P. Ditner) Fix a bug the last plaintext part might be chopped if called via scalarref [rt.cpan.org #21750] (Tatsuhiko Miyagawa) Fix bug when passing 0 in array ref to textfields, also see [rt.cpan.org #22195] (Paul Miller) No longer generate warning if empty array as the value for a select attribute is passed (Dave Rolsky) 1.06 - October 13th, 2005 Distinguish between selects with and without the multiple attribute set (Alexander Hartmaier) Added warnings to PREREQ_PM 1.05 - December 19th, 2004 Added new tests in 19_extra.t (Vsevolod (Simon) Ilyushchenko) as part of Phalanx Make it clearer that doesn't have a CGI.pm dependency. 1.04 - March 8th, 2004 Now queries passed objects for form fields as it encounters them instead of asking for all fields up front. This allows the type of object passed to not have to return all the fields in a empty ->param() call. (Dave Rolsky) Generate XHTML-compliant tags (Dave Rolsky) Documented behavior when passing undef values. Fixed bug when HTML form has two or more radio buttons and second or higher radio button is selected. (Dan Kubb) Made ignore_fields work with fdat, included new test script 18_ignore_fdat.t (James Tolley) 1.03 - October 15th 2003 Fixed warning messages when textarea doesn't have a name attribute (Rob Brown) 1.02 - June 10th 2003 Updated required version number for HTML::Parser to 3.26 in Makefile.PL (Ken Williams) 1.01 - December 31st 2002 Fixed issue with HTML::Parser decoding high-bit entities, by setting attr_encoded option, now requires HTML::Parser >= 3.26. (Jonathan Swartz) 1.00 - August 28th 2002 Workaround for Opera 6.01/02 bug with selected radio boxes - place space before ending "/>" in (Bill Moseley) 0.29 - May 5th 2002 Added ignore_fields option (Boris Zentner) 0.28 - April 27th 2002 Added missing ! in declaration handler (Boris Zentner) Fill all values with the same name if one value is passed (Boris Zentner, Gabriel Burka) 0.27 - April 20th 2002 Fixes to pass through comments, processing instructions, and declarations (Boris Zentner) 0.26 - April 16th 2002 Added fill_password option (Tatsuhiko Miyagawa) 0.25 - April 3rd 2002 Fixed bug with passing single value to multi-valued fields (Maurice Aubrey) 0.24 - March 3rd 2002 Added no_debug to use CGI in t/13_warning.t 0.23 - January 4th 2002 Cleaned up warning messages for input fields without a name (Boris Zentner) 0.22 - November 10th 2001 Fixed bug with multiple inputs (Mark Stosberg) 0.21 - October 16th 2001 Updated credits section 0.20 - October 16th 2001 Fixed bug where selected value of '0' were skipped (Trevor Schellhorn) 0.19 - August 25th 2001 Fixed bug where option values between tags had trailing or leading whitespace (Ade Olonoh) Fixed bug for type tags (Andrew Creer) Fix for error message (object -> fobject) (Mark Stosberg) 0.18 - July 7th 2001 Fix for test on HTML escaping (thanks to Jost Krieger for report) 0.17 - June 29th 2001 Added "fill in target form" feature (Tatsuhiko Miyagawa) 0.16 - June 28th 2001 Fixed problems with HTML escaping (Tatsuhiko Miyagawa) 0.15 - June 18th 2001 Works with checkbox tags that don't have value attribute. (Philip Mak) 0.14 - May 17th 2001 Removed warning message for submit tags. (Joseph Yanni) 0.13 - May 13th 2001 Fixed bug when TYPE attr of input tag not set (Martin H. Sluka) Added docs on password caching (Mark Stosberg) 0.12 - May 11th 2001 Support for multiple fobjects. Fixed bug where new documents were feed into a used $fif object. 0.11 - March 16th 2001 Fixed problem when fdat maps the name of a textarea to an empty string (''). Thanks to Jim Miner for the patch! 0.10 - January 19th 2001 Fixed problem with empty option tags (e.g. ) Thanks to Ade Olonoh for the patch! 0.09 - January 15th 2001 Text in textarea is now escaped. 0.08 - January 15th 2001 Option tags without "value" attribute get filled in correctly. Will not croak anymore if fobject's param method returns undef. 0.07 - January 5th 2001 Added support for multiple checkboxes and select fields, thanks to Patrick Michael Kane for the patch and test script for checkboxes! 0.06 - October 9th 2000 Fixed bug with "0" value in (hidden) fields Added docs from using HTML::FillInForm from Apache::ASP and Apache::PageKit 0.05 - August 28th 2000 Added better support for checkboxes. 0.04 - August 10th 2000 Fixed bug with hidden fields 0.03 - August 10th 2000 FillInForm now forces hidden fields to have a value. So is transformed to if no value is set for 'foo'. Fixed bug with case-sensitivity and missing checkbox. Thanks to Tom Lancaster for this bug report and fix! Added some test scripts. 0.02 - June 27th 2000 Fixed bug with option tags. Now displays all 'option' tag attributes, in addition to selected and value. Better support for boolean attributes. 0.01 - June 18th 2000 Initial Release of Module. HTML-FillInForm-2.21/lib/0000755000175100017510000000000012373152053013420 5ustar markmarkHTML-FillInForm-2.21/lib/HTML/0000755000175100017510000000000012373152053014164 5ustar markmarkHTML-FillInForm-2.21/lib/HTML/FillInForm.pm0000644000175100017510000005613312373152007016532 0ustar markmarkpackage HTML::FillInForm; use integer; # no floating point math so far! use strict; # and no funny business, either. use Carp; # generate better errors with more context # required for UNIVERSAL->can require 5.005; use vars qw($VERSION @ISA); $VERSION = '2.21'; sub new { my $class = shift; my $self = bless {}, $class; # required for attr_encoded my %arg = @_ || (); my $parser_class = $arg{parser_class} || 'HTML::Parser'; eval "require $parser_class;" || die "require $parser_class failed: $@"; @ISA = ($parser_class); $self->init(@_); unless ($self->can('attr_encoded')) { die "attr_encoded method is missing. If are using HTML::Parser, you need at least version 3.26"; } # tell HTML::Parser not to decode attributes $self->attr_encoded(1); return $self; } # a few shortcuts to fill() sub fill_file { my $self = shift; return $self->fill('file' ,@_); } sub fill_arrayref { my $self = shift; return $self->fill('arrayref' ,@_); } sub fill_scalarref { my $self = shift; return $self->fill('scalarref',@_); } # track the keys we support. Useful for file-name detection. sub _known_keys { return { scalarref => 1, arrayref => 1, fdat => 1, fobject => 1, file => 1, target => 1, fill_password => 1, ignore_fields => 1, disable_fields => 1, invalid_fields => 1, invalid_class => 1, } } sub fill { my $self = shift; # If we are called as a class method, go ahead and call new(). $self = $self->new if (not ref $self); my %option; # If the first arg is a scalarref, translate that to scalarref => $first_arg if (ref $_[0] eq 'SCALAR') { $option{scalarref} = shift; } elsif (ref $_[0] eq 'ARRAY') { $option{arrayref} = shift; } elsif (ref $_[0] eq 'GLOB') { $option{file} = shift; } elsif (ref $_[0]) { croak "data source is not a reference type we understand"; } # Last chance, if the first arg isn't one of the known keys, we # assume it is a file name. elsif (not _known_keys()->{$_[0]} ) { $option{file} = shift; } else { # Should be a known key. Nothing to do. } # Now, check to see if the next arg is also a reference. my $data; if (ref $_[0]) { $data = shift; $data = [$data] unless ref $data eq 'ARRAY'; for my $source (@$data) { if (ref $source eq 'HASH') { push @{ $option{fdat} }, $source; } elsif (ref $source) { if ($source->can('param')) { push @{ $option{fobject} }, $source; } else { croak "data source $source does not supply a param method"; } } elsif (defined $source) { croak "data source $source is not a hash or object reference"; } } } # load in the rest of the options %option = (%option, @_); # As suggested in the docs, merge multiple fdats into one. if (ref $option{fdat} eq 'ARRAY') { my %merged; for my $hash (@{ $option{fdat} }) { for my $key (keys %$hash) { $merged{$key} = $hash->{$key}; } } $option{'fdat'} = \%merged; } my %ignore_fields; %ignore_fields = map { $_ => 1 } ( ref $option{'ignore_fields'} eq 'ARRAY' ) ? @{ $option{ignore_fields} } : $option{ignore_fields} if exists( $option{ignore_fields} ); $self->{ignore_fields} = \%ignore_fields; my %disable_fields; %disable_fields = map { $_ => 1 } ( ref $option{'disable_fields'} eq 'ARRAY' ) ? @{ $option{disable_fields} } : $option{disable_fields} if exists( $option{disable_fields} ); $self->{disable_fields} = \%disable_fields; my %invalid_fields; %invalid_fields = map { $_ => 1 } ( ref $option{'invalid_fields'} eq 'ARRAY' ) ? @{ $option{invalid_fields} } : $option{invalid_fields} if exists( $option{invalid_fields} ); $self->{invalid_fields} = \%invalid_fields; if (my $fdat = $option{fdat}){ # Copy the structure to prevent side-effects. my %copy; keys %$fdat; # reset fdat if each or Dumper was called on fdat while(my($key, $val) = each %$fdat) { next if exists $ignore_fields{$key}; $copy{ $key } = ref $val eq 'ARRAY' ? [ @$val ] : $val; } $self->{fdat} = \%copy; } # We want the reference to these objects to go out of scope at the # end of the method. local $self->{objects} = []; if(my $objects = $option{fobject}){ unless(ref($objects) eq 'ARRAY'){ $objects = [ $objects ]; } for my $object (@$objects){ # make sure objects in 'param_object' parameter support param() defined($object->can('param')) or croak("HTML::FillInForm->fill called with fobject option, containing object of type " . ref($object) . " which lacks a param() method!"); } $self->{objects} = $objects; } if (my $target = $option{target}){ $self->{'target'} = $target; } if (my $invalid_class = $option{invalid_class}){ $self->{'invalid_class'} = $invalid_class; } else { $self->{'invalid_class'} = 'invalid'; } if (defined($option{fill_password})){ $self->{fill_password} = $option{fill_password}; } else { $self->{fill_password} = 1; } $self->{clear_absent_checkboxes} = $option{clear_absent_checkboxes}; # make sure method has data to fill in HTML form with! unless(exists $self->{fdat} || $self->{objects}){ croak("HTML::FillInForm->fillInForm() called without 'fobject' or 'fdat' parameter set"); } local $self->{object_param_cache}; if(my $file = $option{file}){ $self->parse_file($file); } elsif (my $scalarref = $option{scalarref}){ $self->parse($$scalarref); } elsif (my $arrayref = $option{arrayref}){ for (@$arrayref){ $self->parse($_); } } $self->eof; return delete $self->{output}; } # handles opening HTML tags such as sub start { my ($self, $tagname, $attr, $attrseq, $origtext) = @_; # set the current form if ($tagname eq 'form') { $self->{object_param_cache} = {}; if (exists $attr->{'name'} || exists $attr->{'id'}) { $self->{'current_form'} = $attr->{'name'} || $attr->{'id'}; } else { # in case of previous one without delete $self->{'current_form'}; } } # This form is not my target. if (exists $self->{'target'} && (! exists $self->{'current_form'} || $self->{'current_form'} ne $self->{'target'})) { $self->{'output'} .= $origtext; return; } # HTML::Parser converts tagname to lowercase, so we don't need /i if ($self->{option_no_value}) { $self->{output} .= '>'; delete $self->{option_no_value}; } # Check if we need to disable this field $attr->{disabled} = 'disabled' if exists $attr->{'name'} and exists $self->{disable_fields}{ $attr->{'name'} } and $self->{disable_fields}{ $attr->{'name'} } and not ( exists $attr->{disabled} and $attr->{disabled} ); # Check if we need to invalidate this field my $invalidating = 0; if (exists $attr->{name} and exists $self->{invalid_fields}{ $attr->{name} } and $self->{invalid_fields}{ $attr->{name} }) { $invalidating = 1; if (exists $attr->{class} and length $attr->{class}) { # don't add the class if it's already there unless ($attr->{class} =~ /\b\Q$self->{invalid_class}\E\b/) { $attr->{class} .= " $self->{invalid_class}"; } } else { $attr->{class} = $self->{invalid_class}; } } if ($tagname eq 'input'){ my $value = exists $attr->{'name'} ? $self->_get_param($attr->{'name'}) : undef; # force hidden fields to have a value $value = '' if exists($attr->{'type'}) && $attr->{'type'} eq 'hidden' && ! exists $attr->{'value'} && ! defined $value; # browsers do not pass unchecked checkboxes at all, so hack around $value = '' if $self->{clear_absent_checkboxes} && !defined $value && exists($attr->{'type'}) && ($attr->{'type'} eq 'checkbox' || $attr->{'type'} eq 'radio'); if (defined($value)){ # check for input type, noting that default type is text if (!exists $attr->{'type'} || $attr->{'type'} =~ /^(text|textfield|hidden|tel|search|url|email|datetime|date|month|week|time|datetime\-local|number|range|color|)$/i){ if ( ref($value) eq 'ARRAY' ) { $value = shift @$value; $value = '' unless defined $value; } $attr->{'value'} = __escapeHTML($value); } elsif (lc $attr->{'type'} eq 'password' && $self->{fill_password}) { if ( ref($value) eq 'ARRAY' ) { $value = shift @$value; $value = '' unless defined $value; } $attr->{'value'} = __escapeHTML($value); } elsif (lc $attr->{'type'} eq 'radio'){ if ( ref($value) eq 'ARRAY' ) { $value = $value->[0]; $value = '' unless defined $value; } # value for radio boxes default to 'on', works with netscape $attr->{'value'} = 'on' unless exists $attr->{'value'}; if ($attr->{'value'} eq __escapeHTML($value)){ $attr->{'checked'} = 'checked'; } else { delete $attr->{'checked'}; } } elsif (lc $attr->{'type'} eq 'checkbox'){ # value for checkboxes default to 'on', works with netscape $attr->{'value'} = 'on' unless exists $attr->{'value'}; delete $attr->{'checked'}; # Everything is unchecked to start $value = [ $value ] unless ref($value) eq 'ARRAY'; foreach my $v ( @$value ) { if ( $attr->{'value'} eq __escapeHTML($v) ) { $attr->{'checked'} = 'checked'; } } # } else { # warn(qq(Input field of unknown type "$attr->{type}": $origtext)); } } $self->{output} .= "<$tagname"; while (my ($key, $value) = each %$attr) { next if $key eq '/'; $self->{output} .= sprintf qq( %s="%s"), $key, $value; } # extra space put here to work around Opera 6.01/6.02 bug $self->{output} .= ' /' if $attr->{'/'}; $self->{output} .= ">"; } elsif ($tagname eq 'option'){ my $value = $self->_get_param($self->{selectName}); # browsers do not pass selects with no selected options at all, # so hack around $value = '' if $self->{clear_absent_checkboxes} && !defined $value; $value = [ $value ] unless ( ref($value) eq 'ARRAY' ); if ( defined $value->[0] ){ delete $attr->{selected} if exists $attr->{selected}; if(defined($attr->{'value'})){ # option tag has value attr - if ($self->{selectMultiple}){ # check if the option tag belongs to a multiple option select foreach my $v ( grep { defined } @$value ) { if ( $attr->{'value'} eq __escapeHTML($v) ){ $attr->{selected} = 'selected'; } } } else { # if not every value of a fdat ARRAY belongs to a different select tag if (not $self->{selectSelected}){ if ( $attr->{'value'} eq __escapeHTML($value->[0])){ shift @$value if ref($value) eq 'ARRAY'; $attr->{selected} = 'selected'; $self->{selectSelected} = 1; # remember that an option tag is selected for this select tag } } } } else { # option tag has no value attr - # save for processing under text handler $self->{option_no_value} = __escapeHTML($value); } } $self->{output} .= "<$tagname"; while (my ($key, $value) = each %$attr) { $self->{output} .= sprintf qq( %s="%s"), $key, $value; } unless ($self->{option_no_value}){ # we can close option tag here $self->{output} .= ">"; } } elsif ($tagname eq 'textarea'){ # need to re-output the -> # we need to set outputText to 'no' so that 'foobar' won't be printed $self->{outputText} = 'no'; $self->{output} .= __escapeHTML($value); } } elsif ($tagname eq 'select'){ $self->{selectName} = $attr->{'name'}; if (defined $attr->{'multiple'}){ $self->{selectMultiple} = 1; # helper var to remember if the select tag has the multiple attr set or not } else { $self->{selectMultiple} = 0; $self->{selectSelected} = 0; # helper var to remember if an option was already selected in the current select tag } # need to re-output the sub end { my ($self, $tagname, $origtext) = @_; if ($self->{option_no_value}) { $self->{output} .= '>'; delete $self->{option_no_value}; } if($tagname eq 'select'){ delete $self->{selectName}; } elsif ($tagname eq 'textarea'){ delete $self->{outputText}; } elsif ($tagname eq 'form') { delete $self->{'current_form'}; } $self->{output} .= $origtext; } sub __escapeHTML { my ($toencode) = @_; return undef unless defined($toencode); $toencode =~ s/&/&/g; $toencode =~ s/\"/"/g; $toencode =~ s/>/>/g; $toencode =~ s/{output} .= ''; } else { $self->{output} .= ''; } } sub process { my ( $self, $token0, $text ) = @_; $self->{output} .= $text; } sub declaration { my ( $self, $text ) = @_; $self->{output} .= ''; } 1; __END__ =head1 NAME HTML::FillInForm - Populates HTML Forms with data. =head1 DESCRIPTION This module fills in an HTML form with data from a Perl data structure, allowing you to keep the HTML and Perl separate. Here are two common use cases: 1. A user submits an HTML form without filling out a required field. You want to redisplay the form with all the previous data in it, to make it easy for the user to see and correct the error. 2. You have just retrieved a record from a database and need to display it in an HTML form. =head1 SYNOPSIS Fill HTML form with data. $output = HTML::FillInForm->fill( \$html, $q ); $output = HTML::FillInForm->fill( \@html, [$q1,$q2] ); $output = HTML::FillInForm->fill( \*HTML, \%data ); $output = HTML::FillInForm->fill( 't.html', [\%data1,%data2] ); The HTML can be provided as a scalarref, arrayref, filehandle or file. The data can come from one or more hashrefs, or objects which support a param() method, like CGI.pm, L, etc. =head1 fill The basic syntax is seen above the Synopsis. There are a few additional options. =head2 Options =head3 target => 'form1' Suppose you have multiple forms in a html file and only want to fill in one. $output = HTML::FillInForm->fill(\$html, $q, target => 'form1'); This will fill in only the form inside
...
=head3 fill_password => 0 Passwords are filled in by default. To disable: fill_password => 0 =head3 ignore_fields => [] To disable the filling of some fields: ignore_fields => ['prev','next'] =head3 disable_fields => [] To disable fields from being edited: disable_fields => [ 'uid', 'gid' ] =head3 invalid_fields => [] To mark fields as being invalid (CSS class set to "invalid" or whatever you set invalid_class to): invalid_fields => [ 'uid', 'gid' ] =head3 invalid_class => "invalid" The CSS class which will be used to mark fields invalid. Defaults to "invalid". =head3 clear_absent_checkboxes => 0 Absent fields are not cleared or in any way changed. This is not what you want when you deal with checkboxes which are not sent by browser at all when cleared by user. To remove "checked" attribute from checkboxes and radio buttons and attribute "selected" from options of select lists for which there's no data: clear_absent_checkboxes => 1 =head2 File Upload fields File upload fields cannot be supported directly. Workarounds include asking the user to re-attach any file uploads or fancy server-side storage and referencing. You are on your own. =head2 Clearing Fields Fields are cleared if you set their value to an empty string or empty arrayref but not undef: # this will leave the form element foo untouched HTML::FillInForm->fill(\$html, { foo => undef }); # this will set clear the form element foo HTML::FillInForm->fill(\$html, { foo => "" }); It has been suggested to add a option to change the behavior so that undef values will clear the form elements. Patches welcome. You can also use C option to clear checkboxes, radio buttons and selects without corresponding keys in the data: # this will set clear the form element foo (and all others except # bar) HTML::FillInForm->fill(\$html, { bar => 123 }, clear_absent_checkboxes => 1); =head1 Old syntax You probably need to read no further. The remaining docs concern the 1.x era syntax, which is still supported. =head2 new Call C to create a new FillInForm object: $fif = HTML::FillInForm->new; $fif->fill(...); In theory, there is a slight performance benefit to calling C before C if you make multiple calls to C before you destroy the object. Benchmark before optimizing. =head2 fill ( old syntax ) Instead of having your HTML and data types auto-detected, you can declare them explicitly in your call to C: HTML source options: arrayref => @html scalarref => $html file => \*HTML file => 't.html' Fill Data options: fobject => $data_obj # with param() method fdat => \%data Additional methods are also available: fill_file(\*HTML,...); fill_file('t.html',...); fill_arrayref(\@html,...); fill_scalarref(\$html,...); =head1 USING AN ALTERNATE PARSER It's possible to use an alternate parser to L if the alternate provides a sufficiently compatible interface. For example, when a Pure Perl implementation of HTML::Parser appears, it could be used for portability. The syntax is simply to provide a C to new(); HTML::FillInForm->new( parser_class => 'MyAlternate::Parser' ); =head1 CALLING FROM OTHER MODULES =head2 Apache::PageKit To use HTML::FillInForm in L is easy. It is automatically called for any page that includes a
tag. It can be turned on or off by using the C configuration option. =head2 Apache::ASP v2.09 and above HTML::FillInForm is now integrated with Apache::ASP. To activate, use PerlSetVar FormFill 1 $Response->{FormFill} = 1 =head2 HTML::Mason Using HTML::FillInForm from HTML::Mason is covered in the FAQ on the masonhq.com website at L =head1 VERSION This documentation describes HTML::FillInForm module version 2.1 =head1 SECURITY Note that you might want to think about caching issues if you have password fields on your page. There is a discussion of this issue at http://www.perlmonks.org/index.pl?node_id=70482 In summary, some browsers will cache the output of CGI scripts, and you can control this by setting the Expires header. For example, use C<-expires> in L or set C to I in Config.xml file of L. =head1 TRANSLATION Kato Atsushi has translated these docs into Japanese, available from http://perldoc.jp =head1 BUGS Please submit any bug reports to tjmather@maxmind.com. =head1 NOTES Requires Perl 5.005 and L version 3.26. I wrote this module because I wanted to be able to insert CGI data into HTML forms, but without combining the HTML and Perl code. CGI.pm and Embperl allow you so insert CGI data into forms, but require that you mix HTML with Perl. There is a nice review of the module available here: L =head1 AUTHOR (c) 2011 TJ Mather, tjmather@maxmind.com, L All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L, L, L, L =head1 CREDITS Fixes, Bug Reports, Docs have been generously provided by: Alex Kapranoff Miika Pekkarinen Michael Fisher Sam Tregar Tatsuhiko Miyagawa Joseph Yanni Boris Zentner Philip Mak Dave Rolsky Jost Krieger Patrick Michael Kane Gabriel Burka Ade Olonoh Bill Moseley Tom Lancaster James Tolley Martin H Sluka Dan Kubb Mark Stosberg Alexander Hartmaier Jonathan Swartz Paul Miller Trevor Schellhorn Anthony Ettinger Jim Miner Simon P. Ditner Paul Lindner Michael Peters Maurice Aubrey Trevor Schellhorn Andrew Creer Thanks! HTML-FillInForm-2.21/META.yml0000664000175100017510000000065012373152053014126 0ustar markmark--- abstract: unknown author: - unknown build_requires: {} dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.120921' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: HTML-FillInForm no_index: directory: - t - inc resources: repository: https://github.com/markstos/HTML-FillInForm.git version: 2.21 HTML-FillInForm-2.21/META.json0000664000175100017510000000132112373152053014272 0ustar markmark{ "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.120921", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "HTML-FillInForm", "no_index" : { "directory" : [ "t", "inc" ] }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "url" : "https://github.com/markstos/HTML-FillInForm.git", "web" : "https://github.com/markstos/HTML-FillInForm" } }, "version" : "2.21" } HTML-FillInForm-2.21/t/0000755000175100017510000000000012373152053013115 5ustar markmarkHTML-FillInForm-2.21/t/09_default_type.t0000644000175100017510000000110312373151675016303 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..2\n"; use HTML::FillInForm; print "ok 1\n"; my $hidden_form_in = qq{ }; my %fdat = (foo1 => 'bar1', foo2 => 'bar2'); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat); if ($output =~ m/^\s*$/){ print "ok 2\n"; } else { print "Got unexpected out for $hidden_form_in:\n$output\n"; print "not ok 2\n"; } HTML-FillInForm-2.21/t/06_radio.t0000644000175100017510000000142212373151675014715 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..2\n"; use HTML::FillInForm; print "ok 1\n"; my $hidden_form_in = qq{ }; my %fdat = (foo1 => 'bar2'); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat); my $is_checked = join(" ",map { m/checked/ ? "yes" : "no" } split ("\n",$output)); if ($is_checked eq 'no yes no no no yes'){ print "ok 2\n"; } else { print "Got unexpected is_checked:\n$is_checked\n"; print "not ok 2\n"; } HTML-FillInForm-2.21/t/16_ignore_fields.t0000644000175100017510000000245012373151675016433 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..2\n"; use HTML::FillInForm; use CGI; print "ok 1\n"; my $hidden_form_in = qq{ }; my $q = new CGI( { foo1 => '0', foo2 => ['bar1', 'bar2',], foo3 => '' } ); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fobject => $q, ignore_fields => ['asdf','foo1','asdf']); my $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output)); if ($is_selected eq "no no no yes yes no no no no no yes no"){ print "ok 2\n"; } else { print "Got unexpected is_selected for select menus:\n$is_selected\n$output\n"; print "not ok 2\n"; } HTML-FillInForm-2.21/t/00_base.t0000644000175100017510000000011612373151675014522 0ustar markmark BEGIN { print "1..1\n"; } use HTML::FillInForm; BEGIN { print "ok 1\n"; } HTML-FillInForm-2.21/t/17_xhtml.t0000644000175100017510000000170312373151675014757 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..1\n"; use HTML::FillInForm; use CGI; my $html = < Canceled
Confirmed
Wait List
No Show
Moved to Another Class
Late Cancel
EOF my $q = CGI->new; $q->param('status', 1 ); my $fif = HTML::FillInForm->new; my $output = $fif->fill( scalarref => \$html, fobject => $q ); my $matches; while ($output =~ m!( />)!g) { $matches++; } if ($matches == 6) { print "ok 1\n"; } else { print "not ok 1\n"; } print $output; HTML-FillInForm-2.21/t/07_reuse.t0000644000175100017510000000124312373151675014744 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..2\n"; use HTML::FillInForm; print "ok 1\n"; my $hidden_form_in = qq{ }; my %fdat = (foo1 => ['bar1'], foo2 => 'bar2'); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat); my $output2 = $fif->fill(scalarref => \$output, fdat => \%fdat); if ($output2 =~ m/^\s*$/){ print "ok 2\n"; } else { print "Got unexpected out for $hidden_form_in:\n$output2\n"; print "not ok 2\n"; } HTML-FillInForm-2.21/t/01_form.t0000644000175100017510000000115512373151675014560 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..2\n"; use HTML::FillInForm; print "ok 1\n"; my $hidden_form_in = qq{ }; my %fdat = (foo1 => 'bar1', foo2 => '"bar2"'); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat); if ($output =~ m/^\s*$/){ print "ok 2\n"; } else { print "Got unexpected out for $hidden_form_in:\n$output\n"; print "not ok 2\n"; } HTML-FillInForm-2.21/t/02_hidden.t0000644000175100017510000000114112373151675015044 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..2\n"; use HTML::FillInForm; print "ok 1\n"; my $hidden_form_in = qq{ }; my %fdat = (foo1a => 'bar1a', foo2 => ['bar2','bar3']); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat); if ($output =~ m/^\s*$/){ print "ok 2\n"; } else { print "Got unexpected out for hidden form:\n$output\n"; print "not ok 2\n"; } HTML-FillInForm-2.21/t/15_multiple_fields.t0000644000175100017510000000110612373151675016777 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..2\n"; use HTML::FillInForm; print "ok 1\n"; my $hidden_form_in = qq{ }; my %fdat = (foo => 'bar1a'); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat); if ($output =~ m/^\s*$/){ print "ok 2\n"; } else { print "Got unexpected out for hidden form:\n$output\n"; print "not ok 2\n"; } HTML-FillInForm-2.21/t/12_mult.t0000644000175100017510000000166312373151675014604 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..3\n"; use HTML::FillInForm; print "ok 1\n"; my $hidden_form_in = qq{ }; my %fdat = (foo1 => ['bar1','bar2']); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat); if ($output =~ m/^\s*$/){ print "ok 2\n"; } else { print "Got unexpected out for $hidden_form_in:\n$output\n"; print "not ok 2\n"; } %fdat = (foo1 => ['bar1']); $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat); if ($output =~ m/^\s*$/){ print "ok 3\n"; } else { print "Got unexpected out for $hidden_form_in:\n$output\n"; print "not ok 3\n"; } HTML-FillInForm-2.21/t/19_extra.t0000644000175100017510000001773612373151675014765 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; #An object without a "param" method package Support::Object; sub new{ my ($proto) = @_; my $self = {}; bless $self, $proto; return $self; } ### #End of Support::Object use Test::More tests => 38; use_ok('HTML::FillInForm'); my $html = qq[ ]; my $result = HTML::FillInForm->new->fill_scalarref( \$html, fdat => { two => "new val 2", three => "new val 3", }, ignore_fields => 'one', ); ok($result =~ /not disturbed/ && $result =~/\bone/,'scalar value of ignore_fields'); ok($result =~ /new val 2/ && $result =~ /two/,'fill_scalarref worked'); ok($result =~ /new val 3/ && $result =~ /three/,'fill_scalarref worked 2'); $html = qq[
]; my @html_array = split /\n/, $html; { $result = HTML::FillInForm->new->fill_arrayref( \@html_array, fdat => { one => "new val 1", two => "new val 2", }, ); ok($result =~ /new val 1/ && $result =~ /\bone/, 'fill_arrayref 1'); ok($result =~ /new val 2/ && $result =~ /\btwo/, 'fill_arrayref 2'); } { $result = HTML::FillInForm->fill( \@html_array, { one => "new val 1", two => "new val 2", }, ); ok($result =~ /new val 1/ && $result =~ /\bone/, 'fill_arrayref 1'); ok($result =~ /new val 2/ && $result =~ /\btwo/, 'fill_arrayref 2'); } { $result = HTML::FillInForm->new->fill_file( "t/data/form1.html", fdat => { one => "new val 1", two => "new val 2", three => "new val 3", }, ); ok($result =~ /new val 1/ && $result =~ /\bone/,'fill_file 1'); ok($result =~ /new val 2/ && $result =~ /\btwo/,'fill_file 2'); ok($result =~ /new val 3/ && $result =~ /\bthree/,'fill_file 3'); } { $result = HTML::FillInForm->fill( "t/data/form1.html", { one => "new val 1", two => "new val 2", three => "new val 3", }, ); ok($result =~ /new val 1/ && $result =~ /\bone/,'fill_file 1'); ok($result =~ /new val 2/ && $result =~ /\btwo/,'fill_file 2'); ok($result =~ /new val 3/ && $result =~ /\bthree/,'fill_file 3'); } { my $fh = open FH, "fill( \*FH, { one => "new val 1", two => "new val 2", three => "new val 3", }, ); ok($result =~ /new val 1/ && $result =~ /\bone/,'fill_file 1'); ok($result =~ /new val 2/ && $result =~ /\btwo/,'fill_file 2'); ok($result =~ /new val 3/ && $result =~ /\bthree/,'fill_file 3'); close(\*FH); } $html = qq[
]; eval{ $result = HTML::FillInForm->new->fill_scalarref( \$html ); }; $result = HTML::FillInForm->new->fill( fdat => {} ); #No meaningful arguments - should not this produce an error? $html = qq[
]; my $fobject = new Support::Object; eval{ $result = HTML::FillInForm->new->fill_scalarref( $html, fobject => $fobject ); }; like($@, qr/HTML::FillInForm->fill called with fobject option, containing object of type Support::Object which lacks a param\(\) method!/, "bad fobject parameter"); $html = qq{ }; my %fdat = (foo1 => 'bar2'); $result = HTML::FillInForm->new->fill(scalarref => \$html, fdat => \%fdat); ok($result =~ /on/ && $result =~ /\bfoo1/,'defaulting radio buttons to on'); $html = qq{ }; %fdat = (foo1 => ['bar2', 'bar3']); $result = HTML::FillInForm->new->fill(scalarref => \$html, fdat => \%fdat); ok($result =~ /bar2/ && $result =~ /\bfoo1/,'first array element taken for password fields'); $html = qq{ }; %fdat = (foo1 => ['bar2', 'bar3']); $result = HTML::FillInForm->new->fill(scalarref => \$html, fdat => \%fdat); my $is_checked = join(" ",map { m/checked/ ? "yes" : "no" } split ("\n",$result)); ok($is_checked eq "yes no",'first array element taken for radio buttons'); $html = qq{}; %fdat = (area => 'foo1'); $result = HTML::FillInForm->new->fill(scalarref => \$html, fdat => \%fdat); ok($result !~ /foo1/,'textarea with no name'); $html = qq{}; %fdat = (foo1 => ['bar2', 'bar3']); $result = HTML::FillInForm->new->fill(scalarref => \$html, fdat => \%fdat); ok($result eq '','first array element taken for textareas'); $html = qq{ }; %fdat = (foo1 => [undef, 'bar1'], foo2 => [undef, 'bar2'], foo3 => [undef, 'bar3']); $result = HTML::FillInForm->new->fill(scalarref => \$html, fdat => \%fdat); ok($result !~ m/checked/, "Empty radio button value"); like($result, qr##, "Empty textarea"); like($result, qr//, "Empty password field value"); $html = qq[
]; %fdat = (foo0 => 'bar1', foo1 => 'bar2'); $result = HTML::FillInForm->new->fill(scalarref => \$html, fdat => \%fdat); ok($result =~ /bar1/ and $result =~ /\bfoo0/,'form with comments 1'); like($result, qr'','form with comments 2'); like($result, qr'','Comment 1'); like($result, qr'','Comment 2'); like($result, qr'','Comment 3'); like($result, qr'','Comment 4'); $html = qq[
]; %fdat = (foo0 => 'bar1', foo1 => 'bar2'); $result = HTML::FillInForm->new->fill(scalarref => \$html, fdat => \%fdat); ok($result =~ /bar1/ && $result =~ /\bfoo0/,'form with processing 1'); like($result, qr'','form with processing 2'); like($result, qr'<\? HTML processing instructions 1 \?>','processing 1'); like($result, qr'<\? XML processing instructions 2\?>','processing 2'); like($result, qr'<\? HTML processing instructions\n\n3>','processing 3'); like($result, qr'<\?HTML processing instructions 4 >','processing 4'); HTML-FillInForm-2.21/t/data/0000755000175100017510000000000012373152053014026 5ustar markmarkHTML-FillInForm-2.21/t/data/form1.html0000644000175100017510000000026012373151675015747 0ustar markmark
HTML-FillInForm-2.21/t/21_disable_fields.t0000644000175100017510000000170712373151675016553 0ustar markmark#!/usr/local/bin/perl # contributed by Trevor Schellhorn use strict; use warnings FATAL => 'all'; use Test::More tests => 5; use_ok('HTML::FillInForm'); my $html = qq[
]; my $result = HTML::FillInForm->new->fill( scalarref => \$html, fdat => { two => "new val 2", }, disable_fields => [qw(two)], ); ok($result =~ /not disturbed/ && $result =~ /\bone/,'don\'t disable 1'); ok($result =~ /new val 2/ && $result =~ /\btwo/ && $result =~ /disabled="disabled"/,'disable 2'); $result = HTML::FillInForm->new->fill( scalarref => \$html, fdat => { two => "new val 2", }, disable_fields => 'two', ); ok($result =~ /not disturbed/ && $result =~ /\bone/,'don\'t disable 1'); ok($result =~ /new val 2/ && $result =~ /\btwo/ && $result =~ /disabled="disabled"/,'disable 2'); HTML-FillInForm-2.21/t/23_absent_checkbox.t0000644000175100017510000000276212373151675016750 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..2\n"; use HTML::FillInForm; print "ok 1\n"; my $hidden_form_in = qq{ }; my %fdat = (foo1 => 'bar1', foo2 => ['bar1', 'bar2',], foo3 => '', foo5 => 'on', foo6 => '', foo7 => 'on', foo8 => ''); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat, clear_absent_checkboxes => 1); my $is_checked = join(" ",map { m/checked/ ? "yes" : "no" } split ("\n",$output)); if ($is_checked eq "yes no no yes yes no no no no no no no yes no yes no"){ print "ok 2\n"; } else { print "Got unexpected is_checked for checkboxes:\n$is_checked\n"; print "not ok 2\n"; } HTML-FillInForm-2.21/t/26_invalid_fields.t0000644000175100017510000000463712373151675016610 0ustar markmark#!/usr/local/bin/perl use strict; use warnings; use Test::More; use HTML::FillInForm; use HTML::TokeParser; my $html = qq[
]; { my $result = HTML::FillInForm->new->fill(scalarref => \$html, fdat => {two => "new val 2"}, invalid_fields => ['one']); my $p = HTML::TokeParser->new(\$result); my $one = $p->get_tag('input')->[1]; is($one->{name}, 'one'); is($one->{class}, 'invalid'); my $two = $p->get_token->[2]; is($two->{name}, 'two'); isnt($two->{class},'invalid'); } { my $result = HTML::FillInForm->new->fill(scalarref => \$html, fdat => {two => "new val 2"}, invalid_fields => ['one', 'two', 'three', 'four', 'five']); my $p = HTML::TokeParser->new(\$result); my $one = $p->get_tag('input')->[1]; is($one->{name}, 'one'); is($one->{class}, 'invalid'); my $two = $p->get_token->[2]; is($two->{name}, 'two'); is($two->{class},'existing invalid'); my $three = $p->get_token->[2]; is($three->{name},'three'); is($three->{class},'invalid'); my $four = $p->get_token->[2]; is($four->{name}, 'four'); is($four->{class}, 'invalid'); my $five = $p->get_tag('textarea')->[1]; is($five->{name},'five'); is($five->{class},'invalid'); } { my $result = HTML::FillInForm->new->fill(scalarref => \$html, fdat => {two => "new val 2"}, invalid_fields => ['one', 'three'], invalid_class => "funky"); my $p = HTML::TokeParser->new(\$result); my $one = $p->get_tag('input')->[1]; is($one->{name}, 'one'); is($one->{class}, 'funky'); my $two = $p->get_token->[2]; is($two->{name}, 'two'); is($two->{class},'existing'); my $three = $p->get_token->[2]; is($three->{name},'three'); is($three->{class},'invalid funky'); } done_testing(); HTML-FillInForm-2.21/t/11_target.t0000644000175100017510000000160312373151675015102 0ustar markmark# -*- Mode: Perl; -*- use strict; use Test; BEGIN { plan tests => 8 } use HTML::FillInForm; my $form = <
EOF ; my %fdat = ( foo1 => 'bar1', foo2 => 'bar2', foo3 => 'bar3', foo4 => 'bar4', ); my $output = HTML::FillInForm->fill( \$form, \%fdat, target => 'foo2', ); my @v = $output =~ m/fill( \$form, \%fdat, target => 'foo4', ); my @v2 = $output2 =~ m/blah}; my %fdat = (foo => 'bar>bar'); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat); if ($output eq ''){ print "ok 2\n"; } else { print "Got unexpected out for $hidden_form_in:\n$output\n"; print "not ok 2\n"; } # empty fdat test %fdat = (foo => ''); $fif = new HTML::FillInForm; $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat); if ($output eq ''){ print "ok 3\n"; } else { print "Got unexpected out for $hidden_form_in:\n$output\n"; print "not ok 3\n"; } HTML-FillInForm-2.21/t/03_checkbox.t0000644000175100017510000000267512373151675015415 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..2\n"; use HTML::FillInForm; print "ok 1\n"; my $hidden_form_in = qq{ }; my %fdat = (foo1 => 'bar1', foo2 => ['bar1', 'bar2',], foo3 => '', foo5 => 'on', foo6 => '', foo7 => 'on', foo8 => ''); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat); my $is_checked = join(" ",map { m/checked/ ? "yes" : "no" } split ("\n",$output)); if ($is_checked eq "yes no no yes yes no no no no no yes no yes no yes no"){ print "ok 2\n"; } else { print "Got unexpected is_checked for checkboxes:\n$is_checked\n"; print "not ok 2\n"; } HTML-FillInForm-2.21/t/25_select_absent_checkboxes.t0000644000175100017510000000723512373151675020641 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..6\n"; use HTML::FillInForm; use CGI; print "ok 1\n"; my $hidden_form_in = qq{ }; my $q = new CGI( { foo1 => '0', foo2 => ['bar1', 'bar2',], foo3 => '' } ); my $output = HTML::FillInForm->fill(\$hidden_form_in, $q, clear_absent_checkboxes => 1); my $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output)); if ($is_selected eq "yes no no yes yes no no no no no no no"){ print "ok 2\n$output\n"; } else { print "Got unexpected is_seleced for select menus:\n$is_selected\n$output\n"; print "not ok 2\n"; } $hidden_form_in = qq{ }; $q = new CGI( { foo1 => 'bar1', foo2 => ['bar1', 'bar2',], foo3 => '' } ); my $fif = new HTML::FillInForm; $output = $fif->fill(scalarref => \$hidden_form_in, fobject => $q, clear_absent_checkboxes => 1 ); $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output)); if ($is_selected eq "yes no no yes yes no no no no no no no"){ print "ok 3\n"; } else { print "Got unexpected is_selected for select menus:\n$is_selected\n$output\n"; print "not ok 3\n"; } # test empty option tag $hidden_form_in = qq{}; $fif = new HTML::FillInForm; $output = $fif->fill(scalarref => \$hidden_form_in, fobject => $q); if ($output eq qq{}){ print "ok 4\n"; } else { print "Got unexpected output for empty option:\n$output\n"; print "not ok 4\n"; } $hidden_form_in = qq{}; $fif = new HTML::FillInForm; $output = $fif->fill(scalarref => \$hidden_form_in, fobject => $q, clear_absent_checkboxes => 1); if ($output =~ m!^$!){ print "ok 5\n"; } else { print "Got unexpected output for empty option:\n$output\n"; print "not ok 5\n"; } $hidden_form_in = qq{}; $fif = new HTML::FillInForm; $output = $fif->fill(scalarref => \$hidden_form_in, fobject => $q, clear_absent_checkboxes => 1); if ($output eq ''){ print "ok 6\n"; } else { print "Got unexpected output for empty option:\n$output\n"; print "not ok 6\n"; } HTML-FillInForm-2.21/t/18_ignore_fdat.t0000644000175100017510000000134512373151675016107 0ustar markmark#!/usr/local/bin/perl # contributed by James Tolley use strict; use warnings FATAL => 'all'; use Test::More tests => 4; use_ok('HTML::FillInForm'); my $html = qq[
]; my $result = HTML::FillInForm->new->fill( scalarref => \$html, fdat => { two => "new val 2", three => "new val 3", }, ignore_fields => [qw(one two)], ); ok($result =~ /not disturbed/ && $result =~ /\bone/,'ignore 1'); ok($result =~ /not disturbed/ && $result =~ /\btwo/,'ignore 2'); ok($result =~ /new val 3/ && $result =~ /\bthree/,'ignore 3'); HTML-FillInForm-2.21/t/22_undef.t0000644000175100017510000000517612373151675014730 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; use Test::More; unless ( eval "use Test::Output; 1" ) { plan skip_all => 'These tests require Test::Output'; } plan tests => 10; use_ok('HTML::FillInForm'); { my $html = qq[
]; stderr_is( sub { fill( $html, undef ) }, '', 'no warnings with undef value for input' ); } { my $html = qq[
]; stderr_is( sub { fill( $html, undef ) }, '', 'no warnings with undef value for textarea' ); } { my $html = qq[
]; stderr_is( sub { fill( $html, undef ) }, '', 'no warnings with undef value for select' ); } { my $html = qq[
]; stderr_is( sub { fill( $html, [] ) }, '', 'no warnings with empty array value for select' ); } { my $html = qq[
]; stderr_is( sub { fill( $html, [ undef ] ) }, '', 'no warnings with array containing undef for select' ); } { my $html = qq[
]; stderr_is( sub { fill( $html, undef ) }, '', 'no warnings with undef for multi select' ); } { my $html = qq[
]; stderr_is( sub { fill( $html, [] ) }, '', 'no warnings with empty array for multi select' ); } { my $html = qq[
]; stderr_is( sub { fill( $html, [ undef ] ) }, '', 'no warnings with array containing undef for multi select' ); } { my $html = qq[
]; stderr_is( sub { fill( $html, [ 1, undef ] ) }, '', 'no warnings with array containing undef as second value for multi select' ); } sub fill { my $html = shift; my $val = shift; HTML::FillInForm->new->fill_scalarref( \$html, fdat => { one => $val, }, ); } HTML-FillInForm-2.21/t/20_scalarref.t0000644000175100017510000000101512373151675015553 0ustar markmarkuse strict; use warnings; use Test::More; use HTML::FillInForm; # a few strings to test against my @contents = ( q{404}, q{404 Not Found}, q{Hello World}, q{Hello World}, ); # our number of tests in the number of elements in @contents plan tests => (scalar @contents); # run each string through H::FIF foreach my $content (@contents) { my $output = HTML::FillInForm->fill( \$content, fdat => {}); is($output, $content, q{output and content should be the same}); } HTML-FillInForm-2.21/t/08_multiple_objects.t0000644000175100017510000000127212373151675017170 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..2\n"; use HTML::FillInForm; use CGI; print "ok 1\n"; my $hidden_form_in = qq{ }; my %fdat = (foo1 => 'bar1', foo2 => 'bar2'); my $q1 = new CGI( { foo1 => 'bar1' }); my $q2 = new CGI( { foo2 => 'bar2' }); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fobject => [$q1, $q2]); if ($output =~ m/^\s*$/){ print "ok 2\n"; } else { print "Got unexpected out for $hidden_form_in:\n$output\n"; print "not ok 2\n"; } HTML-FillInForm-2.21/t/13_warning.t0000644000175100017510000000075512373151675015272 0ustar markmark# -*- Mode: Perl; -*- #!/usr/bin/perl -w # emits warnings for HTML::FIF <= 0.22 use CGI qw(:no_debug); use HTML::FillInForm; use Test; BEGIN { plan tests => 1 } local $/; my $html = qq{}; my $q = new CGI; $q->param( "name", "John Smith" ); my $fif = new HTML::FillInForm; my $output = $fif->fill( scalarref => \$html, fobject => $q ); ok($html =~ m!!); HTML-FillInForm-2.21/t/10_escape.t0000644000175100017510000000211112373151675015046 0ustar markmark# -*- Mode: Perl; -*- use Test::More 'no_plan'; use strict; use HTML::FillInForm; my $html =<<"__HTML__";

test
test
test

__HTML__ my %fdat = (); my $output = HTML::FillInForm->fill( \$html, \%fdat); # FIF changes order of HTML attributes, so split strings and sort my $strings_output = join("\n", sort split(/[\s><]+/, lc($output))); my $strings_html = join("\n", sort split(/[\s><]+/, lc($html))); is($strings_output,$strings_html); HTML-FillInForm-2.21/t/04_select.t0000644000175100017510000000575412373151675015110 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..5\n"; use HTML::FillInForm; use CGI; print "ok 1\n"; my $hidden_form_in = qq{ }; my $q = new CGI( { foo1 => '0', foo2 => ['bar1', 'bar2',], foo3 => '' } ); my $output = HTML::FillInForm->fill(\$hidden_form_in, $q); my $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output)); if ($is_selected eq "yes no no yes yes no no no no no yes no"){ print "ok 2\n$output\n"; } else { print "Got unexpected is_seleced for select menus:\n$is_selected\n$output\n"; print "not ok 2\n"; } $hidden_form_in = qq{ }; $q = new CGI( { foo1 => 'bar1', foo2 => ['bar1', 'bar2',], foo3 => '' } ); my $fif = new HTML::FillInForm; $output = $fif->fill(scalarref => \$hidden_form_in, fobject => $q); $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output)); if ($is_selected eq "yes no no yes yes no no no no no yes no"){ print "ok 3\n"; } else { print "Got unexpected is_selected for select menus:\n$is_selected\n$output\n"; print "not ok 3\n"; } # test empty option tag $hidden_form_in = qq{}; $fif = new HTML::FillInForm; $output = $fif->fill(scalarref => \$hidden_form_in, fobject => $q); if ($output eq qq{}){ print "ok 4\n"; } else { print "Got unexpected output for empty option:\n$output\n"; print "not ok 4\n"; } $hidden_form_in = qq{}; $fif = new HTML::FillInForm; $output = $fif->fill(scalarref => \$hidden_form_in, fobject => $q); if ($output =~ m!^$!){ print "ok 5\n"; } else { print "Got unexpected output for empty option:\n$output\n"; print "not ok 5\n"; } HTML-FillInForm-2.21/t/14_password.t0000644000175100017510000000110512373151675015456 0ustar markmark# -*- Mode: Perl; -*- #!/usr/bin/perl -w use CGI qw(:no_debug); use HTML::FillInForm; use Test; BEGIN { plan tests => 2 } local $/; my $html = qq{}; my $q = new CGI; $q->param( foo => 'bar' ); { my $fif = new HTML::FillInForm; my $output = $fif->fill( scalarref => \$html, fobject => $q, fill_password => 0, ); ok($output !~ /value="bar"/); } { my $fif = new HTML::FillInForm; my $output = $fif->fill( scalarref => \$html, fobject => $q, # fill_password => 1, ); ok($output =~ /value="bar"/); } HTML-FillInForm-2.21/t/24_radio_absent_checkboxes.t0000644000175100017510000000150712373151675020453 0ustar markmark# -*- Mode: Perl; -*- use strict; $^W = 1; print "1..2\n"; use HTML::FillInForm; print "ok 1\n"; my $hidden_form_in = qq{ }; my %fdat = (foo1 => 'bar2'); my $fif = new HTML::FillInForm; my $output = $fif->fill(scalarref => \$hidden_form_in, fdat => \%fdat, clear_absent_checkboxes => 1); my $is_checked = join(" ",map { m/checked/ ? "yes" : "no" } split ("\n",$output)); if ($is_checked eq 'no yes no no no no'){ print "ok 2\n"; } else { print "Got unexpected is_checked:\n$is_checked\n"; print "not ok 2\n"; } HTML-FillInForm-2.21/Makefile.PL0000644000175100017510000000132612373151675014637 0ustar markmarkuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'HTML::FillInForm', 'VERSION_FROM' => 'lib/HTML/FillInForm.pm', # finds $VERSION 'PREREQ_PM' => { HTML::Parser => 3.26, HTML::TokeParser => 3.26, warnings => 0 }, TEST_REQUIRES => { CGI => 0 }, META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', url => 'https://github.com/markstos/HTML-FillInForm.git', web => 'https://github.com/markstos/HTML-FillInForm', }, }, }, );