my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs);
# -or-
- my $schema1 = My::Schema->connect();
+ my $schema1 = "My::Schema";
# ^^ defaults to dsn/user/pass from load_from_connection()
=head1 DESCRIPTION
-DBIx::Class::Schema::Loader automate the definition of a
+DBIx::Class::Schema::Loader automates the definition of a
DBIx::Class::Schema by scanning table schemas and setting up
columns and primary keys.
L<DBIx::Class::Schema::Loader::Writing> for notes on writing your own
db-specific subclass for an unsupported db.
-L<Class::DBI::Loader>, L<Class::DBI>, and L<DBIx::Class::Loader> are now
-obsolete, use L<DBIx::Class> and this module instead. ;)
+This module obsoletes L<DBIx::Class::Loader> for L<DBIx::Class> version 0.5
+and later.
=cut
=head1 METHODS
-=head2 new
+=head2 load_from_connection
Example in Synopsis above demonstrates the available arguments. For
detailed information on the arguments, see the
sub load_from_connection {
my ( $class, %args ) = @_;
- foreach (qw/namespace dsn/) {
- die qq/Argument $_ is required/ if ! $args{$_};
- }
+ die qq/dsn argument is required/ if ! $args{dsn};
+ $args{namespace} ||= $class;
$args{namespace} =~ s/(.*)::$/$1/;
my $dsn = $args{dsn};
my $impl = "DBIx::Class::Schema::Loader::" . $driver;
$impl->require or
- die qq/Couldn't require loader class "$impl", "$UNIVERSAL::require::ERROR"/;
+ die qq/Couldn't require loader class "$impl",/ .
+ qq/"$UNIVERSAL::require::ERROR"/;
push(@ISA, $impl);
$class->_load_from_connection(%args);
=head1 AUTHOR
-Sebastian Riedel, C<sri@oook.de>
+Brandon Black, C<bblack@gmail.com>
+
+Sebastian Riedel, C<sri@oook.de> (DBIx::Class::Loader, which this module is branched from)
Based upon the work of IKEBE Tomohiro
__PACKAGE__->mk_classdata('loader_data');
-# XXX convert all usage of $class/$self->debug to ->debug_loader
-
=head1 NAME
DBIx::Class::Schema::Loader::Generic - Generic DBIx::Class::Schema::Loader Implementation.
$class->loader_data({
_datasource =>
[ $args{dsn}, $args{user}, $args{password}, $args{options} ],
- _namespace => $args{namespace} || $class,
+ _namespace => $args{namespace},
_additional => $additional,
_additional_base => $additional_base,
_left_base => $left_base,
});
$class->connection(@{$class->loader_data->{_datasource}});
- warn qq/\### START DBIx::Class::Schema::Loader dump ###\n/ if $class->debug;
+ warn qq/\### START DBIx::Class::Schema::Loader dump ###\n/ if $class->debug_loader;
$class->_load_classes;
$class->_relationships if $class->loader_data->{_relationships};
- warn qq/\### END DBIx::Class::Schema::Loader dump ###\n/ if $class->debug;
+ warn qq/\### END DBIx::Class::Schema::Loader dump ###\n/ if $class->debug_loader;
$class->storage->dbh->disconnect; # XXX this should be ->storage->disconnect later?
1;
# Returns the moniker for a given table name,
# for use in $conn->resultset($moniker)
+
+=head3 moniker
+
+Returns the moniker for a given literal table name. Used
+as $schema->resultset($moniker), etc.
+
+=cut
sub moniker {
my ( $class, $table ) = @_;
return $class->loader_data->{MONIKERS}->{$table};
}
-=head3 debug
+=head3 debug_loader
-Overload to enable debug messages.
+Overload to enable Loader debug messages.
=cut
-sub debug { 0 }
+sub debug_loader { 0 }
=head3 tables
my $table_class = $class->_find_table_class($table);
my $other_class = $class->_find_table_class($other);
- warn qq/\# Belongs_to relationship\n/ if $class->debug;
+ warn qq/\# Belongs_to relationship\n/ if $class->debug_loader;
if($other_column) {
warn qq/$table_class->belongs_to( '$column' => '$other_class',/
. qq/ { "foreign.$other_column" => "self.$column" },/
. qq/ { accessor => 'filter' });\n\n/
- if $class->debug;
+ if $class->debug_loader;
$table_class->belongs_to( $column => $other_class,
{ "foreign.$other_column" => "self.$column" },
{ accessor => 'filter' }
}
else {
warn qq/$table_class->belongs_to( '$column' => '$other_class' );\n\n/
- if $class->debug;
+ if $class->debug_loader;
$table_class->belongs_to( $column => $other_class );
}
if $class->loader_data->{_inflect}
and exists $class->loader_data->{_inflect}->{ lc $table_class_base };
- warn qq/\# Has_many relationship\n/ if $class->debug;
+ warn qq/\# Has_many relationship\n/ if $class->debug_loader;
if($other_column) {
warn qq/$other_class->has_many( '$plural' => '$table_class',/
. qq/ { "foreign.$column" => "self.$other_column" } );\n\n/
- if $class->debug;
+ if $class->debug_loader;
$other_class->has_many( $plural => $table_class,
{ "foreign.$column" => "self.$other_column" }
);
else {
warn qq/$other_class->has_many( '$plural' => '$table_class',/
. qq/'$other_column' );\n\n/
- if $class->debug;
+ if $class->debug_loader;
$other_class->has_many( $plural => $table_class, $column );
}
}
$class->inject_base( $table_class, 'DBIx::Class::Core' );
$_->require for @db_classes;
$class->inject_base( $table_class, $_ ) for @db_classes;
- warn qq/\# Initializing table "$table_name_db_schema" as "$table_class"\n/ if $class->debug;
+ warn qq/\# Initializing table "$table_name_db_schema" as "$table_class"\n/ if $class->debug_loader;
$table_class->table(lc $table_name_db_schema);
my ( $cols, $pks ) = $class->_table_info($table_name_db_schema);
$table_class->set_primary_key(@$pks) if @$pks;
my $code = "package $table_class;\n$additional_base$additional$left_base";
- warn qq/$code/ if $class->debug;
- warn qq/$table_class->table('$table_name_db_schema');\n/ if $class->debug;
+ warn qq/$code/ if $class->debug_loader;
+ warn qq/$table_class->table('$table_name_db_schema');\n/ if $class->debug_loader;
my $columns = join "', '", @$cols;
- warn qq/$table_class->add_columns('$columns')\n/ if $class->debug;
+ warn qq/$table_class->add_columns('$columns')\n/ if $class->debug_loader;
my $primaries = join "', '", @$pks;
- warn qq/$table_class->set_primary_key('$primaries')\n/ if $class->debug && @$pks;
+ warn qq/$table_class->set_primary_key('$primaries')\n/ if $class->debug_loader && @$pks;
eval $code;
croak qq/Couldn't load additional classes "$@"/ if $@;
unshift @{"$table_class\::ISA"}, $_ foreach ( @{ $class->loader_data->{_left_base} } );
eval { $class->_belongs_to_many( $table, $column, $other,
$other_column ) };
warn qq/\# belongs_to_many failed "$@"\n\n/
- if $@ && $class->debug;
+ if $@ && $class->debug_loader;
}
}
}
if ( $col =~ /^(\w+).*REFERENCES\s+(\w+)\s*(\w+)?/i ) {
chomp $col;
warn qq/\# Found foreign key definition "$col"\n\n/
- if $class->debug;
+ if $class->debug_loader;
eval { $class->_belongs_to_many( $table, $1, $2, $3 ) };
warn qq/\# belongs_to_many failed "$@"\n\n/
- if $@ && $class->debug;
+ if $@ && $class->debug_loader;
}
}
}
use strict;
use base 'DBIx::Class::Schema::Loader::Generic';
- use DBI;
use Carp;
sub _db_classes {
}
sub _tables {
- my $self = shift;
- my $dbh = $self->{_storage}->dbh;
+ my $class = shift;
+ my $dbh = $class->storage->dbh;
return $dbh->tables; # Your DBD may need something different
}
sub _table_info {
- my ( $self, $table ) = @_;
+ my ( $class, $table ) = @_;
...
return ( \@cols, \@primary );
}
sub _relationships {
- my $self = shift;
+ my $class = shift;
...
- $self->_belongs_to_many($table, $f_key, $f_table, $f_column);
+ $class->_belongs_to_many($table, $f_key, $f_table, $f_column);
# For each relationship you want to set up ($f_column is
# optional, default is $f_table's primary key)
...
my $remote_column = shift @cols;
eval { $class->_belongs_to_many( $table, $column, $remote_table, $remote_column) };
- warn qq/\# belongs_to_many failed "$@"\n\n/ if $@ && $class->debug;
+ warn qq/\# belongs_to_many failed "$@"\n\n/ if $@ && $class->debug_loader;
}
$sth->finish;
use strict;
use lib qw( ./t );
-use dbixcl_common_tests;
+use dbixcsl_common_tests;
eval { require DBD::SQLite };
my $class = $@ ? 'SQLite2' : 'SQLite';
{
- my $tester = dbixcl_common_tests->new(
+ my $tester = dbixcsl_common_tests->new(
vendor => 'SQLite',
auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY',
dsn => "dbi:$class:dbname=./t/sqlite_test",
use strict;
use lib qw( . ./t );
-use dbixcl_common_tests;
+use dbixcsl_common_tests;
my $database = $ENV{MYSQL_NAME} || '';
my $user = $ENV{MYSQL_USER} || '';
my $skip_rels_msg = 'You need to set the MYSQL_TEST_INNODB environment variable to test relationships';
-my $tester = dbixcl_common_tests->new(
+my $tester = dbixcsl_common_tests->new(
vendor => 'Mysql',
auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT',
innodb => q{Engine='InnoDB'},
use strict;
use lib qw( . ./t );
-use dbixcl_common_tests;
+use dbixcsl_common_tests;
my $database = $ENV{PG_NAME} || '';
my $user = $ENV{PG_USER} || '';
my $password = $ENV{PG_PASS} || '';
-my $tester = dbixcl_common_tests->new(
+my $tester = dbixcsl_common_tests->new(
vendor => 'Pg',
auto_inc_pk => 'SERIAL NOT NULL PRIMARY KEY',
dsn => "dbi:Pg:dbname=$database",
use strict;
use lib qw( . ./t );
-use dbixcl_common_tests;
+use dbixcsl_common_tests;
my $database = $ENV{DB2_NAME} || '';
my $user = $ENV{DB2_USER} || '';
my $password = $ENV{DB2_PASS} || '';
-my $tester = dbixcl_common_tests->new(
+my $tester = dbixcsl_common_tests->new(
vendor => 'DB2',
auto_inc_pk => 'SERIAL NOT NULL PRIMARY KEY',
dsn => "dbi:DB2:$database",
-package dbixcl_common_tests;
+package dbixcsl_common_tests;
use strict;
$self->create();
- my $namespace = 'DBIXCL_Test_' . $self->{vendor};
+ my $namespace = 'DBIXCSL_Test_' . $self->{vendor};
my $debug = ($self->{verbose} > 1) ? 1 : 0;