[Bast-commits] r7400 - in
branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader:
. Compat RelBuilder RelBuilder/Compat
ilmari at dev.catalyst.perl.org
ilmari at dev.catalyst.perl.org
Wed Aug 26 23:09:44 GMT 2009
Author: ilmari
Date: 2009-08-26 23:09:44 +0000 (Wed, 26 Aug 2009)
New Revision: 7400
Added:
branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Compat/
branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Compat/v0_040.pm
branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder/
branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/
branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm
Modified:
branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Base.pm
branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder.pm
Log:
Initial back-compat code
Modified: branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Base.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Base.pm 2009-08-26 23:07:47 UTC (rev 7399)
+++ branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Base.pm 2009-08-26 23:09:44 UTC (rev 7400)
@@ -269,12 +269,36 @@
TMPDIR => 1,
CLEANUP => 1,
);
+ $self->_check_back_compat;
+ $self;
+}
- $self->{relbuilder} = DBIx::Class::Schema::Loader::RelBuilder->new(
- $self->schema, $self->inflect_plural, $self->inflect_singular
- ) if !$self->{skip_relationships};
+sub _check_back_compat {
+ my ($self) = @_;
- $self;
+ my $filename = $self->_get_dump_filename($self->schema_class);
+ return unless -e $filename;
+
+ open(my $fh, '<', $filename)
+ or croak "Cannot open '$filename' for reading: $!";
+
+ while (<$fh>) {
+ if (/^# Created by DBIx::Class::Schema::Loader (v\d+)\.(\d+)/) {
+ my $ver = "${1}_${2}";
+ while (1) {
+ my $compat_class = "DBIx::Class::Schema::Loader::Compat::${ver}";
+ if ($self->load_optional_class($compat_class)) {
+ no strict 'refs';
+ my $class = ref $self || $self;
+ unshift @{"${class}::ISA"}, $compat_class;
+ last;
+ }
+ $ver =~ s/\d\z// or last;
+ }
+ last;
+ }
+ }
+ close $fh;
}
sub _find_file_in_inc {
@@ -360,7 +384,7 @@
my ($self, $schema) = @_;
$self->{schema} = $schema;
- $self->{relbuilder}{schema} = $schema;
+ $self->_relbuilder->{schema} = $schema;
my @created;
my @current = $self->_tables_list;
@@ -375,6 +399,13 @@
return map { $self->monikers->{$_} } @$loaded;
}
+sub _relbuilder {
+ my ($self) = @_;
+ $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder->new(
+ $self->schema, $self->inflect_plural, $self->inflect_singular
+ );
+}
+
sub _load_tables {
my ($self, @tables) = @_;
@@ -760,7 +791,7 @@
my $tbl_uniq_info = $self->_table_uniq_info($table);
my $local_moniker = $self->monikers->{$table};
- my $rel_stmts = $self->{relbuilder}->generate_code($local_moniker, $tbl_fk_info, $tbl_uniq_info);
+ my $rel_stmts = $self->_relbuilder->generate_code($local_moniker, $tbl_fk_info, $tbl_uniq_info);
foreach my $src_class (sort keys %$rel_stmts) {
my $src_stmts = $rel_stmts->{$src_class};
Added: branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Compat/v0_040.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Compat/v0_040.pm (rev 0)
+++ branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Compat/v0_040.pm 2009-08-26 23:09:44 UTC (rev 7400)
@@ -0,0 +1,22 @@
+package DBIx::Class::Schema::Loader::Compat::v0_040;
+
+use strict;
+use warnings;
+use Class::C3;
+use DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040;
+
+# Make a moniker from a table
+sub _default_table2moniker {
+ my ($self, $table) = @_;
+
+ return join '', map ucfirst, split /[\W_]+/, lc $table;
+}
+
+sub _relbuilder {
+ my ($self) = @_;
+ $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder::v04Compat->new(
+ $self->schema, $self->inflect_plural, $self->inflect_singular
+ );
+}
+
+1;
Added: branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm (rev 0)
+++ branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm 2009-08-26 23:09:44 UTC (rev 7400)
@@ -0,0 +1,34 @@
+package DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040;
+
+use strict;
+use warnings;
+use Class::C3;
+
+use base 'DBIx::Class::Schema::Loader::RelBuilder';
+
+sub _uniq_fk_rel {
+ my ($self, $local_moniker, $local_relname, $local_cols, $uniqs) = @_;
+
+ return ('has_many', $local_relname);
+}
+
+sub _remote_attrs { }
+
+sub _remote_relname {
+ my ($self, $remote_table, $cond) = @_;
+
+ my $remote_relname;
+ # for single-column case, set the remote relname to the column
+ # name, to make filter accessors work
+ if(scalar keys %{$cond} == 1) {
+ $remote_relname = $self->_inflect_singular(values %{$cond});
+ }
+ else {
+ $remote_relname = $self->_inflect_singular(lc $remote_table);
+ }
+
+ return $remote_relname;
+}
+
+
+1;
Modified: branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder.pm 2009-08-26 23:07:47 UTC (rev 7399)
+++ branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder.pm 2009-08-26 23:09:44 UTC (rev 7400)
@@ -2,6 +2,7 @@
use strict;
use warnings;
+use Class::C3;
use Carp::Clan qw/^DBIx::Class/;
use Lingua::EN::Inflect::Number ();
More information about the Bast-commits
mailing list