[Catalyst] Catalyst::Model::CDBI::Sweet, Class::DBI::Loader and inheritance

Will Hawes info at whawes.co.uk
Thu May 5 11:22:25 CEST 2005


> What I do to get around similar problems is unshift my own Base class  
> into the ISA for the loaded classes, after the loader runs.
> 
> Something like:
> 
> sub new {
>      my $class = shift;
> 
>      my $self = $class->NEXT::new(@_);
> 
>      foreach my $subclass ( $self->loader->classes ) {
>          {
>              no strict 'refs';
>              unshift @{ $subclass . "::ISA" }, 'MyApp::CDBI::Base';
>          }
>          $subclass->autoupdate(0);
>      }
> 
>      return $self;
> }
> 
> and then MyApp::CDBI::Base can 'use base  
> Catalyst::Model::CDBI::Sweet' ..
> 
> Maybe something similar will work for you..?

I tried adding this into Catalyst::Model::CDBI:

sub new {
    my ( $self, $c ) = @_;
    $self = $self->NEXT::new($c);
    $self->{namespace}               ||= ref $self;
    $self->{additional_base_classes} ||= ();
    push @{ $self->{additional_base_classes} }, ref $self;
    eval { $self->loader( Class::DBI::Loader->new(%$self) ) };
    if ($@) { $c->log->debug(qq/Couldn't load tables "$@"/) if $c->debug }
    else {
        $c->log->debug(
            'Loaded tables "' . join( ' ', $self->loader->tables ) . '"' )
          if $c->debug;
    }
    for my $class ( $self->loader->classes ) {
        $class->autoupdate(1);
        $c->components->{$class} ||= bless {%$self}, $class;
        no strict 'refs';
        unshift @{ $class . "::ISA" }, 'Catalyst::Model::CDBI::Sweet';
        *{"$class\::new"} = sub { bless {%$self}, $class };
    }
    return $self;
}

When I try to run server.pl I get an error similar to this for every class:

Can't locate package Catalyst::Model::CDBI::Sweet for @Hops::M::CDBI::Beer::ISA
at C:/Perl/site/lib/Catalyst/Model/CDBI.pm line 73.

Weird, because Catalyst::Model::CDBI::Sweet is installed and otherwise working correctly.

Regards

WH




More information about the Catalyst mailing list