Re: [CDBI] Trouble with Perl's reverse function
Carlos Vicente <cvicente-zZ82ZiX1S8l+u43qRgrggVnYRNhDb3e+9nwVQlTi/[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
Hi Randall,
Sorry for the excessive abstraction.
Here it goes, with more context. In my class hierarchy, MyApp::Model
inherits from Class::DBI.
----
package MyApp::Model::Zone;
use base 'MyApp::Model';
use warnings;
use strict;
use Data::Dumper;
my $logger = MyApp->log->get_logger('MyApp::Model');
sub find_by_name {
my ($class, $name) = @_;
my (@sections, $lastfound);
$class->isa_class_method('find_by_name');
$logger->debug("Looking for zone: $name");
my @words = reverse split /\./, $name;
foreach my $word ( @words ){
push @sections, $word;
my $domain = join '.', reverse @sections;
$logger->debug("Looking for zone: $domain");
if ( my $zone = ($class->search( mname => $domain ))[0] ){
$lastfound = $zone;
}
}
$logger->debug("Found zone: ", $lastfound->mname);
return $lastfound;
}
-----
I'm testing with the following script:
#!/usr/bin/perl -w
use MyApp::Model::Zone;
my $zone = Zone->find_by_name('foo.bar');
print $zone->mname if $zone;
Which returns:
Can't locate object method "set" via package "foo" (perhaps you forgot
to load "foo"?) at /usr/lib/perl5/site_perl/5.8.7/Class/Accessor.pm line
390.
cv