Re: Calculation of non-database columns

[prev] [thread] [next] [Date index for 2005/06/04]

From: Uwe Voelker
Subject: Re: Calculation of non-database columns
Date: 11:56 on 04 Jun 2005
Hello Cees,

> As for your has_a question, your missing class above would just be
> 'DateTime::Duration'.  But I don't think you can use has_a with a TEMP
> column.

Okay, this is what I wanted to know. I also have a second calculation 
which multiplies a timespan with a number (hourly wage), so this time 
there would be definitively no class.

> Is there a reason that the simple function I provided is not adequate?

No, your function is very fine. I already use it. I just wanted to know 
if there is another way. I felt there must be, but it seem's it isn't.

> It exists in your Class::DBI table class, and it looks and works just
> like a Class::DBI column works except that it is readonly (you might
> want to improve the function to enforce that).  Is it missing a
> feature that is needed?

No feature is missing. And readonly is no problem.
But consider I would like to add a cache. I could do something like this:

sub duration {
     my $self = shift;

     $self->{duration} ||= $self->to - $self->from;

     return $self->{duration};
}

So I would cache the result inside $self. My last question for this: 
What keys can or should I use? Would 'duration' be fine, or is 
'_duration' better? Or should this be avoided at all?


Thank you,

bye,
Uwe

Calculation of non-database columns
Uwe Voelker 21:21 on 02 Jun 2005

Re: Calculation of non-database columns
Cees Hek 23:02 on 02 Jun 2005

Re: Calculation of non-database columns
Uwe Voelker 09:57 on 03 Jun 2005

Re: Calculation of non-database columns
Cees Hek 15:46 on 03 Jun 2005

Re: Calculation of non-database columns
Uwe Voelker 11:56 on 04 Jun 2005

Generated at 16:36 on 28 Jul 2005 by mariachi v0.52