[Dbix-class] Problem getting data from resultset

Patrick Meidl patrick at pantheon.at
Fri Jul 6 16:07:10 GMT 2012


On Fri, Jul 06 2012, Kenneth S Mclane <ksmclane at us.ibm.com> wrote:

> > perl doesn't eval $data->$field in the way you expect it to. you would
> > have to do something like
> > 
> > my $val = $data;
> > foreach my $method (split(/\./, $field)) {
> >     $val = $val->$method;
> > }
> > $ws->write($row, $col, $val);
> > 
> > to make your code more robust, you should add some sanity checking, like
> > 
> > if ($val->can($method)) { ... }
> > 
> > HTH
> > 
> >     patrick
> > 
> > -- 
> > Patrick Meidl ........................ patrick at pantheon.at
> 
> I'm almost there, having some issues with null values. I keep getting an 
> error about not being able to perform object method on an undefined etc. I 
> can't find my way around it. I tried this and it sets it to 0 but still 
> bombs out with the same error.

foreach my $method (split(/\./, $field)) {
    last unless ($val);
    $val = $val->$method;
}

should solve this.

    patrick

-- 
Patrick Meidl ........................ patrick at pantheon.at
Vienna, Austria ...................... http://gplus.to/pmeidl




More information about the DBIx-Class mailing list