Catalyst::Model::CDBI - [DEPRECATED] CDBI Model Class


Catalyst-Model-CDBI documentation Contained in the Catalyst-Model-CDBI distribution.

Index


Code Index:

NAME

Top

Catalyst::Model::CDBI - [DEPRECATED] CDBI Model Class

SYNOPSIS

Top

    # use the helper
    create model CDBI CDBI dsn user password

    # lib/MyApp/Model/CDBI.pm
    package MyApp::Model::CDBI;

    use base 'Catalyst::Model::CDBI';

    __PACKAGE__->config(
        dsn           => 'dbi:Pg:dbname=myapp',
        password      => '',
        user          => 'postgres',
        options       => { AutoCommit => 1 },
        relationships => 1
    );

    1;

    # As object method
    $c->comp('MyApp::Model::CDBI::Table')->search(...);

    # As class method
    MyApp::Model::CDBI::Table->search(...);

DESCRIPTION

Top

This is the Class::DBI model class. It's built on top of Class::DBI::Loader. Class::DBI is generally not used for new applications, with DBIx::Class being preferred instead. As such this model is deprecated and (mostly) unmaintained.

It is preserved here for older applications which still need it for backwards compatibility.

new

Initializes Class::DBI::Loader and loads classes using the class config. Also attempts to borg all the classes.

SEE ALSO

Top

Catalyst, Class::DBI Class::DBI::Loader

AUTHOR

Top

Sebastian Riedel, sri@cpan.org

CONTRIBUTORS

Top

mst: Matt S Trout mst@shadowcat.co.uk

Arathorn: Matthew Hodgson matthew@arasphere.net

COPYRIGHT

Top


Catalyst-Model-CDBI documentation Contained in the Catalyst-Model-CDBI distribution.
package Catalyst::Model::CDBI;

# work around CDBI being incompatible with C3 mro, due to both Ima::DBI and Class::DBI::__::Base
# inheriting from Class::Data::Inheritable in an inconsistent order.
BEGIN {
    require Class::DBI;
    @Class::DBI::__::Base::ISA = grep { $_ ne 'Class::Data::Inheritable' } @Class::DBI::__::Base::ISA;
}

use strict;
use base qw/Catalyst::Component Class::DBI/;
use MRO::Compat;
use Class::DBI::Loader;

our $VERSION = '0.12';

__PACKAGE__->mk_accessors('loader');

sub new {
    my $class = shift;
    my $self  = $class->next::method( @_ );
    my $c     = shift;
    $self->{namespace}               ||= ref $self;
    $self->{additional_base_classes} ||= ();
    push @{ $self->{additional_base_classes} }, ref $self;
    eval { $self->loader( Class::DBI::Loader->new(%$self) ) };
    if ($@) { 
        Catalyst::Exception->throw( message => $@ );
    }
    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';
        *{"$class\::new"} = sub { bless {%$self}, $class };
    }
    return $self;
}

1;