The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
Changes 327
META.yml 11
lib/HTML/FillInForm.pm 105185
t/04_select.t 42
t/10_escape.t 83
t/11_target.t 517
t/19_extra.t 4391
t/20_scalarref.t 41
t/21_disable_fields.t 111
9 files changed (This is a version diff) 174338
@@ -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)
@@ -9,9 +36,6 @@ 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)
 
-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)
 
@@ -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:
@@ -12,7 +12,7 @@ use HTML::Parser 3.26;
 require 5.005;
 
 use vars qw($VERSION @ISA);
-$VERSION = '1.07';
+$VERSION = '2.00';
 
 @ISA = qw(HTML::Parser);
 
@@ -26,12 +26,97 @@ sub new {
 }
 
 # 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_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,
+    }
+}
+
 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 @@ sub fill {
 
   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 @@ sub start {
   # 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 @@ 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.
+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:
 
-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.
+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".
+Fill HTML form with data.
 
-  my $q = new CGI;
+  $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] );
 
-  $q->param("name","John Smith");
+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. 
 
-  my $fif = new HTML::FillInForm;
-  my $output = $fif->fill(scalarref => \$html,
-			  fobject => $q);
+=head1 fill
 
-Note CGI.pm is B<not> required - see using fdat below.  Also you can use a CGI.pm-like object such as Apache::Request.
+The basic syntax is seen above the Synopsis. There are a few additional options.
 
-=head1 METHODS
+=head2 Options
 
-=over 4
+=head3  target => 'form1'
 
-=item new
+Suppose you have multiple forms in a html file and only want to fill in one.
 
-Call C<new()> to create a new FillInForm object:
+  $output = HTML::FillInForm->fill(\$html, $q, target => 'form1');
+
+This will fill in only the form inside
+
+  <FORM name="form1"> ... </FORM>
 
-  $fif = new HTML::FillInForm;
+=head3 fill_password => 0
 
-=item fill
+Passwords are filled in by default. To disable:
 
-To fill in a HTML form contained in a scalar C<$html>:
+  fill_password => 0
 
-  $output = $fif->fill(scalarref => \$html,
-             fobject => $q);
+=head3 ignore_fields => []
 
-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()>.
+To disable the filling of some fields:
 
-  $output = $fif->fill(scalarref => \$html,
-             fobject => [$q1, $q2]);
+    ignore_fields => ['prev','next']
 
-As of 1.04 the object passed does not need to return all its keys with
-a empty param() call.
+=head3 disable_fields => []
 
-Note that you can pass multiple objects as an array reference.
+To disable fields from being edited:
 
-  $output = $fif->fill(scalarref => \$html,
-             fdat => \%fdat);
+    disable_fields => [ 'uid', 'gid' ]
 
-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.
+=head2 File Upload fields
 
-Alternately you can use
+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.
 
-  $output = $fif->fill(arrayref => \@array_of_lines,
-             fobject => $q);
+=head2 Clearing Fields
 
-and
+Fields are cleared if you set their value to an empty string or empty arrayref but not undef:
 
-  $output = $fif->fill(file => 'form.tmpl',
-             fobject => $q);
+  # this will leave the form element foo untouched
+  HTML::FillInForm->fill(\$html, { foo => undef });
 
-Suppose you have multiple forms in a html and among them there is only
-one form you want to fill in, specify target.
+  # this will set clear the form element foo
+  HTML::FillInForm->fill(\$html, { foo => "" });
 
-  $output = $fif->fill(scalarref => \$html,
-                       fobject => $q,
-                       target => 'form1');
+It has been suggested to add a option to change the behavior so that undef
+values will clear the form elements.  Patches welcome.
 
-This will fill in only the form inside
+=head1 Old syntax
 
-  <FORM name="form1"> ... </FORM>
+You probably need to read no further. The remaining docs concern the
+1.x era syntax, which is still supported. 
 
-Note that this method fills in password fields by default.  To disable, pass
+=head2 new
 
-  fill_password => 0
+Call C<new()> to create a new FillInForm object:
 
-To disable the filling of some fields, use the C<ignore_fields> option:
+  $fif = HTML::FillInForm->new;
+  $fif->fill(...);
 
-  $output = $fif->fill(scalarref => \$html,
-                       fobject => $q,
-                       ignore_fields => ['prev','next']);
+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. 
 
-To disable the form from being edited, use the C<disable_fields> options:
+=head2 fill ( old syntax ) 
 
-  $output = $fif->fill(scalarref => \$html,
-                       fobject => $q,
-                       disable_fields => [ 'uid', 'gid' ]);
+Instead of having your HTML and data types auto-detected, you can declare them explicitly in your
+call to C<fill()>:
 
-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:
+HTML source options:
 
-  # this will leave the form element foo untouched
-  $output = $fif->fill(scalarref => \$html,
-             fdat => { foo => undef });
+    arrayref  => @html
+    scalarref => $html
+    file      => \*HTML 
+    file      => 't.html'
 
-  # this will set clear the form element foo
-  $output = $fif->fill(scalarref => \$html,
-             fdat => { foo => "" });
+Fill Data options:
+
+    fobject   => $data_obj  # with param() method
+    fdat      => \%data
 
-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.
+Additional methods are also available:
 
-=back
+    fill_file(\*HTML,...);
+    fill_file('t.html',...);
+    fill_arrayref(\@html,...);
+    fill_scalarref(\$html,...);
 
 =head1 CALLING FROM OTHER MODULES
 
@@ -522,7 +612,7 @@ L<http://www.masonhq.com/?FAQ:HTTPAndHTML#h-how_can_i_populate_form_values_autom
 
 =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 @@ redistribute it and/or modify it under the same terms as Perl itself.
 
 =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!
@@ -36,9 +36,7 @@ my $q = new CGI( { foo1 => '0',
 	   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 @@ $q = new CGI( { foo1 => 'bar1',
 	   foo3 => '' }
 	);
 
-$fif = new HTML::FillInForm;
+my $fif = new HTML::FillInForm;
 $output = $fif->fill(scalarref => \$hidden_form_in,
                        fobject => $q);
 
@@ -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 @@ __HTML__
 
 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);
 
@@ -2,7 +2,7 @@
 
 use strict;
 use Test;
-BEGIN { plan tests => 3 }
+BEGIN { plan tests => 8 }
 
 use HTML::FillInForm;
 
@@ -16,6 +16,9 @@ my $form = <<EOF;
 <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 @@ my %fdat = (
   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 @@ my @v = $output =~ m/<input .*?value="(.*?)"/ig;
 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');
@@ -17,7 +17,7 @@ sub new{
 ###
 #End of Support::Object
 
-use Test::More tests => 30;
+use Test::More tests => 38;
 
 use_ok('HTML::FillInForm');
 
@@ -38,9 +38,9 @@ my $result = HTML::FillInForm->new->fill_scalarref(
                                          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 @@ $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.+one/, 'fill_arrayref 1');
-ok($result =~ /new val 2.+two/, 'fill_arrayref 2');
+{ 
+    $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->new->fill_file(
-                                         "t/data/form1.html",
-                                         fdat => {
-                                           one => "new val 1",
-                                           two => "new val 2",
-                                           three => "new val 3",
-                                         },
-                                         );
+{
+    $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');
+}
 
-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_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);
+}
 
 
 
@@ -92,8 +142,6 @@ $result = HTML::FillInForm->new->fill_scalarref(
                                          );
 };
 
-#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 @@ $result = HTML::FillInForm->new->fill_scalarref(
                                          );
 };
 
-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 @@ my %fdat = (foo1 => 'bar2');
 $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 @@ $html = qq{<INPUT TYPE="password" NAME="foo1">
 $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 @@ $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");
+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 @@ $html = qq[<div></div>
 $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 @@ $html = qq[<div></div>
 $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');
 
@@ -17,10 +17,7 @@ plan tests => (scalar @contents);
 
 # 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});
 }
@@ -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 @@ my $result = HTML::FillInForm->new->fill(
 
 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');