Do not load DBIC::Optional::Dependencies at runtime unless we need to
Peter Rabbitson [Thu, 3 Mar 2016 11:24:55 +0000 (12:24 +0100)]
lib/DBIx/Class.pm
lib/DBIx/Class/Schema/Versioned.pm
lib/DBIx/Class/Storage.pm
lib/DBIx/Class/Storage/DBI.pm
lib/DBIx/Class/Storage/DBI/Pg.pm
t/52leaks.t
t/84serialize.t
t/lib/DBICTest/Util/LeakTracer.pm
t/storage/cursor.t
t/storage/savepoints.t

index 1adbe64..cec52f7 100644 (file)
@@ -18,8 +18,6 @@ $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev relea
 use DBIx::Class::_Util;
 use mro 'c3';
 
-use DBIx::Class::Optional::Dependencies;
-
 use base qw/DBIx::Class::Componentised DBIx::Class::AccessorGroup/;
 use DBIx::Class::StartupCheck;
 use DBIx::Class::Exception;
index 2f130f6..c155360 100644 (file)
@@ -641,6 +641,7 @@ sub _create_db_to_schema_diff {
     return;
   }
 
+  require DBIx::Class::Optional::Dependencies;
   if ( my $missing = DBIx::Class::Optional::Dependencies->req_missing_for('deploy') ) {
     $self->throw_exception("Unable to proceed without $missing");
   }
index 47aef36..45839e1 100644 (file)
@@ -577,6 +577,7 @@ sub debugobj {
 
       if ($profile =~ /^\.?\//) {
 
+        require DBIx::Class::Optional::Dependencies;
         if ( my $missing = DBIx::Class::Optional::Dependencies->req_missing_for ('config_file_reader') ) {
           $self->throw_exception("Unable to parse TRACE_PROFILE config file '$profile' without $missing");
         }
index 25ed0b5..cafdf19 100644 (file)
@@ -2938,6 +2938,11 @@ them.
 sub create_ddl_dir {
   my ($self, $schema, $databases, $version, $dir, $preversion, $sqltargs) = @_;
 
+  require DBIx::Class::Optional::Dependencies;
+  if (my $missing = DBIx::Class::Optional::Dependencies->req_missing_for ('deploy')) {
+    $self->throw_exception("Can't create a ddl file without $missing");
+  }
+
   if (!$dir) {
     carp "No directory given, using ./\n";
     $dir = './';
@@ -2960,10 +2965,6 @@ sub create_ddl_dir {
     %{$sqltargs || {}}
   };
 
-  if (my $missing = DBIx::Class::Optional::Dependencies->req_missing_for ('deploy')) {
-    $self->throw_exception("Can't create a ddl file without $missing");
-  }
-
   my $sqlt = SQL::Translator->new( $sqltargs );
 
   $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
@@ -3117,6 +3118,7 @@ sub deployment_statements {
       return join('', @rows);
   }
 
+  require DBIx::Class::Optional::Dependencies;
   if (my $missing = DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') ) {
     $self->throw_exception("Can't deploy without a pregenerated 'ddl_dir' directory or $missing");
   }
index ded6d06..87a237d 100644 (file)
@@ -181,6 +181,8 @@ sub bind_attribute_by_data_type {
         );
       }
       elsif (
+        require DBIx::Class::Optional::Dependencies
+          and
         my $missing = DBIx::Class::Optional::Dependencies->req_missing_for([qw( rdbms_pg binary_data )])
       ) {
         # FIXME - perhaps this needs to be an exception too...?
index ca588ce..e54df31 100644 (file)
@@ -33,6 +33,7 @@ use DBICTest::RunMode;
 use DBICTest::Util::LeakTracer qw(populate_weakregistry assert_empty_weakregistry visit_refs);
 use Scalar::Util qw(weaken blessed reftype);
 use DBIx::Class::_Util qw(hrefaddr sigwarn_silencer modver_gt_or_eq modver_gt_or_eq_and_lt);
+use DBIx::Class::Optional::Dependencies;
 
 my $TB = Test::More->builder;
 if ($ENV{DBICTEST_IN_PERSISTENT_ENV}) {
index bbb5f4e..021c44e 100644 (file)
@@ -61,6 +61,7 @@ my %stores = (
 );
 
 SKIP: {
+    require DBIx::Class::Optional::Dependencies;
     DBIx::Class::Optional::Dependencies->skip_without('test_memcached');
 
     my $memcached = Cache::Memcached->new(
index 134ca63..82ff010 100644 (file)
@@ -7,12 +7,17 @@ use ANFANG;
 use Carp;
 use Scalar::Util qw(isweak weaken blessed reftype);
 use DBIx::Class::_Util qw(refcount hrefaddr refdesc);
-use DBIx::Class::Optional::Dependencies;
 use DBICTest::RunMode;
 use Data::Dumper::Concise;
 use DBICTest::Util qw( stacktrace visit_namespaces );
 use constant {
-  CV_TRACING => !DBICTest::RunMode->is_plain && DBIx::Class::Optional::Dependencies->req_ok_for ('test_leaks_heavy'),
+  CV_TRACING => !!(
+    !DBICTest::RunMode->is_plain
+      &&
+    require DBIx::Class::Optional::Dependencies
+      &&
+    DBIx::Class::Optional::Dependencies->req_ok_for ('test_leaks_heavy')
+  ),
 };
 
 use base 'Exporter';
index 93a3161..96f917e 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 use Test::More;
 use Test::Exception;
 
-
+use DBIx::Class::Optional::Dependencies;
 use DBICTest;
 
 my $schema = DBICTest->init_schema(cursor_class => 'DBICTest::Cursor');
index 624ee9c..66b7d71 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 
 use Test::More;
 use Test::Exception;
+use DBIx::Class::Optional::Dependencies;
 use DBIx::Class::_Util qw(modver_gt_or_eq sigwarn_silencer scope_guard);