license => 'perl',
module_name => 'DBIx::Class::Schema::Loader',
requires => {
- 'DBIx::Class' => 0.05,
+ 'DBIx::Class' => 0.05005,
'UNIVERSAL::require' => 0.10,
'Lingua::EN::Inflect' => 0,
'Text::Balanced' => 0,
Revision history for Perl extension DBIx::Class::Schema::Loader
+0.02001 Not Yet Released...
+ - tests fixed up a bit
+ - auto-loading of on-disk class definitions layered on top
+ of the generated definitions (create Foo::Schema::Bar, then
+ also try to ->require it if it exists on disk).
+ - new parameters components and resultset_components, which do
+ the obvious for the generated table classes.
+
0.02000 Sun Feb 12 22:43:47 UTC 2006
- Just docs/version update, 0.01004 code released as 0.02000
lib/DBIx/Class/Schema/Loader/Writing.pm
Makefile.PL
MANIFEST This list of files
+META.yml
+README
t/01use.t
t/02pod.t
t/03podcoverage.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
+t/lib/DBIx/Class/TestComponent.pm
+t/lib/DBIx/Class/TestRSComponent.pm
+t/lib/dbixcsl_common_tests.pm
+t/lib/DBIXCSL_Test/Schema/LoaderTest1.pm
+t/lib/TestAdditional.pm
+t/lib/TestAdditionalBase.pm
+t/lib/TestLeftBase.pm
TODO
-META.yml
-README
# Skip maint stuff
^maint/
+
+# Skip coverage output
+^cover_db/
---
name: DBIx-Class-Schema-Loader
-version: 0.02000
+version: 0.02001
author:
- 'Brandon Black, C<blblack@gmail.com>'
abstract: Dynamic definition of a DBIx::Class::Schema
Class::Accessor::Fast: 0.22
Class::C3: 0.09
Class::Data::Accessor: 0.02
- DBIx::Class: 0.05
+ DBIx::Class: 0.05005
Lingua::EN::Inflect: 0
Text::Balanced: 0
UNIVERSAL::require: 0.1
provides:
DBIx::Class::Schema::Loader:
file: lib/DBIx/Class/Schema/Loader.pm
- version: 0.02000
+ version: 0.02001
DBIx::Class::Schema::Loader::DB2:
file: lib/DBIx/Class/Schema/Loader/DB2.pm
DBIx::Class::Schema::Loader::Generic:
additional_classes => [qw/DBIx::Class::Foo/],
additional_base_classes => [qw/My::Stuff/],
left_base_classes => [qw/DBIx::Class::Bar/],
+ components => [qw/ResultSetManager/],
+ resultset_components => [qw/AlwaysRS/],
constraint => '^foo.*',
relationships => 1,
options => { AutoCommit => 1 },
SQLite needs some heavy refactoring, the subroutines are becoming too complex to understand easily.
+Relationship-building needs to be refactored into a seperate module to share with SQLT.
+
Relationship stuff:
Fix multiple rels between same pair of tables
If local column is UNIQUE or PK, use has_one() for relation?
Re-scan relations/tables after initial relation setup to find ->many_to_many() relations to be set up?
Check NULLability of columns involved in the relationship, which might suggest a more optimal non-default -join-type?
-
+ While scanning for many-to-many, scan for implied rels as well? (if foo->belongs_to('bar') and baz->belongs_to('bar'), does that impliy foo->might_have('baz') and the reverse?)
...
# Always remember to do all digits for the version even if they're 0
# i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports
# brain damage and presumably various other packaging systems too
-our $VERSION = '0.02000';
+our $VERSION = '0.02001';
__PACKAGE__->mk_classaccessor('loader');
additional_classes => [qw/DBIx::Class::Foo/],
additional_base_classes => [qw/My::Stuff/],
left_base_classes => [qw/DBIx::Class::Bar/],
+ components => [qw/ResultSetManager/],
+ resultset_components => [qw/AlwaysRS/],
constraint => '^foo.*',
relationships => 1,
options => { AutoCommit => 1 },
additional_classes
additional_base_classes
left_base_classes
+ components
+ resultset_components
relationships
inflect
db_schema
List of additional classes which your table classes will use.
+=head2 components
+
+List of additional components to be loaded into your table classes.
+A good example would be C<ResultSetManager>.
+
+=head2 resultset_components
+
+List of additional resultset components to be loaded into your table
+classes. A good example would be C<AlwaysRS>. Component
+C<ResultSetManager> will be automatically added to the above
+C<components> list if this option is set.
+
=head2 constraint
Only load tables matching regex.
$self->{inflect} ||= {};
$self->_ensure_arrayref(qw/additional_classes
additional_base_classes
- left_base_classes/);
+ left_base_classes
+ components
+ resultset_components/);
+
+ push(@{$self->{components}}, 'ResultSetManager')
+ if @{$self->{resultset_components}};
$self->{monikers} = {};
$self->{classes} = {};
my $rev_cond = { reverse %$cond };
for (keys %$rev_cond) {
- $rev_cond->{"foreign.$_"} = "self.".$rev_cond->{$_};
- delete $rev_cond->{$_};
+ $rev_cond->{"foreign.$_"} = "self.".$rev_cond->{$_};
+ delete $rev_cond->{$_};
}
my $cond_printable = _stringify_hash($cond)
$self->_inject($table_class, @{$self->additional_base_classes});
$self->_use ($table_class, @{$self->additional_classes});
$self->_inject($table_class, @{$self->left_base_classes});
+ $table_class->load_components(@{$self->components});
+ $table_class->load_resultset_components(@{$self->resultset_components})
+ if @{$self->resultset_components};
warn qq/\# Initializing table "$tablename" as "$table_class"\n/
if $self->debug;
warn qq/$table_class->set_primary_key('$primaries')\n/
if $self->debug && @$pks;
+ $table_class->require;
+ if($@ && $@ !~ /^Can't locate /) {
+ croak "Failed to load external class definition"
+ . "for '$table_class': $@";
+ }
+
+ warn qq/# Loaded external class definition for '$table_class'\n/
+ if $self->debug;
+
$schema->register_class($table_moniker, $table_class);
$self->classes->{$lc_tblname} = $table_class;
$self->monikers->{$lc_tblname} = $table_moniker;
use strict;
-use Test::More tests => 3;
+use Test::More tests => 5;
BEGIN {
- use_ok 'DBIx::Class::Loader';
- SKIP: {
- use_ok 'DBIx::Class::Loader::mysql';
- }
- SKIP: {
- use_ok 'DBIx::Class::Loader::Pg';
- }
+ use_ok 'DBIx::Class::Schema::Loader';
+ use_ok 'DBIx::Class::Schema::Loader::SQLite';
+ use_ok 'DBIx::Class::Schema::Loader::mysql';
+ use_ok 'DBIx::Class::Schema::Loader::Pg';
+ use_ok 'DBIx::Class::Schema::Loader::DB2';
}
use strict;
-use lib qw( ./t );
+use lib qw(t/lib);
use dbixcsl_common_tests;
eval { require DBD::SQLite };
use strict;
-use lib qw( . ./t );
+use lib qw(t/lib);
use dbixcsl_common_tests;
my $dsn = $ENV{DBICTEST_MYSQL_DSN} || '';
use strict;
-use lib qw( . ./t );
+use lib qw(t/lib);
use dbixcsl_common_tests;
my $dsn = $ENV{DBICTEST_PG_DSN} || '';
use strict;
-use lib qw( . ./t );
+use lib qw(t/lib);
use dbixcsl_common_tests;
my $dsn = $ENV{DBICTEST_DB2_DSN} || '';
--- /dev/null
+package DBIXCSL_Test::Schema::LoaderTest1;
+
+sub loader_test1_classmeth { 'all is well' }
+
+sub loader_test1_rsmeth : ResultSet { 'all is still well' }
+
+1;
--- /dev/null
+package DBIx::Class::TestComponent;
+
+sub dbix_class_testcomponent { 'dbix_class_testcomponent works' }
+
+1;
--- /dev/null
+package DBIx::Class::TestRSComponent;
+
+# XXX why is this breaking?
+#sub dbix_class_testrscomponent : ResultSet { 'dbix_class_testrscomponent works' }
+
+1;
sub run_tests {
my $self = shift;
- plan tests => 42;
+ plan tests => 50;
$self->create();
- my $schema_class = 'DBIXCSL_Test_' . $self->{vendor} . '::Schema';
+ my $schema_class = 'DBIXCSL_Test::Schema';
my $debug = ($self->{verbose} > 1) ? 1 : 0;
additional_classes => 'TestAdditional',
additional_base_classes => 'TestAdditionalBase',
left_base_classes => [ qw/TestLeftBase/ ],
+ components => [ qw/TestComponent/ ],
+ resultset_components => [ qw/TestRSComponent/ ],
debug => $debug,
);
isa_ok( $rsobj1, "DBIx::Class::ResultSet" );
isa_ok( $rsobj2, "DBIx::Class::ResultSet" );
- can_ok( $class1, 'test_additional_base' );
- can_ok( $class1, 'test_additional_base_override' );
- can_ok( $class1, 'test_additional_base_additional' );
+ {
+ my ($skip_tab, $skip_tabo, $skip_taba, $skip_cmeth,
+ $skip_rsmeth, $skip_tcomp, $skip_trscomp);
- is( $class1->test_additional_base, "test_additional_base",
- "Additional Base method" );
+ can_ok( $class1, 'test_additional_base' ) or $skip_tab = 1;
+ can_ok( $class1, 'test_additional_base_override' ) or $skip_tabo = 1;
+ can_ok( $class1, 'test_additional_base_additional' ) or $skip_taba = 1;
+ can_ok( $class1, 'dbix_class_testcomponent' ) or $skip_tcomp = 1;
+ can_ok( $class1, 'dbix_class_testrscomponent' ) or $skip_trscomp = 1;
+ can_ok( $class1, 'loader_test1_classmeth' ) or $skip_cmeth = 1;
+ can_ok( $rsobj1, 'loader_test1_rsmeth' ) or $skip_rsmeth = 1;
- is( $class1->test_additional_base_override, "test_left_base_override",
- "Left Base overrides Additional Base method" );
+ SKIP: {
+ skip "Pre-requisite test failed", 1 if $skip_tab;
+ is( $class1->test_additional_base, "test_additional_base",
+ "Additional Base method" );
+ }
+
+ SKIP: {
+ skip "Pre-requisite test failed", 1 if $skip_tabo;
+ is( $class1->test_additional_base_override,
+ "test_left_base_override",
+ "Left Base overrides Additional Base method" );
+ }
+
+ SKIP: {
+ skip "Pre-requisite test failed", 1 if $skip_taba;
+ is( $class1->test_additional_base_additional, "test_additional",
+ "Additional Base can use Additional package method" );
+ }
+
+ SKIP: {
+ skip "Pre-requisite test failed", 1 if $skip_tcomp;
+ is( $class1->dbix_class_testcomponent,
+ 'dbix_class_testcomponent works' );
+ }
+
+ SKIP: {
+ skip "Pre-requisite test failed", 1 if $skip_trscomp;
+ is( $rsobj1->dbix_class_testrscomponent,
+ 'dbix_class_testrscomponent works' );
+ }
+
+ SKIP: {
+ skip "Pre-requisite test failed", 1 if $skip_cmeth;
+ is( $class1->loader_test1_classmeth, 'all is well' );
+ }
+
+ SKIP: {
+ skip "Pre-requisite test failed", 1 if $skip_rsmeth;
+ is( $rsobj1->loader_test1_rsmeth, 'all is still well' );
+ }
+ }
- is( $class1->test_additional_base_additional, "test_additional",
- "Additional Base can use Additional package method" );
my $obj = $rsobj1->find(1);
is( $obj->id, 1 );