Index: lang/perl/Catalyst-Model-Jifty-DBI/trunk/t/20_trace.t
===================================================================
--- lang/perl/Catalyst-Model-Jifty-DBI/trunk/t/20_trace.t (revision 8255)
+++ lang/perl/Catalyst-Model-Jifty-DBI/trunk/t/20_trace.t (revision 8255)
@@ -0,0 +1,58 @@
+use strict;
+use warnings;
+use Test::More;
+use lib qw( t/TestApp/lib );
+
+BEGIN {
+  unless ( $ENV{TEST_C_M_JDBI} ) {
+    plan skip_all => 'set $ENV{TEST_C_M_JDBI} '.
+                     'to enable this test';
+  }
+  eval "require IO::Capture::Stderr";
+  if ( $@ ) {
+    plan skip_all => 'requires IO::Capture::Stderr';
+  }
+}
+
+plan tests => 4;
+
+use TestApp::Model::JDBI;
+
+my $model   = TestApp::Model::JDBI->new;
+my $capture = IO::Capture::Stderr->new;
+
+clear();
+
+$model->setup_database;
+
+ok !capture(), 'no log by default';
+
+$model->trace(1);
+
+ok capture(), 'logged';
+
+$model->trace(0);
+
+ok !capture(), 'log disabled';
+
+$model->trace(sub { print STDERR 'logged' });
+
+ok capture() eq 'logged', 'logger is replaced';
+
+END { clear() }
+
+sub clear {
+  if ( -f $model->database && -s $model->database ) {
+    $model->disconnect;
+    unlink $model->database;
+  }
+}
+
+sub capture {
+  $capture->start;
+  my $author = $model->record('Author');
+     $author->load(1);
+  $capture->stop;
+
+  return $capture->read;
+}
Index: lang/perl/Catalyst-Model-Jifty-DBI/trunk/MANIFEST
===================================================================
--- lang/perl/Catalyst-Model-Jifty-DBI/trunk/MANIFEST (revision 2067)
+++ lang/perl/Catalyst-Model-Jifty-DBI/trunk/MANIFEST (revision 8255)
@@ -7,4 +7,5 @@
 t/00_load.t
 t/10_testapp.t
+t/20_trace.t
 t/99_pod.t
 t/99_podcoverage.t
Index: lang/perl/Catalyst-Model-Jifty-DBI/trunk/lib/Catalyst/Model/Jifty/DBI.pm
===================================================================
--- lang/perl/Catalyst-Model-Jifty-DBI/trunk/lib/Catalyst/Model/Jifty/DBI.pm (revision 2067)
+++ lang/perl/Catalyst-Model-Jifty-DBI/trunk/lib/Catalyst/Model/Jifty/DBI.pm (revision 8255)
@@ -6,5 +6,5 @@
 use base qw( Catalyst::Model Class::Accessor::Fast );
 
-our $VERSION = '0.03';
+our $VERSION = '0.04';
 
 use NEXT;
@@ -206,4 +206,23 @@
 sub simple_query      { shift->handle->simple_query( @_ ) }
 sub fetch_result      { shift->handle->fetch_result( @_ ) }
+
+sub trace {
+  my ($self, $code) = @_;
+
+  if ( ref $code eq 'CODE' ) {
+    $self->handle->log_sql_statements(1);
+    $self->handle->log_sql_hook( trace => $code );
+  }
+  elsif ( $code ) {
+    require Data::Dump;
+    $self->handle->log_sql_statements(1);
+    $self->handle->log_sql_hook(
+      trace => sub { print STDERR Data::Dump::dump(@_) }
+    );
+  }
+  else {
+    $self->handle->log_sql_statements(0);
+  }
+}
 
 1;
@@ -307,4 +326,9 @@
               ->simple_query( $sql_statement, @binds );
 
+When you want to debug (against the default handle):
+
+  $c->model('JDBI')->trace(1);  # start logging
+  $c->model('JDBI')->trace(0);  # stop logging
+
 =head1 BACKWARD INCOMPATIBILITY
 
@@ -335,5 +359,5 @@
 =head2 new
 
-creates a model. Database connection may be or not be prepared, according to the number of connect_info. See above for the configuration.
+creates a model. Database connection may or may not be prepared, according to the number of connect_info. See above for the configuration.
 
 =head2 record
@@ -365,5 +389,5 @@
 =head2 collection
 
-creates and returns a corresponding (new) Jifty::DBI::Collection object. If you haven't created a Collection class but only a Schema/Record class, this model creates a plain Collection class on the fly. I recommend not to omit the obvious 'Collection' part of the class name, but if you prefer, you can spare that part when you explicitly call model("Model")->collection("Schema") (you can't omit if you follow the model("Model::Schema") convention). Other general usage and caveats are the same as ->record.
+creates and returns a corresponding (new) Jifty::DBI::Collection object. If you haven't created a Collection class but only a Schema/Record class, this model creates a plain Collection class on the fly. I recommend not to omit the obvious 'Collection' part of the class name, but if you prefer, you can spare that when you explicitly call model("Model")->collection("Schema") (you can't omit if you follow the model("Model::Schema") convention). Other general usage and caveats are the same as ->record.
 
   # this works.
@@ -465,4 +489,15 @@
 This also is a shortcut to ->handle->disconnect. You can pass an optional hash to specify target database.
 
+=head2 trace
+
+turns on and off the logging of sql statements. If this is set to true, C::M::Jifty::DBI spits the info to STDERR. If you want finer control, give it a code reference.
+
+  $c->model('JDBI')->trace(sub {
+    my ($time, $statement, $binding, $duration, $result) = @_;
+    warn $statement, "\n", @$binding;
+  });
+
+See L<Jifty::DBI::Handle> for details (log_sql_hook / sql_statement_log).
+
 =head1 SEE ALSO
 
Index: lang/perl/Catalyst-Model-Jifty-DBI/trunk/Makefile.PL
===================================================================
--- lang/perl/Catalyst-Model-Jifty-DBI/trunk/Makefile.PL (revision 2067)
+++ lang/perl/Catalyst-Model-Jifty-DBI/trunk/Makefile.PL (revision 8255)
@@ -16,5 +16,5 @@
         'Module::Find'          => 0,
         'NEXT'                  => 0,
-        'Test::UseAllModules'   => 0,
+        'Test::UseAllModules'   => 0.09,
         'UNIVERSAL::require'    => 0.11,
     },
Index: lang/perl/Catalyst-Model-Jifty-DBI/trunk/Changes
===================================================================
--- lang/perl/Catalyst-Model-Jifty-DBI/trunk/Changes (revision 2067)
+++ lang/perl/Catalyst-Model-Jifty-DBI/trunk/Changes (revision 8255)
@@ -1,3 +1,7 @@
 Revision history for Catalyst-Model-Jifty-DBI
+
+0.04 2008/03/21
+  - bumped up the version requirement of Test::UseAllModules to 0.09
+  - added ->trace method
 
 0.03 2007/11/27
