From: Matt S Trout Date: Wed, 10 Aug 2005 18:24:21 +0000 (+0000) Subject: Fixes, refactoring, test additions X-Git-Tag: v0.03001~43 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=227d4dee52a91339e04dd509712ac062450bbb82;hp=b8566d6672a37412d86e07cdb545289e9285f904;p=dbsrgits%2FDBIx-Class.git Fixes, refactoring, test additions --- diff --git a/Build.PL b/Build.PL index 125de09..a665523 100644 --- a/Build.PL +++ b/Build.PL @@ -6,11 +6,12 @@ my %arguments = ( license => 'perl', module_name => 'DBIx::Class', requires => { - 'DBI' => 0, - 'NEXT' => 0, - 'SQL::Abstract' => 1.19, - 'DBD::SQLite' => 1.08, - 'Tie::IxHash' => 0, + 'DBI' => 0, + 'UNIVERSAL::require' => 0, + 'NEXT' => 0, + 'SQL::Abstract' => 1.19, + 'DBD::SQLite' => 1.08, + 'Tie::IxHash' => 0, }, create_makefile_pl => 'passthrough', create_readme => 1, diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 4dba9d1..9f05f06 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -4,31 +4,10 @@ use strict; use warnings; use vars qw($VERSION); -use base; - -$VERSION = '0.01'; - -sub load_components { - my $class = shift; - my @comp = map { "DBIx::Class::$_" } grep { $_ !~ /^#/ } @_; - $class->_load_components(@comp); -} - -sub load_own_components { - my $class = shift; - my @comp = map { "${class}::$_" } grep { $_ !~ /^#/ } @_; - $class->_load_components(@comp); -} - -sub _load_components { - my ($class, @comp) = @_; - foreach my $comp (@comp) { - eval "use $comp"; - die $@ if $@; - } - no strict 'refs'; - unshift(@{"${class}::ISA"}, @comp); -} +use base qw/DBIx::Class::Componentised/; + +$VERSION = '0.02'; + 1; diff --git a/lib/DBIx/Class/Componentised.pm b/lib/DBIx/Class/Componentised.pm new file mode 100644 index 0000000..72dd6f2 --- /dev/null +++ b/lib/DBIx/Class/Componentised.pm @@ -0,0 +1,32 @@ +package DBIx::Class::Componentised; + +sub inject_base { + my ($class, $target, @to_inject) = @_; + { + no strict 'refs'; + unshift(@{"${target}::ISA"}, grep { $target ne $_ } @to_inject); + } +} + +sub load_components { + my $class = shift; + my @comp = map { "DBIx::Class::$_" } grep { $_ !~ /^#/ } @_; + $class->_load_components(@comp); +} + +sub load_own_components { + my $class = shift; + my @comp = map { "${class}::$_" } grep { $_ !~ /^#/ } @_; + $class->_load_components(@comp); +} + +sub _load_components { + my ($class, @comp) = @_; + foreach my $comp (@comp) { + eval "use $comp"; + die $@ if $@; + } + $class->inject_base($class => @comp); +} + +1; diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index d33f4d4..d704d82 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -6,7 +6,7 @@ use warnings; use base qw/Class::Data::Inheritable/; use base qw/DBIx::Class/; -__PACKAGE__->load_components(qw/Exception/); +__PACKAGE__->load_components(qw/Exception Componentised/); __PACKAGE__->mk_classdata('class_registrations' => {}); =head1 NAME @@ -89,6 +89,7 @@ sub compose_connection { while (my ($comp, $comp_class) = each %reg) { my $target_class = "${target}::${comp}"; $class->inject_base($target_class, $conn_class, $comp_class); + $target_class->table($comp_class->table); @map{$comp, $comp_class} = ($target_class, $target_class); } { @@ -109,14 +110,6 @@ sub setup_connection_class { $target->connection(@info); } -sub inject_base { - my ($class, $target, @to_inject) = @_; - { - no strict 'refs'; - unshift(@{"${target}::ISA"}, grep { $target ne $_ } @to_inject); - } -} - 1; =back diff --git a/t/01core.t b/t/01core.t index fbc1851..5ccdd40 100644 --- a/t/01core.t +++ b/t/01core.t @@ -1,6 +1,6 @@ use Test::More; -plan tests => 22; +plan tests => 23; use lib qw(t/lib); @@ -90,3 +90,7 @@ ok($new->in_storage, 'insert_or_update insert ok'); $new->position(5); $new->insert_or_update; is( DBICTest::Track->find(100)->position, 5, 'insert_or_update update ok'); + +eval { DBICTest::Track->load_components('DoesNotExist'); }; + +ok $@, $@; diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index 1bc01c5..525703e 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -1,7 +1,6 @@ use strict; use warnings; use DBICTest::Schema; -use DateTime; my $db_file = "t/var/DBIxClass.db";