fixed busted replication trait
John Napiorkowski [Wed, 23 Jul 2014 01:55:01 +0000 (21:55 -0400)]
Changes
lib/Catalyst/Model/DBIC/Schema/Types.pm
lib/Catalyst/TraitFor/Model/DBIC/Schema/Replicated.pm

diff --git a/Changes b/Changes
index 1dc2bea..1c02d77 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for Perl extension Catalyst::Model::DBIC::Schema
 
+0.64  2014-07-22 23:0:00
+        - Fix Replicated trait that got busted when someone assumed
+          Module::Runtime was a drop in replacement for Class::MOP::load_class
+
 0.63  2014-05-05 22:56:43
         - Make MooseX::MarkAsMethods a hard prerequisite (RT#94923)
         - Fix t/08helper.t with Data::Dumper >= 2.151 (RT#94599)
index 0356482..c48f22c 100644 (file)
@@ -3,7 +3,7 @@ package  # hide from PAUSE
 
 use MooseX::Types -declare => [qw/
     ConnectInfo ConnectInfos Replicants SchemaClass CreateOption
-    Schema
+    Schema LoadedClass
 /];
 
 use Carp::Clan '^Catalyst::Model::DBIC::Schema';
@@ -11,9 +11,21 @@ use MooseX::Types::Moose qw/ArrayRef HashRef CodeRef Str ClassName/;
 use MooseX::Types::LoadableClass qw/LoadableClass/;
 use Scalar::Util 'reftype';
 use List::MoreUtils 'all';
+use Module::Runtime;
 
 use namespace::clean -except => 'meta';
 
+# So I restored the custom Type LoadedClass because 'LoadableClass' doesn't really
+# exactly do the same thing, which busted the Replication trait.  Please don't
+# "clean this up" -JNAP
+
+subtype LoadedClass,
+    as ClassName;
+
+coerce LoadedClass,
+    from Str, # N.B. deliberate paranoia against $_ clobbering below
+    via { my $classname = $_; Module::Runtime::use_module($classname); $classname };
+
 subtype SchemaClass,
     as LoadableClass,
     where { $_->isa('DBIx::Class::Schema') };
index a978d1d..682e468 100644 (file)
@@ -1,13 +1,18 @@
 package Catalyst::TraitFor::Model::DBIC::Schema::Replicated;
 
+## WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
+## If you make changes to this code and don't actually go and test it
+## on a real replicated environment I will rip you an new hole.  The
+## test suite DOES NOT properly test this.  --JNAP
+
 use namespace::autoclean;
 use Moose::Role;
 use Carp::Clan '^Catalyst::Model::DBIC::Schema';
 
-use Catalyst::Model::DBIC::Schema::Types qw/ConnectInfos LoadableClass/;
+use Catalyst::Model::DBIC::Schema::Types qw/ConnectInfos LoadedClass/;
 use MooseX::Types::Moose qw/Str HashRef/;
 
-use Module::Runtime qw/use_module/;
+use Module::Runtime;
 
 =head1 NAME
 
@@ -76,7 +81,10 @@ has replicants => (
     is => 'ro', isa => ConnectInfos, coerce => 1, required => 1
 );
 
-has pool_type => (is => 'ro', isa => LoadableClass);
+# If you change LoadedClass with LoadableClass I will rip you a new hole,
+# it doesn't work exactly the same - JNAP
+
+has pool_type => (is => 'ro', isa => LoadedClass);
 has pool_args => (is => 'ro', isa => HashRef);
 has balancer_type => (is => 'ro', isa => Str);
 has balancer_args => (is => 'ro', isa => HashRef);
@@ -90,7 +98,10 @@ after setup => sub {
             "DBIx::Class::Storage$storage_type"
             : $storage_type;
 
-        use_module($class);
+            # For some odd reason if you try to use 'use_module' as an export
+            # the code breaks.  I guess something odd about MR and all these
+            # runtime loaded crazy trait code.  Please don't "tidy the code up" -JNAP
+            Module::Runtime::use_module($class);
 
         croak "This storage_type cannot be used with replication"
             unless $class->isa('DBIx::Class::Storage::DBI::Replicated');