update changes
[dbsrgits/SQL-Abstract.git] / lib / DBIx / Class / Storage / Debug / PrettyPrint.pm
1 package DBIx::Class::Storage::Debug::PrettyPrint;
2
3 use base 'DBIx::Class::Storage::Statistics';
4
5 use SQL::Abstract::Tree;
6
7 __PACKAGE__->mk_group_accessors( simple => '_sqlat' );
8
9 sub new {
10    my $class = shift;
11
12    my $sqlat = SQL::Abstract::Tree->new(shift @_);
13    my $self = $class->next::method(@_);
14
15    $self->_sqlat($sqlat);
16
17    return $self
18 }
19
20 sub query_start {
21   my $self = shift;
22   my $string = shift;
23
24   my $formatted = $self->_sqlat->format($string);
25
26   $self->next::method($formatted, @_);
27 }
28
29 1;
30
31 =pod
32
33 =head1 SYNOPSIS
34
35  package MyApp::Schema;
36
37  use parent 'DBIx::Class::Schema';
38
39  use DBIx::Class::Storage::Debug::PrettyPrint;
40
41  __PACKAGE__->load_namespaces;
42
43  my $pp = DBIx::Class::Storage::Debug::PrettyPrint->new({
44    profile => 'console',
45  });
46
47  sub connection {
48    my $self = shift;
49
50    my $ret = $self->next::method(@_);
51
52    $self->storage->debugobj($pp);
53
54    $ret
55  }
56