Re: [CDBI] has_a infation of a Time::Piece woes

[prev] [thread] [next] [Date index for 2005/10/24]

From: Peter Speltz
Subject: Re: [CDBI] has_a infation of a Time::Piece woes
Date: 17:04 on 24 Oct 2005
On 10/24/05, William Ross <will@xxxxxxx.xxx> wrote:
> > <snip>
> >
> > For (1) I tried blessing an empty array into Time::Piece. Same out of
> > range error.
> >
> > So i tried this for (2)  which from reading the docs , seems it
> > should work. :
> >
> > __PACKAGE__->has_a("finished" =3D> 'Time::Piece',
> >         inflate =3D> sub {
> >             my $t =3D shift;
> >             if ($t =3D~ /^0000-/) {
> >                   return;  # This makes Time::Piece have current time.
> >                   # return 0;      # Has beginning of epoch (Jan 1
> > 1970)
> >             }
> >             else {
> >                 return Time::Piece->strptime($t, "%Y-%m-%d %T");
> >             }
> >         },
> >       . . .
> > );
> >
> >
> > But what is happening is the value my inflate sub returns is getting
> > passed to the Time::Piece constructor so i am getting some Times i do
> > not want..
>
> Have you overridden _croak()? Your code wouldn't normally work
> because Class::DBI::Relationship::HasA will call _croak if the return
> value of the custom inflation method is not blessed into the class it
> expects to see. Which isn't very helpful in your case.

No i have not overridden _croak to do this. Apparently if the custom
inflate method does not return a  object , then it will pass that onto
the constructor. Maybe the docs need updated.

>
> I'd suggest you write a simple subclass of Time::Piece that
> stringifies the way you want it to.
>

Argh. That does not sound fun but maybe what I have to do. I'm reall
surprised you cannot have a Time:;Piece object without a defined time.
 There is probably good reason for it though.

thanks

[CDBI] has_a infation of a Time::Piece woes
Peter Speltz 16:31 on 24 Oct 2005

Re: [CDBI] has_a infation of a Time::Piece woes
Perrin Harkins 16:38 on 24 Oct 2005

Re: [CDBI] has_a infation of a Time::Piece woes
William Ross 16:47 on 24 Oct 2005

Re: [CDBI] has_a infation of a Time::Piece woes
Peter Speltz 17:04 on 24 Oct 2005

Re: [CDBI] has_a infation of a Time::Piece woes
William Ross 18:25 on 24 Oct 2005

Generated at 14:18 on 27 Oct 2005 by mariachi v0.52