Re: Calculation of non-database columns
[prev]
[thread]
[next]
[Date index for 2005/06/04]
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