extends 'DBIx::Class';
use DBIx::Class::_Util qw(sigwarn_silencer qsub);
-use IO::Handle ();
use namespace::clean;
=head1 NAME
Sets or retrieves the filehandle used for trace/debug output. This should
be an L<IO::Handle> compatible object (only the
-L<< printflush|IO::Handle/$io->printflush_(_ARGS_) >> method is used). By
+L<< print|IO::Handle/METHODS >> method is used). By
default it is initially set to STDERR - although see discussion of the
L<DBIC_TRACE|DBIx::Class::Storage/DBIC_TRACE> environment variable.
-Invoked as a getter it will lazily open a filehandle for you if one is not
-already set.
+Invoked as a getter it will lazily open a filehandle and set it to
+L<< autoflush|perlvar/HANDLE->autoflush( EXPR ) >> (if one is not
+already set).
=cut
$_[0]->_defaulted_to_stderr(1);
}
+ $fh->autoflush(1);
+
$fh;
}
local $SIG{__WARN__} = sigwarn_silencer(qr/^Wide character in print/)
if $self->_defaulted_to_stderr;
- $fh->printflush($msg);
+ $fh->print($msg);
}
=head2 silence
ok ( $schema->storage->debug(1), 'debug' );
$schema->storage->debugfh($lfn->openw);
+$schema->storage->debugfh->autoflush(1);
$schema->resultset('CD')->count;
my @loglines = $lfn->slurp;
is_deeply(\@warnings, [], 'No warnings with unicode on STDERR');
-
# test debugcb and debugobj protocol
{
my $rs = $schema->resultset('CD')->search( {
is_deeply ( $do->{_traced_bind}, \@bind_trace );
}
+# recreate test as seen in DBIx::Class::QueryLog
+# the rationale is that if someone uses a non-IO::Handle object
+# on CPAN, many are *bound* to use one on darkpan. Thus this
+# test to ensure there is no future silent breakage
+{
+ my $output = "";
+
+ {
+ package DBICTest::_Printable;
+
+ sub print {
+ my ($self, @args) = @_;
+ $output .= join('', @args);
+ }
+ }
+
+ $schema->storage->debugobj(undef);
+ $schema->storage->debug(1);
+ $schema->storage->debugfh( bless {}, "DBICTest::_Printable" );
+ $schema->storage->txn_do( sub { $schema->resultset('Artist')->count } );
+
+ like (
+ $output,
+ qr/
+ \A
+ ^ \QBEGIN WORK\E \s*?
+ ^ \QSELECT COUNT( * ) FROM artist me:\E \s*?
+ ^ \QCOMMIT\E \s*?
+ \z
+ /xm
+ );
+
+ $schema->storage->debug(0);
+ $schema->storage->debugfh(undef);
+}
+
done_testing;