r7514 - in /branches/upstream/libhtml-fillinform-perl/current: Changes META.yml lib/HTML/FillInForm.pm t/04_select.t t/10_escape.t t/11_target.t t/19_extra.t t/20_scalarref.t t/21_disable_fields.t

dmn at users.alioth.debian.org dmn at users.alioth.debian.org
Thu Sep 13 07:20:14 UTC 2007


Author: dmn
Date: Thu Sep 13 07:20:13 2007
New Revision: 7514

URL: http://svn.debian.org/wsvn/?sc=1&rev=7514
Log:
[svn-upgrade] Integrating new upstream version, libhtml-fillinform-perl (2.00)

Modified:
    branches/upstream/libhtml-fillinform-perl/current/Changes
    branches/upstream/libhtml-fillinform-perl/current/META.yml
    branches/upstream/libhtml-fillinform-perl/current/lib/HTML/FillInForm.pm
    branches/upstream/libhtml-fillinform-perl/current/t/04_select.t
    branches/upstream/libhtml-fillinform-perl/current/t/10_escape.t
    branches/upstream/libhtml-fillinform-perl/current/t/11_target.t
    branches/upstream/libhtml-fillinform-perl/current/t/19_extra.t
    branches/upstream/libhtml-fillinform-perl/current/t/20_scalarref.t
    branches/upstream/libhtml-fillinform-perl/current/t/21_disable_fields.t

Modified: branches/upstream/libhtml-fillinform-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libhtml-fillinform-perl/current/Changes?rev=7514&op=diff
==============================================================================
--- branches/upstream/libhtml-fillinform-perl/current/Changes (original)
+++ branches/upstream/libhtml-fillinform-perl/current/Changes Thu Sep 13 07:20:13 2007
@@ -1,3 +1,30 @@
+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)
@@ -8,9 +35,6 @@
 
 Fix a bug the last plaintext part might be chopped if called via
 scalarref [rt.cpan.org #21750] (Tatsuhiko Miyagawa)
-
-Add support for ID attribute on form tags (name attribute is
-deprecated in xhtml) [rt.cpan.org #27376] (Anthony Ettinger)
 
 Fix bug when passing 0 in array ref to textfields, also see
 [rt.cpan.org #22195] (Paul Miller)

Modified: branches/upstream/libhtml-fillinform-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libhtml-fillinform-perl/current/META.yml?rev=7514&op=diff
==============================================================================
--- branches/upstream/libhtml-fillinform-perl/current/META.yml (original)
+++ branches/upstream/libhtml-fillinform-perl/current/META.yml Thu Sep 13 07:20:13 2007
@@ -1,7 +1,7 @@
 # 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.07
+version:      2.00
 version_from: lib/HTML/FillInForm.pm
 installdirs:  site
 requires:

Modified: branches/upstream/libhtml-fillinform-perl/current/lib/HTML/FillInForm.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libhtml-fillinform-perl/current/lib/HTML/FillInForm.pm?rev=7514&op=diff
==============================================================================
--- branches/upstream/libhtml-fillinform-perl/current/lib/HTML/FillInForm.pm (original)
+++ branches/upstream/libhtml-fillinform-perl/current/lib/HTML/FillInForm.pm Thu Sep 13 07:20:13 2007
@@ -12,7 +12,7 @@
 require 5.005;
 
 use vars qw($VERSION @ISA);
-$VERSION = '1.07';
+$VERSION = '2.00';
 
 @ISA = qw(HTML::Parser);
 
@@ -26,12 +26,97 @@
 }
 
 # 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_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 _); }
 
+# 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,
+    }
+}
+
 sub fill {
-  my ($self, %option) = @_;
+   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' )
@@ -40,7 +125,7 @@
 
   my %disable_fields;
   %disable_fields = map { $_ => 1 } ( ref $option{'disable_fields'} eq 'ARRAY' )
-    ? @{ $option{disable_fields} } : $option{ignore_fields} if exists( $option{disable_fields} );
+    ? @{ $option{disable_fields} } : $option{disable_fields} if exists( $option{disable_fields} );
   $self->{disable_fields} = \%disable_fields;
 
   if (my $fdat = $option{fdat}){
@@ -107,8 +192,8 @@
   # set the current form
   if ($tagname eq 'form') {
     $self->{object_param_cache} = {};
-    if (exists $attr->{'name'}) {
-      $self->{'current_form'} = $attr->{'name'};
+    if (exists $attr->{'name'} || exists $attr->{'id'}) {
+      $self->{'current_form'} = $attr->{'name'} || $attr->{'id'};
     } else {
       # in case of previous one without </FORM>
       delete $self->{'current_form'};
@@ -387,116 +472,121 @@
 
 =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.
+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
 
-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
+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<Apache::Request|Apache::Request>, 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
+
+  <FORM name="form1"> ... </FORM>
+
+=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' ]
+
+=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.
+
+=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<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']);
-
-To disable the form from being edited, use the C<disable_fields> options:
-
-  $output = $fif->fill(scalarref => \$html,
-                       fobject => $q,
-                       disable_fields => [ 'uid', 'gid' ]);
-
-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
+  $fif = HTML::FillInForm->new;
+  $fif->fill(...);
+
+In theory, there is a slight performance benefit to calling C<new()> before C<fill()> if you make multiple 
+calls to C<fill()> 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<fill()>:
+
+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 CALLING FROM OTHER MODULES
 
@@ -522,7 +612,7 @@
 
 =head1 VERSION
 
-This documentation describes HTML::FillInForm module version 1.06.
+This documentation describes HTML::FillInForm module version 2.00
 
 =head1 SECURITY
 
@@ -567,38 +657,28 @@
 
 =head1 SEE ALSO
 
-L<HTML::Parser>, L<Data::FormValidator>, L<HTML::Template>, L<Apache::PageKit>
+L<HTML::Parser|HTML::Parser>, 
+L<Data::FormValidator|Data::FormValidato>, 
+L<HTML::Template|HTML::Template>, 
+L<Apache::PageKit|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
-  Alexander Hartmaier
-  Paul Miller
-  Anthony Ettinger
-  Simon P. Ditner
-  Michael Peters
-  Trevor Schellhorn
+  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!

Modified: branches/upstream/libhtml-fillinform-perl/current/t/04_select.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhtml-fillinform-perl/current/t/04_select.t?rev=7514&op=diff
==============================================================================
--- branches/upstream/libhtml-fillinform-perl/current/t/04_select.t (original)
+++ branches/upstream/libhtml-fillinform-perl/current/t/04_select.t Thu Sep 13 07:20:13 2007
@@ -36,9 +36,7 @@
 	   foo3 => '' }
 	);
 
-my $fif = new HTML::FillInForm;
-my $output = $fif->fill(scalarref => \$hidden_form_in,
-                       fobject => $q);
+my $output = HTML::FillInForm->fill(\$hidden_form_in, $q);
 
 my $is_selected = join(" ",map { m/selected/ ? "yes" : "no" } grep /option/, split ("\n",$output));
 
@@ -75,7 +73,7 @@
 	   foo3 => '' }
 	);
 
-$fif = new HTML::FillInForm;
+my $fif = new HTML::FillInForm;
 $output = $fif->fill(scalarref => \$hidden_form_in,
                        fobject => $q);
 

Modified: branches/upstream/libhtml-fillinform-perl/current/t/10_escape.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhtml-fillinform-perl/current/t/10_escape.t?rev=7514&op=diff
==============================================================================
--- branches/upstream/libhtml-fillinform-perl/current/t/10_escape.t (original)
+++ branches/upstream/libhtml-fillinform-perl/current/t/10_escape.t Thu Sep 13 07:20:13 2007
@@ -1,8 +1,8 @@
 # -*- Mode: Perl; -*-
 
+use Test::More 'no_plan';
 use strict;
 
-print "1..1\n";
 use HTML::FillInForm;
  
 my $html =<<"__HTML__";
@@ -29,16 +29,11 @@
 
 my %fdat = ();
 
-my $fif = HTML::FillInForm->new;
-my $output = $fif->fill(scalarref => \$html,
-			fdat => \%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)));
 
-unless ($strings_output eq $strings_html){
-	print "not ";
-}
-print "ok 1";
+is($strings_output,$strings_html);
 

Modified: branches/upstream/libhtml-fillinform-perl/current/t/11_target.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhtml-fillinform-perl/current/t/11_target.t?rev=7514&op=diff
==============================================================================
--- branches/upstream/libhtml-fillinform-perl/current/t/11_target.t (original)
+++ branches/upstream/libhtml-fillinform-perl/current/t/11_target.t Thu Sep 13 07:20:13 2007
@@ -2,7 +2,7 @@
 
 use strict;
 use Test;
-BEGIN { plan tests => 3 }
+BEGIN { plan tests => 8 }
 
 use HTML::FillInForm;
 
@@ -16,6 +16,9 @@
 <FORM>
 <INPUT TYPE="TEXT" NAME="foo3" value="nada">
 </FORM>
+<FORM id="foo4">
+<INPUT TYPE="TEXT" NAME="foo4" value="nada">
+</FORM>
 EOF
   ;
   
@@ -23,12 +26,10 @@
   foo1 => 'bar1',
   foo2 => 'bar2',
   foo3 => 'bar3',
+  foo4 => 'bar4',
 );
 
-my $fif = new HTML::FillInForm;
-my $output = $fif->fill(
-  scalarref => \$form,
-  fdat => \%fdat,
+my $output = HTML::FillInForm->fill( \$form, \%fdat,
   target => 'foo2',
 );
 
@@ -36,3 +37,14 @@
 ok($v[0], 'nada');
 ok($v[1], 'bar2');
 ok($v[2], 'nada');
+ok($v[3], 'nada');
+
+my $output2 = HTML::FillInForm->fill( \$form, \%fdat,
+  target => 'foo4',
+);
+
+my @v2 = $output2 =~ m/<input .*?value="(.*?)"/ig;
+ok($v2[0], 'nada');
+ok($v2[1], 'nada');
+ok($v2[2], 'nada');
+ok($v2[3], 'bar4');

Modified: branches/upstream/libhtml-fillinform-perl/current/t/19_extra.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhtml-fillinform-perl/current/t/19_extra.t?rev=7514&op=diff
==============================================================================
--- branches/upstream/libhtml-fillinform-perl/current/t/19_extra.t (original)
+++ branches/upstream/libhtml-fillinform-perl/current/t/19_extra.t Thu Sep 13 07:20:13 2007
@@ -17,7 +17,7 @@
 ###
 #End of Support::Object
 
-use Test::More tests => 30;
+use Test::More tests => 38;
 
 use_ok('HTML::FillInForm');
 
@@ -38,9 +38,9 @@
                                          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');
+like($result, qr/not disturbed.+one/,'scalar value of ignore_fields');
+like($result, qr/new val 2.+two/,'fill_scalarref worked');
+like($result, qr/new val 3.+three/,'fill_scalarref worked 2');
 
 
 $html = qq[
@@ -52,30 +52,80 @@
 
 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');
+
+{ 
+    $result = HTML::FillInForm->new->fill_arrayref(
+                                             \@html_array,
+                                             fdat => {
+                                               one => "new val 1",
+                                               two => "new val 2",
+                                             },
+                                             );
+
+    like($result, qr/new val 1.+one/, 'fill_arrayref 1');
+    like($result, qr/new val 2.+two/, 'fill_arrayref 2');
+}
+
+{
+    $result = HTML::FillInForm->fill(
+        \@html_array,
+        {
+            one => "new val 1",
+            two => "new val 2",
+        },
+     );
+
+    like($result, qr/new val 1.+one/, 'fill_arrayref 1');
+    like($result, qr/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",
+        },
+    );
+
+    like($result, qr/new val 1.+one/,'fill_file 1');
+    like($result, qr/new val 2.+two/,'fill_file 2');
+    like($result, qr/new val 3.+three/,'fill_file 3');
+}
+
+{
+    $result = HTML::FillInForm->fill(
+        "t/data/form1.html",
+        {
+            one => "new val 1",
+            two => "new val 2",
+            three => "new val 3",
+        },
+    );
+
+    like($result, qr/new val 1.+one/,'fill_file 1');
+    like($result, qr/new val 2.+two/,'fill_file 2');
+    like($result, qr/new val 3.+three/,'fill_file 3');
+}
+{
+    my $fh = open FH, "<t/data/form1.html" || die "can't open file: $!";
+
+    $result = HTML::FillInForm->fill(
+        \*FH,
+        {
+            one => "new val 1",
+            two => "new val 2",
+            three => "new val 3",
+        },
+    );
+
+    like($result, qr/new val 1.+one/,'fill_file 1');
+    like($result, qr/new val 2.+two/,'fill_file 2');
+    like($result, qr/new val 3.+three/,'fill_file 3');
+    close($fh);
+}
 
 
 
@@ -91,8 +141,6 @@
                                          \$html
                                          );
 };
-
-#ok($@ =~ 'HTML::FillInForm->fillInForm\(\) called without \'fobject\' or \'fdat\' parameter set', "no fdat or fobject parameters");
 
 $result = HTML::FillInForm->new->fill(
                                     fdat => {}
@@ -117,7 +165,7 @@
                                          );
 };
 
-ok($@ =~ 'HTML::FillInForm->fill called with fobject option, containing object of type Support::Object which lacks a param\(\) method!', "bad fobject parameter");
+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{<INPUT TYPE="radio" NAME="foo1">
@@ -129,7 +177,7 @@
 $result = HTML::FillInForm->new->fill(scalarref => \$html,
                         fdat => \%fdat);
 
-ok($result =~ /on.+foo1/,'defaulting radio buttons to on');
+like($result, qr/on.+foo1/,'defaulting radio buttons to on');
 
 
 $html = qq{<INPUT TYPE="password" NAME="foo1">
@@ -140,7 +188,7 @@
 $result = HTML::FillInForm->new->fill(scalarref => \$html,
                         fdat => \%fdat);
 
-ok($result =~ /bar2.+foo1/,'first array element taken for password fields');
+like($result, qr/bar2.+foo1/,'first array element taken for password fields');
 
 
 $html = qq{<INPUT TYPE="radio" NAME="foo1" value="bar2">
@@ -190,8 +238,8 @@
                         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");
+like($result, qr#<TEXTAREA NAME="foo2"></TEXTAREA>#, "Empty textarea");
+like($result, qr/<input( (type="password"|name="foo3"|value="")){3}>/, "Empty password field value");
 
 
 $html = qq[<div></div>
@@ -212,12 +260,12 @@
 $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');
+like($result, qr/bar1.+foo0/,'form with comments 1');
+like($result, qr'<TEXTAREA NAME="foo1">bar2</TEXTAREA>','form with comments 2');
+like($result, qr'<!--Comment 1-->','Comment 1');
+like($result, qr'<!--Comment 2-->','Comment 2');
+like($result, qr'<!--Comment\n\n3-->','Comment 3');
+like($result, qr'<!--Comment 4-->','Comment 4');
 
 $html = qq[<div></div>
 <? HTML processing instructions 1 ?>
@@ -236,10 +284,10 @@
 $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');
-
+like($result, qr/bar1.+foo0/,'form with processing 1');
+like($result, qr'<TEXTAREA NAME="foo1">bar2</TEXTAREA>','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');
+

Modified: branches/upstream/libhtml-fillinform-perl/current/t/20_scalarref.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhtml-fillinform-perl/current/t/20_scalarref.t?rev=7514&op=diff
==============================================================================
--- branches/upstream/libhtml-fillinform-perl/current/t/20_scalarref.t (original)
+++ branches/upstream/libhtml-fillinform-perl/current/t/20_scalarref.t Thu Sep 13 07:20:13 2007
@@ -17,10 +17,7 @@
 
 # run each string through H::FIF
 foreach my $content (@contents) {
-    my $output = HTML::FillInForm->new->fill(
-        scalarref => \$content,
-        fdat      => {}
-    );
+    my $output = HTML::FillInForm->fill( \$content, fdat      => {});
 
     is($output, $content, q{output and content should be the same});
 }

Modified: branches/upstream/libhtml-fillinform-perl/current/t/21_disable_fields.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhtml-fillinform-perl/current/t/21_disable_fields.t?rev=7514&op=diff
==============================================================================
--- branches/upstream/libhtml-fillinform-perl/current/t/21_disable_fields.t (original)
+++ branches/upstream/libhtml-fillinform-perl/current/t/21_disable_fields.t Thu Sep 13 07:20:13 2007
@@ -5,7 +5,7 @@
 use strict;
 use warnings FATAL => 'all';
 
-use Test::More tests => 3;
+use Test::More tests => 5;
 
 use_ok('HTML::FillInForm');
 
@@ -26,3 +26,13 @@
 
 ok($result =~ /not disturbed.+one/,'don\'t disable 1');
 ok($result =~ /new val 2.+two.+disable="1"/,'disable 2');
+$result = HTML::FillInForm->new->fill(
+					 scalarref => \$html,
+					 fdat => {
+					   two => "new val 2",
+					 },
+					 disable_fields => 'two',
+					 );
+
+ok($result =~ /not disturbed.+one/,'don\'t disable 1');
+ok($result =~ /new val 2.+two.+disable="1"/,'disable 2');




More information about the Pkg-perl-cvs-commits mailing list