1 package DBIx::Class::Storage::Debug::PrettyPrint;
6 use base 'DBIx::Class::Storage::Statistics';
8 use SQL::Abstract::Tree;
10 __PACKAGE__->mk_group_accessors( simple => '_sqlat' );
11 __PACKAGE__->mk_group_accessors( simple => 'clear_line_str' );
12 __PACKAGE__->mk_group_accessors( simple => 'executing_str' );
18 my $clear_line = $args->{clear_line} || "\r
\e[J";
19 my $executing = $args->{executing} || eval { require Term::ANSIColor } ? do {
20 my $c = \&Term::ANSIColor::color;
21 $c->('blink white on_black') . 'EXECUTING...' . $c->('reset');;
25 my $sqlat = SQL::Abstract::Tree->new($args);
26 my $self = $class->next::method(@_);
27 $self->clear_line_str($clear_line);
28 $self->executing_str($executing);
30 $self->_sqlat($sqlat);
38 my $bindargs = shift || [];
41 ($lw, $string, $lr) = $string =~ /^(\s*)(.+?)(\s*)$/s;
43 return if defined $bindargs && defined $bindargs->[0] &&
44 $bindargs->[0] eq q('__BULK_INSERT__');
46 my $use_placeholders = !!$self->_sqlat->fill_in_placeholders;
48 # DBIC pre-quotes bindargs
49 $bindargs = [map { s/^'//; s/'$//; $_ } @{$bindargs}] if $use_placeholders;
51 my $formatted = $self->_sqlat->format($string, $bindargs);
53 $formatted = "$formatted: " . join ', ', @{$bindargs}
54 unless $use_placeholders;
56 $self->next::method("$lw$formatted$lr", @_);
60 my ($self, $string, @bind) = @_;
62 if(defined $self->callback) {
64 $self->callback->($1, "$string: ".join(', ', @bind)."\n");
70 $self->print("$string\n", \@bind);
72 $self->debugfh->print($self->executing_str)
76 $_[0]->debugfh->print($_[0]->clear_line_str);
85 package MyApp::Schema;
87 use parent 'DBIx::Class::Schema';
89 use DBIx::Class::Storage::Debug::PrettyPrint;
91 __PACKAGE__->load_namespaces;
93 my $pp = DBIx::Class::Storage::Debug::PrettyPrint->new({
100 my $ret = $self->next::method(@_);
102 $self->storage->debugobj($pp);