From: Brandon Black Date: Tue, 31 Jan 2006 04:46:44 +0000 (+0000) Subject: switched to Build.PL, updated deps, updated docs X-Git-Tag: 0.03000~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8a6b44efef66c45bdf1336135b0c9c5e5face742;hp=52bf3f264b3d5e1a0c494e82e13fb377eaa28a6f;p=dbsrgits%2FDBIx-Class-Schema-Loader.git switched to Build.PL, updated deps, updated docs --- diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..6ff962b --- /dev/null +++ b/Build.PL @@ -0,0 +1,24 @@ +use strict; +use Module::Build; + +my %arguments = ( + license => 'perl', + module_name => 'DBIx::Class::Schema::Loader', + requires => { + 'DBIx::Class' => 0.04999_07, + 'UNIVERSAL::require' => 0.10, + 'Lingua::EN::Inflect' => 0, + 'Text::Balanced' => 0, + 'Class::Accessor::Fast' => 0.22, + 'Class::Data::Accessor' => 0.02, + }, + build_requires => { + 'Test::More' => 0.32, + 'DBI' => 1.40, + 'DBD::SQLite' => 1.11, + }, + create_makefile_pl => 'passthrough', + create_readme => 1, +); + +Module::Build->new(%arguments)->create_build_script; diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..509e9cf --- /dev/null +++ b/MANIFEST @@ -0,0 +1,25 @@ +Build.PL +Changes +lib/DBIx/Class/Schema/Loader.pm +lib/DBIx/Class/Schema/Loader/DB2.pm +lib/DBIx/Class/Schema/Loader/Generic.pm +lib/DBIx/Class/Schema/Loader/mysql.pm +lib/DBIx/Class/Schema/Loader/Pg.pm +lib/DBIx/Class/Schema/Loader/SQLite.pm +lib/DBIx/Class/Schema/Loader/Writing.pm +Makefile.PL +MANIFEST This list of files +t/01use.t +t/02pod.t +t/03podcoverage.t +t/10sqlite_common.t +t/11mysql_common.t +t/12pg_common.t +t/13db2_common.t +t/dbixcsl_common_tests.pm +t/TestAdditional.pm +t/TestAdditionalBase.pm +t/TestLeftBase.pm +TODO +META.yml +README diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..d25803e --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,39 @@ +# copied over from DBIx::Class +# +# Avoid version control files. +\bRCS\b +\bCVS\b +,v$ +\B\.svn\b + +# Avoid Makemaker generated and utility files. +\bMakefile$ +\bblib +\bMakeMaker-\d +\bpm_to_blib$ +\bblibdirs$ +^MANIFEST\.SKIP$ + +# Avoid Module::Build generated and utility files. +\bBuild$ +\b_build + +# Avoid temp and backup files. +~$ +\.tmp$ +\.old$ +\.bak$ +\#$ +\b\.# + +# avoid OS X finder files +\.DS_Store$ + +# Don't ship the test db +^t/var + +# Don't ship the last dist we built :) +\.tar\.gz$ + +# Skip maint stuff +^maint/ diff --git a/META.yml b/META.yml new file mode 100644 index 0000000..5f25b3f --- /dev/null +++ b/META.yml @@ -0,0 +1,35 @@ +--- +name: DBIx-Class-Schema-Loader +version: 0.01000 +author: + - 'Brandon Black, C' +abstract: Dynamic definition of a DBIx::Class::Schema +license: perl +requires: + Class::Accessor::Fast: 0.22 + Class::Data::Accessor: 0.02 + DBIx::Class: 0.0499907 + Lingua::EN::Inflect: 0 + Text::Balanced: 0 + UNIVERSAL::require: 0.1 +build_requires: + DBD::SQLite: 1.11 + DBI: 1.4 + Test::More: 0.32 +provides: + DBIx::Class::Schema::Loader: + file: lib/DBIx/Class/Schema/Loader.pm + version: 0.01000 + DBIx::Class::Schema::Loader::DB2: + file: lib/DBIx/Class/Schema/Loader/DB2.pm + DBIx::Class::Schema::Loader::Generic: + file: lib/DBIx/Class/Schema/Loader/Generic.pm + DBIx::Class::Schema::Loader::Pg: + file: lib/DBIx/Class/Schema/Loader/Pg.pm + DBIx::Class::Schema::Loader::SQLite: + file: lib/DBIx/Class/Schema/Loader/SQLite.pm + DBIx::Class::Schema::Loader::Writing: + file: lib/DBIx/Class/Schema/Loader/Writing.pm + DBIx::Class::Schema::Loader::mysql: + file: lib/DBIx/Class/Schema/Loader/mysql.pm +generated_by: Module::Build version 0.2611 diff --git a/Makefile.PL b/Makefile.PL index 76c030c..51d31fd 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,14 +1,31 @@ -use ExtUtils::MakeMaker; - -WriteMakefile( - 'NAME' => 'DBIx::Class::Schema::Loader', - 'VERSION_FROM' => 'lib/DBIx/Class/Schema/Loader.pm', - 'PREREQ_PM' => { - Test::More => 0.32, - DBIx::Class => 0.05, - DBI => 1.30, - Lingua::EN::Inflect => 0, - Text::Balanced => 0, - UNIVERSAL::require => 0.10, - }, -); +# Note: this file was auto-generated by Module::Build::Compat version 0.03 + + unless (eval "use Module::Build::Compat 0.02; 1" ) { + print "This module requires Module::Build to install itself.\n"; + + require ExtUtils::MakeMaker; + my $yn = ExtUtils::MakeMaker::prompt + (' Install Module::Build now from CPAN?', 'y'); + + unless ($yn =~ /^y/i) { + die " *** Cannot install without Module::Build. Exiting ...\n"; + } + + require Cwd; + require File::Spec; + require CPAN; + + # Save this 'cause CPAN will chdir all over the place. + my $cwd = Cwd::cwd(); + my $makefile = File::Spec->rel2abs($0); + + CPAN::Shell->install('Module::Build::Compat') + or die " *** Cannot install without Module::Build. Exiting ...\n"; + + chdir $cwd or die "Cannot chdir() back to $cwd: $!"; + } + eval "use Module::Build::Compat 0.02; 1" or die $@; + use lib '_build/lib'; + Module::Build::Compat->run_build_pl(args => \@ARGV); + require Module::Build; + Module::Build::Compat->write_makefile(build_class => 'Module::Build'); diff --git a/README b/README new file mode 100644 index 0000000..624037a --- /dev/null +++ b/README @@ -0,0 +1,83 @@ +NAME + DBIx::Class::Schema::Loader - Dynamic definition of a + DBIx::Class::Schema + +SYNOPSIS + package My::Schema; + use base qw/DBIx::Class::Schema::Loader/; + + __PACKAGE__->load_from_connection( + dsn => "dbi:mysql:dbname", + user => "root", + password => "", + additional_classes => [qw/DBIx::Class::Foo/], + additional_base_classes => [qw/My::Stuff/], + left_base_classes => [qw/DBIx::Class::Bar/], + constraint => '^foo.*', + relationships => 1, + options => { AutoCommit => 1 }, + inflect => { child => 'children' }, + debug => 1, + ); + + # in seperate application code ... + + use My::Schema; + + my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs); + # -or- + my $schema1 = "My::Schema"; + # ^^ defaults to dsn/user/pass from load_from_connection() + + # Get a list of the original (database) names of the tables that + # were loaded + my @tables = $schema1->loader->tables; + + # Get a hashref of table_name => 'TableName' table-to-moniker + # mappings. + my $monikers = $schema1->loader->monikers; + + # Get a hashref of table_name => 'My::Schema::TableName' + # table-to-classname mappings. + my $classes = $schema1->loader->classes; + + # Use the schema as per normal for L + my $rs = $schema1->resultset($monikers->{table_table})->search(...); + +DESCRIPTION + DBIx::Class::Schema::Loader automates the definition of a + DBIx::Class::Schema by scanning table schemas and setting up columns and + primary keys. + + DBIx::Class::Schema::Loader supports MySQL, Postgres, SQLite and DB2. + See DBIx::Class::Schema::Loader::Generic for more, and + DBIx::Class::Schema::Loader::Writing for notes on writing your own + db-specific subclass for an unsupported db. + + This module requires DBIx::Class::Loader 0.5 or later, and obsoletes + DBIx::Class::Loader for DBIx::Class version 0.5 and later. + +METHODS + load_from_connection + Example in Synopsis above demonstrates the available arguments. For + detailed information on the arguments, see the + DBIx::Class::Schema::Loader::Generic documentation. + +AUTHOR + Brandon Black, "bblack@gmail.com" + + Based on DBIx::Class::Loader by Sebastian Riedel + + Based upon the work of IKEBE Tomohiro + +THANK YOU + Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton, + Randal Schwartz, Simon Flack and all the others who've helped. + +LICENSE + This library is free software; you can redistribute it and/or modify it + under the same terms as Perl itself. + +SEE ALSO + DBIx::Class + diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index 1a67c82..4e84da0 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -5,6 +5,11 @@ use warnings; use Carp; use UNIVERSAL::require; +use base qw/DBIx::Class::Schema/; +use base qw/Class::Data::Accessor/; + +__PACKAGE__->mk_classaccessor('loader'); + use vars qw($VERSION); # Always remember to do all digits for the version even if they're 0 @@ -12,10 +17,6 @@ use vars qw($VERSION); # brain damage and presumably various other packaging systems too $VERSION = '0.01000'; -use base qw/DBIx::Class::Schema/; - -__PACKAGE__->mk_classaccessor('loader'); - =head1 NAME DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema @@ -111,7 +112,7 @@ sub load_from_connection { Brandon Black, C -Sebastian Riedel, C (DBIx::Class::Loader, which this module is branched from) +Based on L by Sebastian Riedel Based upon the work of IKEBE Tomohiro diff --git a/lib/DBIx/Class/Schema/Loader/Generic.pm b/lib/DBIx/Class/Schema/Loader/Generic.pm index c27538a..95b82d8 100644 --- a/lib/DBIx/Class/Schema/Loader/Generic.pm +++ b/lib/DBIx/Class/Schema/Loader/Generic.pm @@ -308,9 +308,37 @@ sub _load_classes { =head3 tables -Returns a sorted list of tables. +Returns a sorted list of loaded tables, using the original database table +names. Actually generated from the keys of the C hash below. - my @tables = $loader->tables; + my @tables = $schema->loader->tables; + +=head3 monikers + +Returns a hashref of loaded table-to-moniker mappings for the original +database table names. + + my $monikers = $schema->loader->monikers; + my $foo_tbl_moniker = $monikers->{foo_tbl}; + # -or- + my $foo_tbl_moniker = $schema->loader->monikers->{foo_tbl}; + # $foo_tbl_moniker would look like "FooTbl" + +=head3 classes + +Returns a hashref of table-to-classname mappings for the original database +table names. You probably shouldn't be using this, as operating on the +original class names is usually a bad idea. This hook is here for people +who want to do strange and/or possibly broken things. The usual way to +get at things is C<$schema->resultset('FooTbl')>, where C is a +moniker as returned by C above. + + my $classes = $schema->loader->classes; + my $foo_tbl_class = $classes->{foo_tbl}; + # -or- + my $foo_tbl_class = $schema->loader->classes->{foo_tbl}; + # $foo_tbl_class would look like "My::Schema::FooTbl", + # assuming the schema class is "My::Schema" =cut