From: Brandon Black Date: Sat, 21 Jan 2006 21:59:34 +0000 (+0000) Subject: first functional commit of non-subclassed-style Schema::Loader X-Git-Tag: 0.03000~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=18fca96ada05368ead5bb38b5c868e9c4d5c0c07;p=dbsrgits%2FDBIx-Class-Schema-Loader.git first functional commit of non-subclassed-style Schema::Loader --- diff --git a/lib/DBIx/Class/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm similarity index 62% rename from lib/DBIx/Class/Loader.pm rename to lib/DBIx/Class/Schema/Loader.pm index 7c7868e..75318cf 100644 --- a/lib/DBIx/Class/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -1,4 +1,4 @@ -package DBIx::Class::Loader; +package DBIx::Class::Schema::Loader; use strict; use UNIVERSAL::require; @@ -7,13 +7,13 @@ our $VERSION = '0.01'; =head1 NAME -DBIx::Class::Loader - Dynamic definition of DBIx::Class sub classes. +DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema =head1 SYNOPSIS - use DBIx::Class::Loader; + use DBIx::Class::Schema::Loader; - my $loader = DBIx::Class::Loader->new( + my $loader = DBIx::Class::Schema::Loader->new( dsn => "dbi:mysql:dbname", user => "root", password => "", @@ -28,8 +28,8 @@ DBIx::Class::Loader - Dynamic definition of DBIx::Class sub classes. debug => 1, ); - my $conn = $loader->get_connection($dsn, $user, $password); # - my $conn = $loader->get_connection(); # uses same dsn as ->new(); + my $conn = $loader->connection($dsn, $user, $password); # + my $conn = $loader->connection(); # uses same dsn as ->new(); use with mod_perl @@ -49,29 +49,23 @@ in your web application. use strict; # you can use Data::Film directly - my $film = Data::Film->retrieve($id); - + my $conn = $loader->connection(); + my $film_moniker = $loader->moniker('film'); + my $a_film = $conn->resultset($film_moniker)->find($id); =head1 DESCRIPTION -DBIx::Class::Loader automate the definition of DBIx::Class sub-classes by -scanning table schemas and setting up columns and primary keys. - -Class names are defined by table names and the namespace option, which is -required. - - +---------+-----------+--------------+ - | table | namespace | class | - +---------+-----------+--------------+ - | foo | Data | Data::Foo | - | foo_bar | MyDB | MyDB::FooBar | - +---------+-----------+--------------+ +DBIx::Class::Schema::Loader automate the definition of a +DBIx::Class::Schema by scanning table schemas and setting up +columns and primary keys. -DBIx::Class::Loader supports MySQL, Postgres, SQLite and DB2. See -L for more, and L -for notes on writing your own db-specific subclass for an unsupported db. +DBIx::Class::Schema::Loader supports MySQL, Postgres, SQLite and DB2. See +L for more, and +L for notes on writing your own +db-specific subclass for an unsupported db. -L and L are now obsolete, use L and this module instead. ;) +L, L, and L are now +obsolete, use L and this module instead. ;) =cut @@ -81,7 +75,7 @@ L and L are now obsolete, use L and Example in Synopsis above demonstrates the available arguments. For detailed information on the arguments, see the -L documentation. +L documentation. =cut @@ -97,7 +91,7 @@ sub new { my $dsn = $args{dsn}; my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i; $driver = 'SQLite' if $driver eq 'SQLite2'; - my $impl = "DBIx::Class::Loader::" . $driver; + my $impl = "DBIx::Class::Schema::Loader::" . $driver; $impl->require or die qq/Couldn't require loader class "$impl", "$UNIVERSAL::require::ERROR"/; diff --git a/lib/DBIx/Class/Loader/DB2.pm b/lib/DBIx/Class/Schema/Loader/DB2.pm similarity index 82% rename from lib/DBIx/Class/Loader/DB2.pm rename to lib/DBIx/Class/Schema/Loader/DB2.pm index 8dce7e1..70a22b6 100644 --- a/lib/DBIx/Class/Loader/DB2.pm +++ b/lib/DBIx/Class/Schema/Loader/DB2.pm @@ -1,20 +1,20 @@ -package DBIx::Class::Loader::DB2; +package DBIx::Class::Schema::Loader::DB2; use strict; -use base 'DBIx::Class::Loader::Generic'; +use base 'DBIx::Class::Schema::Loader::Generic'; use DBI; use Carp; =head1 NAME -DBIx::Class::Loader::DB2 - DBIx::Class::Loader DB2 Implementation. +DBIx::Class::Schema::Loader::DB2 - DBIx::Class::Schema::Loader DB2 Implementation. =head1 SYNOPSIS - use DBIx::Class::Loader; + use DBIx::Schema::Class::Loader; - # $loader is a DBIx::Class::Loader::DB2 - my $loader = DBIx::Class::Loader->new( + # $loader is a DBIx::Class::Schema::Loader::DB2 + my $loader = DBIx::Class::Schema::Loader->new( dsn => "dbi:DB2:dbname", user => "myuser", password => "", @@ -22,12 +22,10 @@ DBIx::Class::Loader::DB2 - DBIx::Class::Loader DB2 Implementation. schema => "MYSCHEMA", dropschema => 0, ); - my $class = $loader->find_class('film'); # $class => Data::Film - my $obj = $class->retrieve(1); =head1 DESCRIPTION -See L. +See L. =cut @@ -90,7 +88,7 @@ SQL =head1 SEE ALSO -L +L =cut diff --git a/lib/DBIx/Class/Loader/Generic.pm b/lib/DBIx/Class/Schema/Loader/Generic.pm similarity index 95% rename from lib/DBIx/Class/Loader/Generic.pm rename to lib/DBIx/Class/Schema/Loader/Generic.pm index a1b4744..70bca82 100644 --- a/lib/DBIx/Class/Loader/Generic.pm +++ b/lib/DBIx/Class/Schema/Loader/Generic.pm @@ -1,4 +1,4 @@ -package DBIx::Class::Loader::Generic; +package DBIx::Class::Schema::Loader::Generic; use strict; use base 'DBIx::Class::Componentised'; @@ -11,11 +11,11 @@ require DBIx::Class::Schema; =head1 NAME -DBIx::Class::Loader::Generic - Generic DBIx::Class::Loader Implementation. +DBIx::Class::Schema::Loader::Generic - Generic DBIx::Class::Schema::Loader Implementation. =head1 SYNOPSIS -See L +See L =head1 DESCRIPTION @@ -79,7 +79,7 @@ Username. =head3 new Not intended to be called directly. This is used internally by the -C method in L. +C method in L. =cut @@ -113,10 +113,10 @@ sub new { TABLE_CLASSES => {}, MONIKERS => {}, }, $class; - warn qq/\### START DBIx::Class::Loader dump ###\n/ if $self->debug; + warn qq/\### START DBIx::Class::Schema::Loader dump ###\n/ if $self->debug; $self->_load_classes; $self->_relationships if $self->{_relationships}; - warn qq/\### END DBIx::Class::Loader dump ###\n/ if $self->debug; + warn qq/\### END DBIx::Class::Schema::Loader dump ###\n/ if $self->debug; $self->{_storage}->dbh->disconnect; $self; } @@ -321,7 +321,7 @@ sub _table_info { croak "ABSTRACT METHOD" } =head1 SEE ALSO -L +L =cut diff --git a/lib/DBIx/Class/Loader/Pg.pm b/lib/DBIx/Class/Schema/Loader/Pg.pm similarity index 73% rename from lib/DBIx/Class/Loader/Pg.pm rename to lib/DBIx/Class/Schema/Loader/Pg.pm index a44db20..6bc4f80 100644 --- a/lib/DBIx/Class/Loader/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/Pg.pm @@ -1,31 +1,29 @@ -package DBIx::Class::Loader::Pg; +package DBIx::Class::Schema::Loader::Pg; use strict; -use base 'DBIx::Class::Loader::Generic'; +use base 'DBIx::Class::Schema::Loader::Generic'; use DBI; use Carp; =head1 NAME -DBIx::Class::Loader::Pg - DBIx::Class::Loader Postgres Implementation. +DBIx::Class::Schema::Loader::Pg - DBIx::Class::Schema::Loader Postgres Implementation. =head1 SYNOPSIS - use DBIx::Class::Loader; + use DBIx::Class::Schema::Loader; - # $loader is a DBIx::Class::Loader::Pg - my $loader = DBIx::Class::Loader->new( + # $loader is a DBIx::Class::Schema::Loader::Pg + my $loader = DBIx::Class::Schema::Loader->new( dsn => "dbi:Pg:dbname=dbname", user => "postgres", password => "", namespace => "Data", ); - my $class = $loader->find_class('film'); # $class => Data::Film - my $obj = $class->retrieve(1); =head1 DESCRIPTION -See L. +See L. =cut @@ -64,7 +62,7 @@ sub _table_info { =head1 SEE ALSO -L +L =cut diff --git a/lib/DBIx/Class/Loader/SQLite.pm b/lib/DBIx/Class/Schema/Loader/SQLite.pm similarity index 89% rename from lib/DBIx/Class/Loader/SQLite.pm rename to lib/DBIx/Class/Schema/Loader/SQLite.pm index 61be9ab..70859dd 100644 --- a/lib/DBIx/Class/Loader/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/SQLite.pm @@ -1,30 +1,28 @@ -package DBIx::Class::Loader::SQLite; +package DBIx::Class::Schema::Loader::SQLite; use strict; -use base 'DBIx::Class::Loader::Generic'; +use base 'DBIx::Class::Schema::Loader::Generic'; use Text::Balanced qw( extract_bracketed ); use DBI; use Carp; =head1 NAME -DBIx::Class::Loader::SQLite - DBIx::Class::Loader SQLite Implementation. +DBIx::Class::Schema::Loader::SQLite - DBIx::Class::Schema::Loader SQLite Implementation. =head1 SYNOPSIS - use DBIx::Class::Loader; + use DBIx::Class::Schema::Loader; - # $loader is a DBIx::Class::Loader::SQLite - my $loader = DBIx::Class::Loader->new( + # $loader is a DBIx::Class::Schema::Loader::SQLite + my $loader = DBIx::Class::Schema::Loader->new( dsn => "dbi:SQLite:dbname=/path/to/dbfile", namespace => "Data", ); - my $class = $loader->find_class('film'); # $class => Data::Film - my $obj = $class->retrieve(1); =head1 DESCRIPTION -See L. +See L. =cut @@ -144,7 +142,7 @@ SQL =head1 SEE ALSO -L +L =cut diff --git a/lib/DBIx/Class/Loader/Writing.pm b/lib/DBIx/Class/Schema/Loader/Writing.pm similarity index 81% rename from lib/DBIx/Class/Loader/Writing.pm rename to lib/DBIx/Class/Schema/Loader/Writing.pm index 5fd54f3..8b25d4b 100644 --- a/lib/DBIx/Class/Loader/Writing.pm +++ b/lib/DBIx/Class/Schema/Loader/Writing.pm @@ -1,4 +1,4 @@ -package DBIx::Class::Loader::Writing; +package DBIx::Class::Schema::Loader::Writing; # Empty. POD only. @@ -6,16 +6,16 @@ package DBIx::Class::Loader::Writing; =head1 NAME -DBIx::Class::Loader::Writing - Loader subclass writing guide +DBIx::Class::Schema::Loader::Writing - Loader subclass writing guide =head1 SYNOPSIS - package DBIx::Class::Loader::Foo; + package DBIx::Class::Schema::Loader::Foo; # THIS IS JUST A TEMPLATE TO GET YOU STARTED. use strict; - use base 'DBIx::Class::Loader::Generic'; + use base 'DBIx::Class::Schema::Loader::Generic'; use DBI; use Carp; diff --git a/lib/DBIx/Class/Loader/mysql.pm b/lib/DBIx/Class/Schema/Loader/mysql.pm similarity index 85% rename from lib/DBIx/Class/Loader/mysql.pm rename to lib/DBIx/Class/Schema/Loader/mysql.pm index c59e82a..d065764 100644 --- a/lib/DBIx/Class/Loader/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/mysql.pm @@ -1,31 +1,29 @@ -package DBIx::Class::Loader::mysql; +package DBIx::Class::Schema::Loader::mysql; use strict; -use base 'DBIx::Class::Loader::Generic'; +use base 'DBIx::Class::Schema::Loader::Generic'; use DBI; use Carp; =head1 NAME -DBIx::Class::Loader::mysql - DBIx::Class::Loader mysql Implementation. +DBIx::Class::Schema::Loader::mysql - DBIx::Schema::Class::Loader mysql Implementation. =head1 SYNOPSIS - use DBIx::Class::Loader; + use DBIx::Class::Schema::Loader; - # $loader is a DBIx::Class::Loader::mysql - my $loader = DBIx::Class::Loader->new( + # $loader is a DBIx::Class::Schema::Loader::mysql + my $loader = DBIx::Class::Schema::Loader->new( dsn => "dbi:mysql:dbname", user => "root", password => "", namespace => "Data", ); - my $class = $loader->find_class('film'); # $class => Data::Film - my $obj = $class->retrieve(1); =head1 DESCRIPTION -See L. +See L. =cut @@ -102,7 +100,7 @@ sub _table_info { =head1 SEE ALSO -L +L =cut diff --git a/t/dbixcl_common_tests.pm b/t/dbixcl_common_tests.pm index 21c4d50..e92496e 100644 --- a/t/dbixcl_common_tests.pm +++ b/t/dbixcl_common_tests.pm @@ -3,7 +3,7 @@ package dbixcl_common_tests; use strict; use Test::More; -use DBIx::Class::Loader; +use DBIx::Class::Schema::Loader; use DBI; sub new { @@ -44,7 +44,7 @@ sub run_tests { my $debug = ($self->{verbose} > 1) ? 1 : 0; - my $loader = DBIx::Class::Loader->new( + my $loader = DBIx::Class::Schema::Loader->new( dsn => $self->{dsn}, user => $self->{user}, password => $self->{password},