Commit | Line | Data |
---|---|---|
0d5df7d6 | 1 | package DBIx::Class::Storage::Debug::PrettyPrint; |
1dc93d17 | 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 { | |
0d5df7d6 | 10 | my $class = shift; |
1dc93d17 | 11 | |
0d5df7d6 | 12 | my $sqlat = SQL::Abstract::Tree->new(shift @_); |
13 | my $self = $class->next::method(@_); | |
1dc93d17 | 14 | |
0d5df7d6 | 15 | $self->_sqlat($sqlat); |
1dc93d17 | 16 | |
0d5df7d6 | 17 | return $self |
1dc93d17 | 18 | } |
19 | ||
31756ef2 | 20 | sub print { |
1dc93d17 | 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; | |
6b1bf9f8 | 30 | |
31 | =pod | |
32 | ||
33 | =head1 SYNOPSIS | |
34 | ||
35 | package MyApp::Schema; | |
36 | ||
37 | use parent 'DBIx::Class::Schema'; | |
38 | ||
0d5df7d6 | 39 | use DBIx::Class::Storage::Debug::PrettyPrint; |
6b1bf9f8 | 40 | |
41 | __PACKAGE__->load_namespaces; | |
42 | ||
0d5df7d6 | 43 | my $pp = DBIx::Class::Storage::Debug::PrettyPrint->new({ |
44 | profile => 'console', | |
45 | }); | |
6b1bf9f8 | 46 | |
47 | sub connection { | |
0d5df7d6 | 48 | my $self = shift; |
6b1bf9f8 | 49 | |
0d5df7d6 | 50 | my $ret = $self->next::method(@_); |
6b1bf9f8 | 51 | |
0d5df7d6 | 52 | $self->storage->debugobj($pp); |
6b1bf9f8 | 53 | |
0d5df7d6 | 54 | $ret |
6b1bf9f8 | 55 | } |
56 |