[html-formfu] HTML::FormFu::Inflator::DateTime

Will Hawes wdhawes at gmail.com
Thu Jul 31 22:23:38 BST 2008


The docs for HTML::FormFu::Inflator::DateTime have the following
(slightly boiled down) example:

      - type: Text
        name: end_time
        inflators:
          - type: DateTime
            parser:
              regex: '^ (\d{2}) - (\d{2}) - (\d{4}) $'

On my machine, with HTML::FormFu 0.3001 and DateTime::Format::Builder
0.7901, this results in:

Caught exception in ... "The 'regex' parameter ("^ (\d{2}) - (\d{2}) -
(\d{4}) $") to DateTime::Format::Builder::Parser::create_single_parser
was a 'scalar', which is not one of the allowed types: scalarref
 at /usr/local/share/perl/5.8.8/DateTime/Format/Builder/Parser.pm line 311

DateTime::Format::Builder::Parser expects the "regex" parameter to be
a scalar ref containing a compiled regex, so the string supplied in
the example won't work. This patch fixes it:

===================================================================
--- FormFu/Inflator/DateTime.pm	(revision 1089)
+++ FormFu/Inflator/DateTime.pm	(working copy)
@@ -19,10 +19,14 @@

 sub parser {
     my $self = shift;
+	my $arg = shift;

-    $self->_builder->parser(@_);
+	my $regex = $arg->{regex};
+	$arg->{regex} = qr/$regex/ if $regex;

-    return $self;
+	$self->_builder->parser($arg);
+
+	return $self;
 }

Any objections to me committing this? Anything I've missed?



More information about the HTML-FormFu mailing list