r792 - in packages: . libhtml-fillinform-perl
libhtml-fillinform-perl/branches
libhtml-fillinform-perl/branches/upstream
libhtml-fillinform-perl/branches/upstream/current
libhtml-fillinform-perl/branches/upstream/current/lib
libhtml-fillinform-perl/branches/upstream/current/lib/HTML
libhtml-fillinform-perl/branches/upstream/current/t
libhtml-fillinform-perl/branches/upstream/current/t/data
Gunnar Wolf
gwolf at costa.debian.org
Sun Jul 17 08:08:58 UTC 2005
Author: gwolf
Date: 2005-03-15 19:59:53 +0100 (Tue, 15 Mar 2005)
New Revision: 792
Added:
packages/libhtml-fillinform-perl/
packages/libhtml-fillinform-perl/branches/
packages/libhtml-fillinform-perl/branches/upstream/
packages/libhtml-fillinform-perl/branches/upstream/current/
packages/libhtml-fillinform-perl/branches/upstream/current/Changes
packages/libhtml-fillinform-perl/branches/upstream/current/MANIFEST
packages/libhtml-fillinform-perl/branches/upstream/current/META.yml
packages/libhtml-fillinform-perl/branches/upstream/current/Makefile.PL
packages/libhtml-fillinform-perl/branches/upstream/current/README
packages/libhtml-fillinform-perl/branches/upstream/current/lib/
packages/libhtml-fillinform-perl/branches/upstream/current/lib/HTML/
packages/libhtml-fillinform-perl/branches/upstream/current/lib/HTML/FillInForm.pm
packages/libhtml-fillinform-perl/branches/upstream/current/t/
packages/libhtml-fillinform-perl/branches/upstream/current/t/00_base.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/01_form.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/02_hidden.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/03_checkbox.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/04_select.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/05_textarea.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/06_radio.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/07_reuse.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/08_multiple_objects.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/09_default_type.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/10_escape.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/11_target.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/12_mult.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/13_warning.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/14_password.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/15_multiple_fields.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/16_ignore_fields.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/17_xhtml.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/18_ignore_fdat.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/19_extra.t
packages/libhtml-fillinform-perl/branches/upstream/current/t/data/
packages/libhtml-fillinform-perl/branches/upstream/current/t/data/form1.html
packages/libhtml-fillinform-perl/tags/
Log:
[svn-inject] Installing original source of libhtml-fillinform-perl
Added: packages/libhtml-fillinform-perl/branches/upstream/current/Changes
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/Changes 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/Changes 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,187 @@
+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 <input .. /> (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 <input ... /> 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. <select name="x"><option></select>)
+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 <input type="hidden" name="foo">
+is transformed to <input type="hidden" name="foo" value=""> 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.
Added: packages/libhtml-fillinform-perl/branches/upstream/current/MANIFEST
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/MANIFEST 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/MANIFEST 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,27 @@
+Changes
+MANIFEST
+Makefile.PL
+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/data/form1.html
+META.yml Module meta-data (added by MakeMaker)
Added: packages/libhtml-fillinform-perl/branches/upstream/current/META.yml
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/META.yml 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/META.yml 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,11 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
+name: HTML-FillInForm
+version: 1.05
+version_from: lib/HTML/FillInForm.pm
+installdirs: site
+requires:
+ HTML::Parser: 3.26
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17
Added: packages/libhtml-fillinform-perl/branches/upstream/current/Makefile.PL
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/Makefile.PL 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/Makefile.PL 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,8 @@
+use 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}, # e.g., Module::Name => 1.1
+);
Added: packages/libhtml-fillinform-perl/branches/upstream/current/README
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/README 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/README 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,22 @@
+This 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 Thomas J. Mather, tjmather at 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.
Added: packages/libhtml-fillinform-perl/branches/upstream/current/lib/HTML/FillInForm.pm
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/lib/HTML/FillInForm.pm 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/lib/HTML/FillInForm.pm 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,535 @@
+package 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 attr_encoded
+use HTML::Parser 3.26;
+
+# required for UNIVERSAL->can
+require 5.005;
+
+use vars qw($VERSION @ISA);
+$VERSION = '1.05';
+
+ at ISA = qw(HTML::Parser);
+
+sub new {
+ my ($class) = @_;
+ my $self = bless {}, $class;
+ $self->init;
+ # 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', at _); }
+sub fill_arrayref { my $self = shift; return $self->fill('arrayref', at _); }
+sub fill_scalarref { my $self = shift; return $self->fill('scalarref', at _); }
+
+sub fill {
+ my ($self, %option) = @_;
+
+ 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;
+
+ if (my $fdat = $option{fdat}){
+ # Copy the structure to prevent side-effects.
+ my %copy;
+ 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 (defined($option{fill_password})){
+ $self->{fill_password} = $option{fill_password};
+ } else {
+ $self->{fill_password} = 1;
+ }
+
+ # 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($_);
+ }
+ }
+ return delete $self->{output};
+}
+
+# handles opening HTML tags such as <input ...>
+sub start {
+ my ($self, $tagname, $attr, $attrseq, $origtext) = @_;
+
+ # set the current form
+ if ($tagname eq 'form') {
+ $self->{object_param_cache} = {};
+ if (exists $attr->{'name'}) {
+ $self->{'current_form'} = $attr->{'name'};
+ } else {
+ # in case of previous one without </FORM>
+ 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};
+ }
+ 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;
+ if (defined($value)){
+ $value = $self->escapeHTMLStringOrList($value);
+ # check for input type, noting that default type is text
+ if (!exists $attr->{'type'} ||
+ $attr->{'type'} =~ /^(text|textfield|hidden|)$/i){
+ $value = (shift @$value || '') if ref($value) eq 'ARRAY';
+ $attr->{'value'} = $value;
+ } elsif (lc $attr->{'type'} eq 'password' && $self->{fill_password}) {
+ $value = (shift @$value || '') if ref($value) eq 'ARRAY';
+ $attr->{'value'} = $value;
+ } elsif (lc $attr->{'type'} eq 'radio'){
+ $value = ($value->[0] || '') if ref($value) eq 'ARRAY';
+ # value for radio boxes default to 'on', works with netscape
+ $attr->{'value'} = 'on' unless exists $attr->{'value'};
+ if ($attr->{'value'} eq $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 $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});
+
+ if (defined($value)){
+ $value = $self->escapeHTMLStringOrList($value);
+ $value = [ $value ] unless ( ref($value) eq 'ARRAY' );
+ delete $attr->{selected} if exists $attr->{selected};
+
+ if(defined($attr->{'value'})){
+ # option tag has value attr - <OPTION VALUE="foo">bar</OPTION>
+ foreach my $v ( @$value ) {
+ if ( $attr->{'value'} eq $v ) {
+ $attr->{selected} = 'selected';
+ }
+ }
+ } else {
+ # option tag has no value attr - <OPTION>bar</OPTION>
+ # save for processing under text handler
+ $self->{option_no_value} = $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'){
+ if ($attr->{'name'} and defined (my $value = $self->_get_param($attr->{'name'}))){
+ $value = $self->escapeHTMLStringOrList($value);
+ $value = (shift @$value || '') if ref($value) eq 'ARRAY';
+ # <textarea> foobar </textarea> -> <textarea> $value </textarea>
+ # we need to set outputText to 'no' so that 'foobar' won't be printed
+ $self->{outputText} = 'no';
+ $self->{output} .= $origtext . $value;
+ } else {
+ $self->{output} .= $origtext;
+ }
+ } elsif ($tagname eq 'select'){
+ $self->{selectName} = $attr->{'name'};
+ $self->{output} .= $origtext;
+ } else {
+ $self->{output} .= $origtext;
+ }
+}
+
+sub _get_param {
+ my ($self, $param) = @_;
+
+ return undef if $self->{ignore_fields}{$param};
+
+ return $self->{fdat}{$param} if exists $self->{fdat}{$param};
+
+ return $self->{object_param_cache}{$param} if exists $self->{object_param_cache}{$param};
+
+ # traverse the list in reverse order for backwards compatibility
+ # with the previous implementation.
+ for my $o (reverse @{$self->{objects}}) {
+ my @v = $o->param($param);
+
+ next unless @v;
+
+ return $self->{object_param_cache}{$param} = @v > 1 ? \@v : $v[0];
+ }
+
+ return undef;
+}
+
+# handles non-html text
+sub text {
+ my ($self, $origtext) = @_;
+ # just output text, unless replaced value of <textarea> tag
+ unless(exists $self->{outputText} && $self->{outputText} eq 'no'){
+ if(exists $self->{option_no_value}){
+ # dealing with option tag with no value - <OPTION>bar</OPTION>
+ my $values = $self->{option_no_value};
+ my $value = $origtext;
+ $value =~ s/^\s+//;
+ $value =~ s/\s+$//;
+ foreach my $v ( @$values ) {
+ if ( $value eq $v ) {
+ $self->{output} .= ' selected="selected"';
+ }
+ }
+ # close <OPTION> tag
+ $self->{output} .= ">$origtext";
+ delete $self->{option_no_value};
+ } else {
+ $self->{output} .= $origtext;
+ }
+ }
+}
+
+# handles closing HTML tags such as </textarea>
+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 escapeHTMLStringOrList {
+ my ($self, $toencode) = @_;
+
+ if (ref($toencode) eq 'ARRAY') {
+ foreach my $elem (@$toencode) {
+ $elem = $self->escapeHTML($elem);
+ }
+ return $toencode;
+ } else {
+ return $self->escapeHTML($toencode);
+ }
+}
+
+sub escapeHTML {
+ my ($self, $toencode) = @_;
+
+ return undef unless defined($toencode);
+ $toencode =~ s/&/&/g;
+ $toencode =~ s/\"/"/g;
+ $toencode =~ s/>/>/g;
+ $toencode =~ s/</</g;
+ return $toencode;
+}
+
+sub comment {
+ my ( $self, $text ) = @_;
+ $self->{output} .= '<!--' . $text . '-->';
+}
+
+sub process {
+ my ( $self, $token0, $text ) = @_;
+ $self->{output} .= $text;
+}
+
+sub declaration {
+ my ( $self, $text ) = @_;
+ $self->{output} .= '<!' . $text . '>';
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+HTML::FillInForm - Populates HTML Forms with data.
+
+=head1 DESCRIPTION
+
+This module automatically inserts data from a previous HTML form into the HTML input, textarea,
+radio buttons, checkboxes and select tags.
+It is a subclass of L<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 a
+required field. HTML::FillInForm can be used to redisplay the HTML form
+with all the form elements containing the submitted info.
+
+=head1 SYNOPSIS
+
+This examples fills data into a HTML form stored in C<$htmlForm> from CGI parameters that are stored
+in C<$q>. For example, it will set the value of any "name" textfield to "John Smith".
+
+ my $q = new CGI;
+
+ $q->param("name","John Smith");
+
+ my $fif = new HTML::FillInForm;
+ my $output = $fif->fill(scalarref => \$html,
+ fobject => $q);
+
+Note CGI.pm is B<not> required - see using fdat below. Also you can use a CGI.pm-like object such as Apache::Request.
+
+=head1 METHODS
+
+=over 4
+
+=item new
+
+Call C<new()> to create a new FillInForm object:
+
+ $fif = new HTML::FillInForm;
+
+=item fill
+
+To fill in a HTML form contained in a scalar C<$html>:
+
+ $output = $fif->fill(scalarref => \$html,
+ fobject => $q);
+
+Returns filled in HTML form contained in C<$html> with data from C<$q>.
+C<$q> is required to have a C<param()> method that works like
+CGI's C<param()>.
+
+ $output = $fif->fill(scalarref => \$html,
+ fobject => [$q1, $q2]);
+
+As of 1.04 the object passed does not need to return all its keys with
+a empty param() call.
+
+Note that you can pass multiple objects as an array reference.
+
+ $output = $fif->fill(scalarref => \$html,
+ fdat => \%fdat);
+
+Returns filled in HTML form contained in C<$html> with data from C<%fdat>.
+To pass multiple values using C<%fdat> use an array reference.
+
+Alternately you can use
+
+ $output = $fif->fill(arrayref => \@array_of_lines,
+ fobject => $q);
+
+and
+
+ $output = $fif->fill(file => 'form.tmpl',
+ fobject => $q);
+
+Suppose you have multiple forms in a html and among them there is only
+one form you want to fill in, specify target.
+
+ $output = $fif->fill(scalarref => \$html,
+ fobject => $q,
+ target => 'form1');
+
+This will fill in only the form inside
+
+ <FORM name="form1"> ... </FORM>
+
+Note that this method fills in password fields by default. To disable, pass
+
+ fill_password => 0
+
+To disable the filling of some fields, use the C<ignore_fields> option:
+
+ $output = $fif->fill(scalarref => \$html,
+ fobject => $q,
+ ignore_fields => ['prev','next']);
+
+Note that this module does not clear fields if you set the value to undef.
+It will clear fields if you set the value to an empty array or an empty string. For example:
+
+ # this will leave the form element foo untouched
+ $output = $fif->fill(scalarref => \$html,
+ fdat => { foo => undef });
+
+ # this will set clear the form element foo
+ $output = $fif->fill(scalarref => \$html,
+ fdat => { foo => "" });
+
+It has been suggested to add a option to the new constructer to change the behavior
+so that undef values will clear the form elements. Patches welcome.
+
+=back
+
+=head1 CALLING FROM OTHER MODULES
+
+=head2 Apache::PageKit
+
+To use HTML::FillInForm in L<Apache::PageKit> is easy. It is
+automatically called for any page that includes a <form> tag.
+It can be turned on or off by using the C<fill_in_form> 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<http://www.masonhq.com/docs/faq/#how_can_i_integrate_html_fillin>
+
+=head1 VERSION
+
+This documentation describes HTML::FillInForm module version 1.04.
+
+=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<CGI.pm> or set C<browser_cache> to I<no> in
+Config.xml file of L<Apache::PageKit>.
+
+=head1 TRANSLATION
+
+Kato Atsushi has translated these docs into Japanese, available from
+
+http://perldoc.jp
+
+=head1 BUGS
+
+Please submit any bug reports to tjmather at maxmind.com.
+
+=head1 NOTES
+
+Requires Perl 5.005 and L<HTML::Parser> 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:
+http://www.perlmonks.org/index.pl?node_id=274534
+
+=head1 AUTHOR
+
+(c) 2004 TJ Mather, Maxmind LLC, tjmather at 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.
+
+Paid support is available from directly from the author of this package.
+Please see L<http://www.maxmind.com/app/opensourceservices> for more details.
+
+=head1 SEE ALSO
+
+L<HTML::Parser>, L<Data::FormValidator>, L<HTML::Template>, L<Apache::PageKit>
+
+=head1 CREDITS
+
+Fixes, Bug Reports, Docs have been generously provided by:
+
+ Tatsuhiko Miyagawa
+ Boris Zentner
+ Dave Rolsky
+ Patrick Michael Kane
+ Ade Olonoh
+ Tom Lancaster
+ Martin H Sluka
+ Mark Stosberg
+ Jonathan Swartz
+ Trevor Schellhorn
+ Jim Miner
+ Paul Lindner
+ Maurice Aubrey
+ Andrew Creer
+ Joseph Yanni
+ Philip Mak
+ Jost Krieger
+ Gabriel Burka
+ Bill Moseley
+ James Tolley
+ Dan Kubb
+
+Thanks!
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/00_base.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/00_base.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/00_base.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,8 @@
+
+BEGIN {
+ print "1..1\n";
+}
+
+use HTML::FillInForm;
+
+BEGIN { print "ok 1\n"; }
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/01_form.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/01_form.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/01_form.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,27 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..2\n";
+
+use HTML::FillInForm;
+
+print "ok 1\n";
+
+my $hidden_form_in = qq{<INPUT TYPE="TEXT" NAME="foo1" value="nada">
+<input type="hidden" name="foo2"/>};
+
+my %fdat = (foo1 => 'bar1',
+ foo2 => '"bar2"');
+
+my $fif = new HTML::FillInForm;
+my $output = $fif->fill(scalarref => \$hidden_form_in,
+ fdat => \%fdat);
+if ($output =~ m/^<input( (type="TEXT"|name="foo1"|value="bar1")){3}>\s*<input( (type="hidden"|name="foo2"|value=""bar2"")){3} \/>$/){
+ print "ok 2\n";
+} else {
+ print "Got unexpected out for $hidden_form_in:\n$output\n";
+ print "not ok 2\n";
+}
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/02_hidden.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/02_hidden.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/02_hidden.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,27 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..2\n";
+
+use HTML::FillInForm;
+
+print "ok 1\n";
+
+my $hidden_form_in = qq{<input type="hidden" name="foo1">
+<input type="hidden" name="foo2" value="ack">};
+
+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/^<input( (type="hidden"|name="foo1"|value="")){3}>\s*<input( (type="hidden"|name="foo2"|value="bar2")){3}>$/){
+ print "ok 2\n";
+} else {
+ print "Got unexpected out for hidden form:\n$output\n";
+ print "not ok 2\n";
+}
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/03_checkbox.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/03_checkbox.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/03_checkbox.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,49 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..2\n";
+
+use HTML::FillInForm;
+
+print "ok 1\n";
+
+my $hidden_form_in = qq{<input type="checkbox" name="foo1" value="bar1">
+<input type="checkbox" name="foo1" value="bar2">
+<input type="checkbox" name="foo1" value="bar3">
+<input type="checkbox" name="foo2" value="bar1">
+<input type="checkbox" name="foo2" value="bar2">
+<input type="checkbox" name="foo2" value="bar3">
+<input type="checkbox" name="foo3" value="bar1">
+<input type="checkbox" name="foo3" checked value="bar2">
+<input type="checkbox" name="foo3" value="bar3">
+<input type="checkbox" name="foo4" value="bar1">
+<input type="checkbox" name="foo4" checked value="bar2">
+<input type="checkbox" name="foo4" value="bar3">
+<input type="checkbox" name="foo5">
+<input type="checkbox" name="foo6">
+<input type="checkbox" name="foo7" checked>
+<input type="checkbox" name="foo8" checked>};
+
+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";
+}
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/04_select.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/04_select.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/04_select.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,114 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..5\n";
+
+use HTML::FillInForm;
+use CGI;
+
+print "ok 1\n";
+
+my $hidden_form_in = qq{<select multiple name="foo1">
+ <option value="0">bar1</option>
+ <option value="bar2">bar2</option>
+ <option value="bar3">bar3</option>
+</select>
+<select multiple name="foo2">
+ <option value="bar1">bar1</option>
+ <option value="bar2">bar2</option>
+ <option value="bar3">bar3</option>
+</select>
+<select multiple name="foo3">
+ <option value="bar1">bar1</option>
+ <option selected value="bar2">bar2</option>
+ <option value="bar3">bar3</option>
+</select>
+<select multiple name="foo4">
+ <option value="bar1">bar1</option>
+ <option selected value="bar2">bar2</option>
+ <option value="bar3">bar3</option>
+</select>};
+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);
+
+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{<select multiple name="foo1">
+ <option>bar1</option>
+ <option>bar2</option>
+ <option>bar3</option>
+</select>
+<select multiple name="foo2">
+ <option> bar1</option>
+ <option> bar2</option>
+ <option>bar3</option>
+</select>
+<select multiple name="foo3">
+ <option>bar1</option>
+ <option selected>bar2</option>
+ <option>bar3</option>
+</select>
+<select multiple name="foo4">
+ <option>bar1</option>
+ <option selected>bar2</option>
+ <option>bar3 </option>
+</select>};
+
+$q = new CGI( { foo1 => 'bar1',
+ foo2 => ['bar1', 'bar2',],
+ foo3 => '' }
+ );
+
+$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{<select name="x"><option></select>};
+$fif = new HTML::FillInForm;
+$output = $fif->fill(scalarref => \$hidden_form_in,
+ fobject => $q);
+if ($output eq qq{<select name="x"><option></select>}){
+ print "ok 4\n";
+} else {
+ print "Got unexpected output for empty option:\n$output\n";
+ print "not ok 4\n";
+}
+
+$hidden_form_in = qq{<select name="foo1"><option><option value="bar1"></select>};
+$fif = new HTML::FillInForm;
+$output = $fif->fill(scalarref => \$hidden_form_in,
+ fobject => $q);
+if ($output =~ m!^<select name="foo1"><option><option( selected="selected"| value="bar1"){2}></select>$!){
+ print "ok 5\n";
+} else {
+ print "Got unexpected output for empty option:\n$output\n";
+ print "not ok 5\n";
+}
+
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/05_textarea.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/05_textarea.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/05_textarea.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,39 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..3\n";
+
+use HTML::FillInForm;
+
+print "ok 1\n";
+
+my $hidden_form_in = qq{<TEXTAREA NAME="foo">blah</TEXTAREA>};
+
+my %fdat = (foo => 'bar>bar');
+
+my $fif = new HTML::FillInForm;
+my $output = $fif->fill(scalarref => \$hidden_form_in,
+ fdat => \%fdat);
+if ($output eq '<TEXTAREA NAME="foo">bar>bar</TEXTAREA>'){
+ 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 '<TEXTAREA NAME="foo"></TEXTAREA>'){
+ print "ok 3\n";
+} else {
+ print "Got unexpected out for $hidden_form_in:\n$output\n";
+ print "not ok 3\n";
+}
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/06_radio.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/06_radio.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/06_radio.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,29 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..2\n";
+
+use HTML::FillInForm;
+
+print "ok 1\n";
+
+my $hidden_form_in = qq{<INPUT TYPE="radio" NAME="foo1" value="bar1">
+<input type="radio" name="foo1" value="bar2">
+<input type="radio" name="foo1" value="bar3">
+<input type="radio" name="foo1" checked value="bar4">};
+
+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'){
+ print "ok 2\n";
+} else {
+ print "Got unexpected is_checked:\n$is_checked\n";
+ print "not ok 2\n";
+}
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/07_reuse.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/07_reuse.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/07_reuse.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,29 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..2\n";
+
+use HTML::FillInForm;
+
+print "ok 1\n";
+
+my $hidden_form_in = qq{<INPUT TYPE="TEXT" NAME="foo1" value="nada">
+<input type="hidden" name="foo2">};
+
+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/^<input( (type="TEXT"|name="foo1"|value="bar1")){3}>\s*<input( (type="hidden"|name="foo2"|value="bar2")){3}>$/){
+ print "ok 2\n";
+} else {
+ print "Got unexpected out for $hidden_form_in:\n$output2\n";
+ print "not ok 2\n";
+}
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/08_multiple_objects.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/08_multiple_objects.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/08_multiple_objects.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,31 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..2\n";
+
+use HTML::FillInForm;
+use CGI;
+
+print "ok 1\n";
+
+my $hidden_form_in = qq{<INPUT TYPE="TEXT" NAME="foo1" value="nada">
+<input type="hidden" name="foo2">};
+
+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/^<input( (type="TEXT"|name="foo1"|value="bar1")){3}>\s*<input( (type="hidden"|name="foo2"|value="bar2")){3}>$/){
+ print "ok 2\n";
+} else {
+ print "Got unexpected out for $hidden_form_in:\n$output\n";
+ print "not ok 2\n";
+}
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/09_default_type.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/09_default_type.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/09_default_type.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,27 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..2\n";
+
+use HTML::FillInForm;
+
+print "ok 1\n";
+
+my $hidden_form_in = qq{<INPUT NAME="foo1" value="nada">
+<input type="hidden" name="foo2">};
+
+my %fdat = (foo1 => 'bar1',
+ foo2 => 'bar2');
+
+my $fif = new HTML::FillInForm;
+my $output = $fif->fill(scalarref => \$hidden_form_in,
+ fdat => \%fdat);
+if ($output =~ m/^<input( (name="foo1"|value="bar1")){2}>\s*<input( (type="hidden"|name="foo2"|value="bar2")){3}>$/){
+ print "ok 2\n";
+} else {
+ print "Got unexpected out for $hidden_form_in:\n$output\n";
+ print "not ok 2\n";
+}
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/10_escape.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/10_escape.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/10_escape.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,44 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+print "1..1\n";
+use HTML::FillInForm;
+
+my $html =<<"__HTML__";
+<HTML>
+<BODY>
+<FORM action="test.cgi" method="POST">
+<INPUT type="hidden" name="hidden" value=">"">
+<INPUT type="text" name="text" value="<>"õ"><BR>
+<INPUT type="radio" name="radio" value=""<>">test<BR>
+<INPUT type="checkbox" name="checkbox" value=""<>">test<BR>
+<INPUT type="checkbox" name="checkbox" value=""><>">test<BR>
+<SELECT name="select">
+<OPTION value="<>"><>
+<OPTION value=">>">>>
+<OPTION value="õ"><<
+<OPTION>>>>
+</SELECT><BR>
+<TEXTAREA name="textarea" rows="5"><>"</TEXTAREA><P>
+<INPUT type="submit" value=" OK ">
+</FORM>
+</BODY>
+</HTML>
+__HTML__
+
+my %fdat = ();
+
+my $fif = HTML::FillInForm->new;
+my $output = $fif->fill(scalarref => \$html,
+ fdat => \%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)));
+
+unless ($strings_output eq $strings_html){
+ print "not ";
+}
+print "ok 1";
+
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/11_target.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/11_target.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/11_target.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,38 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+use Test;
+BEGIN { plan tests => 3 }
+
+use HTML::FillInForm;
+
+my $form = <<EOF;
+<FORM name="foo1">
+<INPUT TYPE="TEXT" NAME="foo1" value="nada">
+</FORM>
+<FORM name="foo2">
+<INPUT TYPE="TEXT" NAME="foo2" value="nada">
+</FORM>
+<FORM>
+<INPUT TYPE="TEXT" NAME="foo3" value="nada">
+</FORM>
+EOF
+ ;
+
+my %fdat = (
+ foo1 => 'bar1',
+ foo2 => 'bar2',
+ foo3 => 'bar3',
+);
+
+my $fif = new HTML::FillInForm;
+my $output = $fif->fill(
+ scalarref => \$form,
+ fdat => \%fdat,
+ target => 'foo2',
+);
+
+my @v = $output =~ m/<input .*?value="(.*?)"/ig;
+ok($v[0], 'nada');
+ok($v[1], 'bar2');
+ok($v[2], 'nada');
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/12_mult.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/12_mult.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/12_mult.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,37 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..3\n";
+
+use HTML::FillInForm;
+
+print "ok 1\n";
+
+my $hidden_form_in = qq{<INPUT TYPE="TEXT" NAME="foo1" value="cat1">
+<input type="text" name="foo1" value="cat2"/>};
+
+my %fdat = (foo1 => ['bar1','bar2']);
+
+my $fif = new HTML::FillInForm;
+my $output = $fif->fill(scalarref => \$hidden_form_in,
+ fdat => \%fdat);
+if ($output =~ m/^<input( (type="TEXT"|name="foo1"|value="bar1")){3}>\s*<input( (type="text"|name="foo1"|value="bar2")){3} \/>$/){
+ 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/^<input( (type="TEXT"|name="foo1"|value="bar1")){3}>\s*<input( (type="text"|name="foo1"|value="")){3} \/>$/){
+ print "ok 3\n";
+} else {
+ print "Got unexpected out for $hidden_form_in:\n$output\n";
+ print "not ok 3\n";
+}
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/13_warning.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/13_warning.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/13_warning.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,25 @@
+# -*- 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{<input type="submit" value="Commit">};
+
+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!<input( type="submit"| value="Commit"){2}>!);
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/14_password.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/14_password.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/14_password.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,39 @@
+# -*- Mode: Perl; -*-
+
+#!/usr/bin/perl -w
+
+use CGI qw(:no_debug);
+use HTML::FillInForm;
+use Test;
+
+BEGIN { plan tests => 2 }
+
+local $/;
+my $html = qq{<input type="password" name="foo">};
+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"/);
+}
+
+
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/15_multiple_fields.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/15_multiple_fields.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/15_multiple_fields.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,25 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..2\n";
+
+use HTML::FillInForm;
+print "ok 1\n";
+
+my $hidden_form_in = qq{<input type="hidden" name="foo">
+<input type="hidden" name="foo" value="ack">};
+
+my %fdat = (foo => 'bar1a');
+
+my $fif = new HTML::FillInForm;
+my $output = $fif->fill(scalarref => \$hidden_form_in,
+ fdat => \%fdat);
+if ($output =~ m/^<input( (type="hidden"|name="foo"|value="bar1a")){3}>\s*<input( (type="hidden"|name="foo"|value="bar1a")){3}>$/){
+ print "ok 2\n";
+} else {
+ print "Got unexpected out for hidden form:\n$output\n";
+ print "not ok 2\n";
+}
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/16_ignore_fields.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/16_ignore_fields.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/16_ignore_fields.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,52 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..2\n";
+
+use HTML::FillInForm;
+use CGI;
+
+print "ok 1\n";
+
+my $hidden_form_in = qq{<select multiple name="foo1">
+ <option value="0">bar1</option>
+ <option value="bar2">bar2</option>
+ <option value="bar3">bar3</option>
+</select>
+<select multiple name="foo2">
+ <option value="bar1">bar1</option>
+ <option value="bar2">bar2</option>
+ <option value="bar3">bar3</option>
+</select>
+<select multiple name="foo3">
+ <option value="bar1">bar1</option>
+ <option selected value="bar2">bar2</option>
+ <option value="bar3">bar3</option>
+</select>
+<select multiple name="foo4">
+ <option value="bar1">bar1</option>
+ <option selected value="bar2">bar2</option>
+ <option value="bar3">bar3</option>
+</select>};
+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";
+}
+
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/17_xhtml.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/17_xhtml.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/17_xhtml.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,49 @@
+# -*- Mode: Perl; -*-
+
+use strict;
+
+$^W = 1;
+
+print "1..1\n";
+
+use HTML::FillInForm;
+use CGI;
+
+my $html = <<EOF;
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
+<html>
+<body>
+ <input type="radio" name="status" value=0 />Canceled<br>
+ <input type="radio" name="status" value=1 />Confirmed<br>
+ <input type="radio" name="status" value=2 />Wait List<br>
+
+ <input type="radio" name="status" value=3 />No Show<br>
+ <input type="radio" name="status" value=4 />Moved to Another Class<br>
+ <input type="radio" name="status" value=5 />Late Cancel<br>
+</body>
+</html>
+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;
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/18_ignore_fdat.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/18_ignore_fdat.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/18_ignore_fdat.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,31 @@
+#!/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[
+<form>
+<input type="text" name="one" value="not disturbed">
+<input type="text" name="two" value="not disturbed">
+<input type="text" name="three" value="not disturbed">
+</form>
+];
+
+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.+one/,'ignore 1');
+ok($result =~ /not disturbed.+two/,'ignore 2');
+ok($result =~ /new val 3.+three/,'ignore 3');
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/19_extra.t
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/19_extra.t 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/19_extra.t 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,245 @@
+# -*- 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 => 30;
+
+use_ok('HTML::FillInForm');
+
+my $html = qq[
+<form>
+<input type="text" name="one" value="not disturbed">
+<input type="text" name="two" value="not disturbed">
+<input type="text" name="three" value="not disturbed">
+</form>
+];
+
+my $result = HTML::FillInForm->new->fill_scalarref(
+ \$html,
+ fdat => {
+ two => "new val 2",
+ three => "new val 3",
+ },
+ ignore_fields => 'one',
+ );
+
+ok($result =~ /not disturbed.+one/,'scalar value of ignore_fields');
+ok($result =~ /new val 2.+two/,'fill_scalarref worked');
+ok($result =~ /new val 3.+three/,'fill_scalarref worked 2');
+
+
+$html = qq[
+<form>
+<input type="text" name="one" value="not disturbed">
+<input type="text" name="two" value="not disturbed">
+</form>
+];
+
+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.+one/, 'fill_arrayref 1');
+ok($result =~ /new val 2.+two/, '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.+one/,'fill_file 1');
+ok($result =~ /new val 2.+two/,'fill_file 2');
+ok($result =~ /new val 3.+three/,'fill_file 3');
+
+
+
+$html = qq[
+<form>
+<input type="text" name="one" value="not disturbed">
+<input type="text" name="two" value="not disturbed">
+</form>
+];
+
+eval{
+$result = HTML::FillInForm->new->fill_scalarref(
+ \$html
+ );
+};
+
+#ok($@ =~ 'HTML::FillInForm->fillInForm\(\) called without \'fobject\' or \'fdat\' parameter set', "no fdat or fobject parameters");
+
+$result = HTML::FillInForm->new->fill(
+ fdat => {}
+ );
+
+#No meaningful arguments - should not this produce an error?
+
+
+$html = qq[
+<form>
+<input type="text" name="one" value="not disturbed">
+<input type="text" name="two" value="not disturbed">
+</form>
+];
+
+my $fobject = new Support::Object;
+
+eval{
+$result = HTML::FillInForm->new->fill_scalarref(
+ $html,
+ fobject => $fobject
+ );
+};
+
+ok($@ =~ 'HTML::FillInForm->fill called with fobject option, containing object of type Support::Object which lacks a param\(\) method!', "bad fobject parameter");
+
+
+$html = qq{<INPUT TYPE="radio" NAME="foo1">
+<input type="radio" name="foo1" >
+};
+
+my %fdat = (foo1 => 'bar2');
+
+$result = HTML::FillInForm->new->fill(scalarref => \$html,
+ fdat => \%fdat);
+
+ok($result =~ /on.+foo1/,'defaulting radio buttons to on');
+
+
+$html = qq{<INPUT TYPE="password" NAME="foo1">
+};
+
+%fdat = (foo1 => ['bar2', 'bar3']);
+
+$result = HTML::FillInForm->new->fill(scalarref => \$html,
+ fdat => \%fdat);
+
+ok($result =~ /bar2.+foo1/,'first array element taken for password fields');
+
+
+$html = qq{<INPUT TYPE="radio" NAME="foo1" value="bar2">
+<INPUT TYPE="radio" NAME="foo1" value="bar3">
+};
+
+%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{<TEXTAREA></TEXTAREA>};
+
+%fdat = (area => 'foo1');
+
+$result = HTML::FillInForm->new->fill(scalarref => \$html,
+ fdat => \%fdat);
+
+ok($result !~ /foo1/,'textarea with no name');
+
+
+$html = qq{<TEXTAREA NAME="foo1"></TEXTAREA>};
+
+%fdat = (foo1 => ['bar2', 'bar3']);
+
+$result = HTML::FillInForm->new->fill(scalarref => \$html,
+ fdat => \%fdat);
+
+
+ok($result eq '<TEXTAREA NAME="foo1">bar2</TEXTAREA>','first array element taken for textareas');
+
+
+$html = qq{<INPUT TYPE="radio" NAME="foo1" value="bar2">
+<INPUT TYPE="radio" NAME="foo1" value="bar3">
+<TEXTAREA NAME="foo2"></TEXTAREA>
+<INPUT TYPE="password" NAME="foo3">
+};
+
+%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");
+ok($result =~ m#<TEXTAREA NAME="foo2"></TEXTAREA>#, "Empty textarea");
+ok($result =~ m/<input( (type="password"|name="foo3"|value="")){3}>/, "Empty password field value");
+
+
+$html = qq[<div></div>
+<!--Comment 1-->
+<form>
+<!--Comment 2-->
+<input type="text" name="foo0" value="not disturbed">
+<!--Comment
+
+3-->
+<TEXTAREA NAME="foo1"></TEXTAREA>
+</form>
+<!--Comment 4-->
+];
+
+%fdat = (foo0 => 'bar1', foo1 => 'bar2');
+
+$result = HTML::FillInForm->new->fill(scalarref => \$html,
+ fdat => \%fdat);
+
+ok($result =~ /bar1.+foo0/,'form with comments 1');
+ok($result =~ '<TEXTAREA NAME="foo1">bar2</TEXTAREA>','form with comments 2');
+ok($result =~ '<!--Comment 1-->','Comment 1');
+ok($result =~ '<!--Comment 2-->','Comment 2');
+ok($result =~ '<!--Comment\n\n3-->','Comment 3');
+ok($result =~ '<!--Comment 4-->','Comment 4');
+
+$html = qq[<div></div>
+<? HTML processing instructions 1 ?>
+<form>
+<? XML processing instructions 2?>
+<input type="text" name="foo0" value="not disturbed">
+<? HTML processing instructions
+
+3><TEXTAREA NAME="foo1"></TEXTAREA>
+</form>
+<?HTML processing instructions 4 >
+];
+
+%fdat = (foo0 => 'bar1', foo1 => 'bar2');
+
+$result = HTML::FillInForm->new->fill(scalarref => \$html,
+ fdat => \%fdat);
+
+ok($result =~ /bar1.+foo0/,'form with processing 1');
+ok($result =~ '<TEXTAREA NAME="foo1">bar2</TEXTAREA>','form with processing 2');
+ok($result =~ '<\? HTML processing instructions 1 \?>','processing 1');
+ok($result =~ '<\? XML processing instructions 2\?>','processing 2');
+ok($result =~ '<\? HTML processing instructions\n\n3>','processing 3');
+ok($result =~ '<\?HTML processing instructions 4 >','processing 4');
+
Added: packages/libhtml-fillinform-perl/branches/upstream/current/t/data/form1.html
===================================================================
--- packages/libhtml-fillinform-perl/branches/upstream/current/t/data/form1.html 2005-03-14 06:44:04 UTC (rev 791)
+++ packages/libhtml-fillinform-perl/branches/upstream/current/t/data/form1.html 2005-03-15 18:59:53 UTC (rev 792)
@@ -0,0 +1,5 @@
+<form>
+<input type="text" name="one" value="not disturbed">
+<input type="text" name="two" value="not disturbed">
+<input type="text" name="three" value="not disturbed">
+</form>
More information about the Pkg-perl-cvs-commits
mailing list