Institute a central "load this first in testing" package
[dbsrgits/DBIx-Class-Historic.git] / t / lib / DBICTest / RunMode.pm
index 39661a1..178378e 100644 (file)
@@ -4,22 +4,15 @@ package # hide from PAUSE
 use strict;
 use warnings;
 
-BEGIN {
-  if ($INC{'DBIx/Class.pm'}) {
-    my ($fr, @frame) = 1;
-    while (@frame = caller($fr++)) {
-      last if $frame[1] !~ m|^t/lib/DBICTest|;
-    }
-
-    die __PACKAGE__ . " must be loaded before DBIx::Class (or modules using DBIx::Class) at $frame[1] line $frame[2]\n";
-  }
-}
-
 use Path::Class qw/file dir/;
 use Fcntl ':DEFAULT';
 use File::Spec ();
 use File::Temp ();
-use DBICTest::Util 'local_umask';
+use DBICTest::Util qw( local_umask find_co_root );
+
+# Try to determine the root of a checkout/untar if possible
+# return a Path::Class::Dir object or undef
+sub _find_co_root { eval { dir( find_co_root() ) } }
 
 _check_author_makefile() unless $ENV{DBICTEST_NO_MAKEFILE_VERIFICATION};
 
@@ -36,7 +29,7 @@ sub tmpdir {
     my $reason_dir_unusable;
 
     my @parts = File::Spec->splitdir($dir);
-    if (@parts == 2 and $parts[1] =~ /^ [ \\ \/ ]? $/x ) {
+    if (@parts == 2 and $parts[1] =~ /^ [\/\\]? $/x ) {
       $reason_dir_unusable =
         'File::Spec->tmpdir returned a root directory instead of a designated '
       . 'tempdir (possibly https://rt.cpan.org/Ticket/Display.html?id=76663)';
@@ -197,47 +190,31 @@ sub is_author {
 }
 
 sub is_smoker {
-  return
-    __PACKAGE__->is_ci
-      ||
+  return (
     ( $ENV{AUTOMATED_TESTING} && ! $ENV{PERL5_CPANM_IS_RUNNING} && ! $ENV{RELEASE_TESTING} )
-  ;
+      or
+    __PACKAGE__->is_ci
+  );
 }
 
 sub is_ci {
   return (
     ($ENV{TRAVIS}||'') eq 'true'
       and
-    ($ENV{TRAVIS_REPO_SLUG}||'') eq 'dbsrgits/dbix-class'
+    ($ENV{TRAVIS_REPO_SLUG}||'') =~ m|\w+/dbix-class$|
   )
 }
 
 sub is_plain {
-  return (! __PACKAGE__->is_smoker && ! __PACKAGE__->is_author && ! $ENV{RELEASE_TESTING} )
-}
-
-# Try to determine the root of a checkout/untar if possible
-# or return undef
-sub _find_co_root {
-
-    my @mod_parts = split /::/, (__PACKAGE__ . '.pm');
-    my $rel_path = join ('/', @mod_parts);  # %INC stores paths with / regardless of OS
-
-    return undef unless ($INC{$rel_path});
-
-    # a bit convoluted, but what we do here essentially is:
-    #  - get the file name of this particular module
-    #  - do 'cd ..' as many times as necessary to get to t/lib/../..
-
-    my $root = dir ($INC{$rel_path});
-    for (1 .. @mod_parts + 2) {
-        $root = $root->parent;
-    }
-
-    return (-f $root->file ('Makefile.PL') )
-      ? $root
-      : undef
-    ;
+  return (
+    ! $ENV{RELEASE_TESTING}
+      and
+    ! $ENV{DBICTEST_RUN_ALL_TESTS}
+      and
+    ! __PACKAGE__->is_smoker
+      and
+    ! __PACKAGE__->is_author
+  )
 }
 
 1;