[CDBI] Trouble with Perl's reverse function

Carlos Vicente cvicente at network-services.uoregon.edu
Tue Nov 14 20:47:58 GMT 2006


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



More information about the ClassDBI mailing list