Not sure if this should go to this list, but also not sure where else to put 
this.

Writing a small app and I'm using HTML::FormHandler::Moose with an SQLite 
database.  I have a table which looks like this (not really, but close enough):

  CREATE TABLE person (
      id         INTEGER PRIMARY KEY AUTOINCREMENT,
      person     TEXT NOT NULL,
      notes      TEXT NOT NULL,
      birth      DATE NOT NULL,
      created    TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  ); 
In my formhandler class, it looks like this:

    package My::Form::Person;

    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler::Model::DBIC';
    use namespace::autoclean;

    has '+name'       => ( default => 'person' );
    has '+item_class' => ( default => 'Person' );
    has 'post'        => ( isa     => 'My::Model::DB::Person', is => 'rw' );

    has_field 'person' => ( label => 'Person', );
    has_field 'birth'  => ( type  => 'DateTime' );
    has_field 'birth.month' => ( type => 'Month' );
    has_field 'birth.day'   => ( type => 'MonthDay' );
    has_field 'birth.year'  => (
        type        => 'Year',
        range_start => '1930',
        range_end   => '1999',
    );
    has_field 'notes' => ( label    => 'Notes' );
    has_field 'submit' => ( type => 'Submit', value => 'Create Person' );

    __PACKAGE__->meta->make_immutable;

    1;

When I try to create a person, the form renders just fine (I'm just using [% 
form.render %]), but when I try to edit a person.  Creating the person is fine 
and is stored in the database.  However, when I try to edit this person, I get 
the following error:

Caught exception in My::Controller::Person->edit "Can't use string 
("1930-01-01T00:00:00") as a HASH ref while "strict refs" in use at 
/Library/Perl/5.10.1/HTML/FormHandler/InitResult.pm line 111."

In other words, it's clearly working for post, but in reading the data from the 
database, it's failing.

I've also tried this:

  has_field 'birth' => (
      type    => 'Compound',
      actions => [ { transform => sub { DateTime->new( $_[0] ) } } ],
  );

But it gives me the same error.

What am I doing wrong?  (I also tried installing the latest version from 
github. Same thing).

Cheers,
Ovid
--
Buy the book         - http://www.oreilly.com/catalog/perlhks/
Tech blog            - http://blogs.perl.org/users/ovid/
Twitter              - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Reply via email to