| 1 | package DBIx::Class::Storage::Debug::PrettyTrace; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use base 'DBIx::Class::Storage::Statistics'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use SQL::Abstract::Tree; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | __PACKAGE__->mk_group_accessors( simple => '_sqlat' ); | |||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | __PACKAGE__->mk_group_accessors( simple => '_clear_line_str' ); | |||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | __PACKAGE__->mk_group_accessors( simple => '_executing_str' ); | |||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | __PACKAGE__->mk_group_accessors( simple => '_show_progress' ); | |||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | __PACKAGE__->mk_group_accessors( simple => '_last_sql' ); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | __PACKAGE__->mk_group_accessors( simple => 'squash_repeats' ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | my $clear_line = $args->{clear_line} || "\r\x1b[J"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'clear_line'} || "\r\e[J"
MC/DC100%1/1
$args->{'clear_line'} || "\r\e[J"
$args->{'clear_line'}
Truth table100%2/2
A
A= $args->{'clear_line'}
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | my $executing = $args->{executing} || ( | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | eval { require Term::ANSIColor } ? do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args->{'executing'} || (eval {
do {
require Term::ANSIColor
}
} ? do {
my $c = \&Term::ANSIColor::color;
&$c('blink white on_black') . 'EXECUTING...' . &$c('reset')
} : 'EXECUTING...')
MC/DC0%0/2
$args->{'executing'} || (eval {
do {
require Term::ANSIColor
}
} ? do {
my $c = \&Term::ANSIColor::color;
&$c('blink white on_black') . 'EXECUTING...' . &$c('reset')
} : 'EXECUTING...')
$args->{'executing'}
(eval {
do {
require Term::ANSIColor
}
} ? do {
my $c = \&Term::ANSIColor::color;
&$c('blink white on_black') . 'EXECUTING...' . &$c('reset')
} : 'EXECUTING...')
Truth table66%2/3
A || B
A= $args->{'executing'}B= (eval {
do {
require Term::ANSIColor
}
} ? do {
my $c = \&Term::ANSIColor::color;
&$c('blink white on_black') . 'EXECUTING...' . &$c('reset')
} : 'EXECUTING...')
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | my $c = \&Term::ANSIColor::color; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | $c->('blink white on_black') . 'EXECUTING...' . $c->('reset'); | |||||||||||||||||||||||||||||||||||||||||
| 26 | } : 'EXECUTING...' | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | my $show_progress = $args->{show_progress}; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | my $squash_repeats = $args->{squash_repeats}; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | my $sqlat = SQL::Abstract::Tree->new($args); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | my $self = $class->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | $self->_clear_line_str($clear_line); | |||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | $self->_executing_str($executing); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | $self->_show_progress($show_progress); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | $self->squash_repeats($squash_repeats); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | $self->_sqlat($sqlat); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | $self->_last_sql(''); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | return $self | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | ▶ | sub print { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 8 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | ▶ | my $bindargs = shift || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || []
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 8 | my ($lw, $lr); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 8 | ($lw, $string, $lr) = $string =~ /^(\s*)(.+?)(\s*)$/s; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 8 | ▶ | local $self->_sqlat->{fill_in_placeholders} = 0 if defined $bindargs | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $bindargs and defined $bindargs->[0] and $bindargs->[0] eq "'__BULK_INSERT__'"
defined $bindargs and defined $bindargs->[0]
MC/DC66%2/3
defined $bindargs and defined $bindargs->[0] and $bindargs->[0] eq "'__BULK_INSERT__'"
defined $bindargs
defined $bindargs->[0]
$bindargs->[0] eq "'__BULK_INSERT__'"
Truth table75%3/4
A and B and C
A= defined $bindargsB= defined $bindargs->[0]C= $bindargs->[0] eq "'__BULK_INSERT__'"
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | && defined $bindargs->[0] && $bindargs->[0] eq q('__BULK_INSERT__'); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | my $use_placeholders = !!$self->_sqlat->fill_in_placeholders; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 8 | my $sqlat = $self->_sqlat; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 8 | my $formatted; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 8 | ▶ | if ($self->squash_repeats && $self->_last_sql eq $string) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->squash_repeats and $self->_last_sql eq $string
MC/DC100%2/2
$self->squash_repeats and $self->_last_sql eq $string
$self->squash_repeats
$self->_last_sql eq $string
Truth table100%3/3
A and B
A= $self->squash_repeatsB= $self->_last_sql eq $string
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | my ( $l, $r ) = @{ $sqlat->placeholder_surround }; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | $formatted = '... : ' . join(', ', map "$l$_$r", @$bindargs) | |||||||||||||||||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | $self->_last_sql($string); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | $formatted = $sqlat->format($string, $bindargs); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | ▶ | $formatted = "$formatted : " . join ', ', @{$bindargs} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | unless $use_placeholders; | ||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 8 | $self->next::method("$lw$formatted$lr", @_); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | ▶ | sub query_start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_start: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 8 | my ($self, $string, @bind) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 8 | ▶ | if (defined $self->callback) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $string =~ m/^(\w+)/; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $self->callback->($1, "$string: ".join(', ', @bind)."\n"); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 8 | $string =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 8 | $self->print("$string\n", \@bind); | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | ▶ | $self->debugfh->print($self->_executing_str) if $self->_show_progress | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | sub query_end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_end: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | $_[0]->debugfh->print($_[0]->_clear_line_str) if $_[0]->_show_progress | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | DBIx::Class::Storage::Debug::PrettyTrace - Pretty Tracing DebugObj | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | DBIC_TRACE_PROFILE=~/dbic.json perl -Ilib ./foo.pl | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | Where dbic.json contains: | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | "profile":"console", | ||||||||||||||||||||||||||||||||||||||||||
| 109 | "show_progress":1, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | "squash_repeats":1 | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | my $pp = DBIx::Class::Storage::Debug::PrettyTrace->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 118 | show_progress => 1, # tries it's best to make it clear that a SQL | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # statement is still running | ||||||||||||||||||||||||||||||||||||||||||
| 120 | executing => '...', # the string that is added to the end of SQL | ||||||||||||||||||||||||||||||||||||||||||
| 121 | # if show_progress is on. You probably don't | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # need to set this | ||||||||||||||||||||||||||||||||||||||||||
| 123 | clear_line => '<CR><ESC>[J', # the string used to erase the string added | ||||||||||||||||||||||||||||||||||||||||||
| 124 | # to SQL if show_progress is on. Again, the | ||||||||||||||||||||||||||||||||||||||||||
| 125 | # default is probably good enough. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | squash_repeats => 1, # set to true to make repeated SQL queries | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # be ellided and only show the new bind params | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # any other args are passed through directly to SQL::Abstract::Tree | ||||||||||||||||||||||||||||||||||||||||||
| 130 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | =head1 FURTHER QUESTIONS? | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE> | ||||||||||||||||||||||||||||||||||||||||||
| 139 | by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can | ||||||||||||||||||||||||||||||||||||||||||
| 140 | redistribute it and/or modify it under the same terms as the | ||||||||||||||||||||||||||||||||||||||||||
| 141 | L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||||||||||||||||||||||||