[CDBI] Delay Inflate

Bill Moseley moseley at hank.org
Sat Jan 7 17:52:41 GMT 2006


Oh, who can catch my dumb mistake.

Trying another approach overriding get() instead.

This is kind of ugly, but it generates:

  Can't call method "time_zone" without a package or object reference

because $item->location is not returning an object, just the value.

sub get {
    my ( $item, @cols ) = @_;
    my @values = $item->SUPER::get( @cols );

    for my $i (0.. at values-1) {
        my $col = $cols[$i];
        next unless $col =~ /_time$/;
        next if $item->{$col . '_zoneset'}++;  # ouch

        $values[$i]->set_time_zone( $item->location->time_zone->name );
        $item->_attribute_store( $col, $values[$i] );
    }

    return @values;

}



Yet, overriding the accessor name in my previous post works.  Isn't
the accessor just a thin wrapper around get()?

sub my_time_column { shift->_set_time_zone( 'my_time_column', @_ ) }

sub _set_time_zone {
    my ( $item, $col, $dt ) = @_;
    return $item->set( $col, $dt ) if defined $dt;

    $dt = $item->get($col);

    return $dt if $item->{$col . '_zoneset'}++;  # ouch

    $dt->set_time_zone( $item->location->time_zone->name );
    $item->_attribute_store( $col, $dt );  # don't want t flag as updated
    return $dt;

}



-- 
Bill Moseley
moseley at hank.org





More information about the ClassDBI mailing list