Get rid of Path::Class ( that *does* feel good )
[dbsrgits/DBIx-Class.git] / t / storage / debug.t
index e3cef38..aac2a23 100644 (file)
@@ -19,39 +19,41 @@ use Try::Tiny;
 use File::Spec;
 
 use DBICTest;
-use Path::Class qw/file/;
+use DBICTest::Util 'slurp_bytes';
 
 my $schema = DBICTest->init_schema();
 
-my $lfn = file("t/var/sql-$$.log");
-unlink $lfn or die $!
-  if -e $lfn;
+my $log_fn = "t/var/sql-$$.log";
+unlink $log_fn or die $! if -e $log_fn;
 
 # make sure we are testing the vanilla debugger and not ::PrettyPrint
 require DBIx::Class::Storage::Statistics;
 $schema->storage->debugobj(DBIx::Class::Storage::Statistics->new);
 
 ok ( $schema->storage->debug(1), 'debug' );
-$schema->storage->debugfh($lfn->openw);
-$schema->storage->debugfh->autoflush(1);
-$schema->resultset('CD')->count;
+{
+  open my $dbgfh, '>', $log_fn or die $!;
+  $schema->storage->debugfh($dbgfh);
+  $schema->storage->debugfh->autoflush(1);
+  $schema->resultset('CD')->count;
+  $schema->storage->debugfh(undef);
+}
 
-my @loglines = $lfn->slurp;
+my @loglines = slurp_bytes $log_fn;
 is (@loglines, 1, 'one line of log');
 like($loglines[0], qr/^SELECT COUNT/, 'File log via debugfh success');
 
-$schema->storage->debugfh(undef);
 
 {
-  local $ENV{DBIC_TRACE} = "=$lfn";
-  unlink $lfn;
+  local $ENV{DBIC_TRACE} = "=$log_fn";
+  unlink $log_fn;
 
   $schema->resultset('CD')->count;
 
   my $schema2 = DBICTest->init_schema(no_deploy => 1);
   $schema2->storage->_do_query('SELECT 1'); # _do_query() logs via standard mechanisms
 
-  my @loglines = $lfn->slurp;
+  my @loglines = slurp_bytes $log_fn;
   is(@loglines, 2, '2 lines of log');
   like($loglines[0], qr/^SELECT COUNT/, 'Env log from schema1 success');
   like($loglines[1], qr/^SELECT 1:/, 'Env log from schema2 success');
@@ -60,7 +62,7 @@ $schema->storage->debugfh(undef);
 }
 
 END {
-  unlink $lfn;
+  unlink $log_fn if $log_fn;
 }
 
 open(STDERRCOPY, '>&STDERR');