Show
Ignore:
Timestamp:
03/21/08 21:33:57 (7 years ago)
Author:
charsbar
Message:

lang/perl/Catalyst-Model-Jifty-DBI: added ->trace and 0.04 -> CPAN

Location:
lang/perl/Catalyst-Model-Jifty-DBI/trunk
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Catalyst-Model-Jifty-DBI/trunk/Changes

    r2067 r8255  
    11Revision history for Catalyst-Model-Jifty-DBI 
     2 
     30.04 2008/03/21 
     4  - bumped up the version requirement of Test::UseAllModules to 0.09 
     5  - added ->trace method 
    26 
    370.03 2007/11/27 
  • lang/perl/Catalyst-Model-Jifty-DBI/trunk/MANIFEST

    r2067 r8255  
    77t/00_load.t 
    88t/10_testapp.t 
     9t/20_trace.t 
    910t/99_pod.t 
    1011t/99_podcoverage.t 
  • lang/perl/Catalyst-Model-Jifty-DBI/trunk/Makefile.PL

    r2067 r8255  
    1616        'Module::Find'          => 0, 
    1717        'NEXT'                  => 0, 
    18         'Test::UseAllModules'   => 0, 
     18        'Test::UseAllModules'   => 0.09, 
    1919        'UNIVERSAL::require'    => 0.11, 
    2020    }, 
  • lang/perl/Catalyst-Model-Jifty-DBI/trunk/lib/Catalyst/Model/Jifty/DBI.pm

    r2067 r8255  
    66use base qw( Catalyst::Model Class::Accessor::Fast ); 
    77 
    8 our $VERSION = '0.03'; 
     8our $VERSION = '0.04'; 
    99 
    1010use NEXT; 
     
    206206sub simple_query      { shift->handle->simple_query( @_ ) } 
    207207sub fetch_result      { shift->handle->fetch_result( @_ ) } 
     208 
     209sub trace { 
     210  my ($self, $code) = @_; 
     211 
     212  if ( ref $code eq 'CODE' ) { 
     213    $self->handle->log_sql_statements(1); 
     214    $self->handle->log_sql_hook( trace => $code ); 
     215  } 
     216  elsif ( $code ) { 
     217    require Data::Dump; 
     218    $self->handle->log_sql_statements(1); 
     219    $self->handle->log_sql_hook( 
     220      trace => sub { print STDERR Data::Dump::dump(@_) } 
     221    ); 
     222  } 
     223  else { 
     224    $self->handle->log_sql_statements(0); 
     225  } 
     226} 
    208227 
    2092281; 
     
    307326              ->simple_query( $sql_statement, @binds ); 
    308327 
     328When you want to debug (against the default handle): 
     329 
     330  $c->model('JDBI')->trace(1);  # start logging 
     331  $c->model('JDBI')->trace(0);  # stop logging 
     332 
    309333=head1 BACKWARD INCOMPATIBILITY 
    310334 
     
    335359=head2 new 
    336360 
    337 creates a model. Database connection may be or not be prepared, according to the number of connect_info. See above for the configuration. 
     361creates a model. Database connection may or may not be prepared, according to the number of connect_info. See above for the configuration. 
    338362 
    339363=head2 record 
     
    365389=head2 collection 
    366390 
    367 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. 
     391creates 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. 
    368392 
    369393  # this works. 
     
    465489This also is a shortcut to ->handle->disconnect. You can pass an optional hash to specify target database. 
    466490 
     491=head2 trace 
     492 
     493turns 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. 
     494 
     495  $c->model('JDBI')->trace(sub { 
     496    my ($time, $statement, $binding, $duration, $result) = @_; 
     497    warn $statement, "\n", @$binding; 
     498  }); 
     499 
     500See L<Jifty::DBI::Handle> for details (log_sql_hook / sql_statement_log). 
     501 
    467502=head1 SEE ALSO 
    468503