[Dbix-class] Problem getting data from resultset
Patrick Meidl
patrick at pantheon.at
Fri Jul 6 20:29:41 GMT 2012
On Fri, Jul 06 2012, Kenneth S Mclane <ksmclane at us.ibm.com> wrote:
> > Subject:
> >
> > Re: [Dbix-class] Problem getting data from resultset
> >
> >
> > foreach my $method (split(/\./, $field)) {
> > last unless ($val);
> > $val = $val->$method;
> > }
> >
> > should solve this.
> >
> That just causes an infinite loop somewhere.
unless you modifiy the iteration list inside your loop, you can't get an
infinite loop with foreach.
> I have been trying an if
> (exists $val->$method) { $val= $val->$method; } else { $val = 0; }, but
> that gets me this:
> exists argument is not a subroutine name at
> /opt/catalyst/dbms/script/../lib/dbms/Controller/AccountView.pm line 71.
'exists' tests the existence of hash keys, array elements and subroutine
names, not object methods (see 'perldoc perlfunc'). as I mentioned
before, you should use can() for this. so something like this should put
you on the right track:
foreach my $method (split(/\./, $field)) {
if (defined($val) and ref($val) and $val->can($method)) {
$val = $val->$method;
} else {
# this is not required, but shortcuts the processing
last;
}
}
HTH
patrick
--
Patrick Meidl ........................ patrick at pantheon.at
Vienna, Austria ...................... http://gplus.to/pmeidl
More information about the DBIx-Class
mailing list