backcompat mode now runs more than once
Rafael Kitover [Sat, 28 Nov 2009 08:17:05 +0000 (08:17 +0000)]
Makefile.PL
TODO-BACKCOMPAT
lib/DBIx/Class/Schema/Loader/Base.pm

index 7baf854..58f13ae 100644 (file)
@@ -27,6 +27,8 @@ requires 'Class::Unload'               => 0;
 
 install_script 'script/dbicdump';
 
+tests_recursive;
+
 # This is my manual hack for better feature control
 #  If you want to change the default answer for a feature,
 #  set the appropriate environment variable, like
index 54376f4..96bf2ad 100644 (file)
@@ -8,7 +8,6 @@ SL Backcompat Plan:
 *** 0.04006 mode
 
 * use the detector and compat relbuilder ilmari already wrote for static schemas
-* make sure results are not singularized
 * add a loud warning that says that we're running in backcompat mode, and refers
   to the ::Manual::UpgradingFrom4006 POD.
 
@@ -21,11 +20,6 @@ SL Backcompat Plan:
 * need to run in 0.04006 mode (by seeding with a Schema.pm generated by
   0.04006, activation of backcompat mode should be minimally invasive.)
 
-*** common tests
-
-* should be all based off a static schema, because dynamic schemas will be
-  in 0.04006 mode
-
 *** Schema::Loader::Base
 
 * 'naming' accessor should be a Class::Accessor::Grouped 'inherited' type
index de54546..2e39d31 100644 (file)
@@ -33,7 +33,6 @@ __PACKAGE__->mk_ro_accessors(qw/
                                 moniker_map
                                 inflect_singular
                                 inflect_plural
-                                naming
                                 debug
                                 dump_directory
                                 dump_overwrite
@@ -51,6 +50,10 @@ __PACKAGE__->mk_ro_accessors(qw/
                                 monikers
                              /);
 
+__PACKAGE__->mk_accessors(qw/
+                                version_to_dump
+/);
+
 =head1 NAME
 
 DBIx::Class::Schema::Loader::Base - Base DBIx::Class::Schema::Loader Implementation.
@@ -322,6 +325,8 @@ sub new {
 
     $self->{dump_directory} ||= $self->{temp_directory};
 
+    $self->version_to_dump($DBIx::Class::Schema::Loader::VERSION);
+
     $self->_check_back_compat;
 
     $self;
@@ -330,6 +335,17 @@ sub new {
 sub _check_back_compat {
     my ($self) = @_;
 
+# dynamic schemas will always be in 0.04006 mode
+    if ($self->{dynamic}) {
+        no strict 'refs';
+        my $class = ref $self || $self;
+        unshift @{"${class}::ISA"},
+            'DBIx::Class::Schema::Loader::Compat::v0_040';
+        Class::C3::reinitialize;
+        return;
+    }
+
+# otherwise check if we need backcompat mode for a static schema
     my $filename = $self->_get_dump_filename($self->schema_class);
     return unless -e $filename;
 
@@ -337,14 +353,17 @@ sub _check_back_compat {
         or croak "Cannot open '$filename' for reading: $!";
 
     while (<$fh>) {
-        if (/^# Created by DBIx::Class::Schema::Loader (v\d+)\.(\d+)/) {
-            my $ver = "${1}_${2}";
+        if (/^# Created by DBIx::Class::Schema::Loader v((\d+)\.(\d+))/) {
+            my $real_ver = $1;
+            my $ver      = "v${2}_${3}";
             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;
+                    Class::C3::reinitialize;
+                    $self->version_to_dump($real_ver);
                     last;
                 }
                 $ver =~ s/\d\z// or last;
@@ -663,7 +682,7 @@ sub _write_classfile {
     }
 
     $text .= $self->_sig_comment(
-      $DBIx::Class::Schema::Loader::VERSION, 
+      $self->version_to_dump,
       POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime)
     );