| Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/DBIx/MultiStatementDo.pm |
| Statements | Executed 16 statements in 517µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 2.34ms | 6.22ms | DBIx::MultiStatementDo::BEGIN@11 |
| 1 | 1 | 1 | 1.29ms | 291ms | DBIx::MultiStatementDo::BEGIN@8 |
| 1 | 1 | 1 | 8µs | 35µs | DBIx::MultiStatementDo::BEGIN@9 |
| 1 | 1 | 1 | 7µs | 62µs | DBIx::MultiStatementDo::BEGIN@113 |
| 1 | 1 | 1 | 5µs | 5µs | DBIx::MultiStatementDo::BEGIN@3 |
| 0 | 0 | 0 | 0s | 0s | DBIx::MultiStatementDo::__ANON__[:36] |
| 0 | 0 | 0 | 0s | 0s | DBIx::MultiStatementDo::_do_statements |
| 0 | 0 | 0 | 0s | 0s | DBIx::MultiStatementDo::_set_splitter |
| 0 | 0 | 0 | 0s | 0s | DBIx::MultiStatementDo::do |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | ## no critic | ||||
| 2 | package DBIx::MultiStatementDo; | ||||
| 3 | # spent 5µs within DBIx::MultiStatementDo::BEGIN@3 which was called:
# once (5µs+0s) by BenchmarkAnything::Storage::Frontend::Lib::BEGIN@280 at line 5 | ||||
| 4 | 1 | 3µs | $DBIx::MultiStatementDo::VERSION = '1.00009'; | ||
| 5 | 1 | 15µs | 1 | 5µs | } # spent 5µs making 1 call to DBIx::MultiStatementDo::BEGIN@3 |
| 6 | ## use critic | ||||
| 7 | |||||
| 8 | 2 | 70µs | 2 | 294ms | # spent 291ms (1.29+290) within DBIx::MultiStatementDo::BEGIN@8 which was called:
# once (1.29ms+290ms) by BenchmarkAnything::Storage::Frontend::Lib::BEGIN@280 at line 8 # spent 291ms making 1 call to DBIx::MultiStatementDo::BEGIN@8
# spent 2.57ms making 1 call to Moose::import |
| 9 | 2 | 22µs | 2 | 62µs | # spent 35µs (8+27) within DBIx::MultiStatementDo::BEGIN@9 which was called:
# once (8µs+27µs) by BenchmarkAnything::Storage::Frontend::Lib::BEGIN@280 at line 9 # spent 35µs making 1 call to DBIx::MultiStatementDo::BEGIN@9
# spent 27µs making 1 call to Exporter::import |
| 10 | |||||
| 11 | 3 | 348µs | 3 | 6.23ms | # spent 6.22ms (2.34+3.88) within DBIx::MultiStatementDo::BEGIN@11 which was called:
# once (2.34ms+3.88ms) by BenchmarkAnything::Storage::Frontend::Lib::BEGIN@280 at line 11 # spent 6.22ms making 1 call to DBIx::MultiStatementDo::BEGIN@11
# spent 6µs making 1 call to UNIVERSAL::VERSION
# spent 2µs making 1 call to Class::Accessor::import |
| 12 | |||||
| 13 | 1 | 800ns | 1 | 7.30ms | has 'dbh' => ( # spent 7.30ms making 1 call to Moose::has |
| 14 | is => 'rw', | ||||
| 15 | isa => 'DBI::db', | ||||
| 16 | required => 1 | ||||
| 17 | ); | ||||
| 18 | |||||
| 19 | 1 | 2µs | 1 | 3.05ms | has 'splitter_options' => ( # spent 3.05ms making 1 call to Moose::has |
| 20 | is => 'rw', | ||||
| 21 | isa => 'Maybe[HashRef[Bool]]', | ||||
| 22 | trigger => \&_set_splitter, | ||||
| 23 | default => undef | ||||
| 24 | ); | ||||
| 25 | |||||
| 26 | sub _set_splitter { | ||||
| 27 | my ($self, $new_options) = @_; | ||||
| 28 | $self->_splitter( SQL::SplitStatement->new($new_options) ) | ||||
| 29 | } | ||||
| 30 | |||||
| 31 | has '_splitter' => ( | ||||
| 32 | is => 'rw', | ||||
| 33 | isa => 'SQL::SplitStatement', | ||||
| 34 | handles => [ qw(split split_with_placeholders) ], | ||||
| 35 | lazy => 1, | ||||
| 36 | default => sub { SQL::SplitStatement->new } | ||||
| 37 | 1 | 4µs | 1 | 1.84ms | ); # spent 1.84ms making 1 call to Moose::has |
| 38 | |||||
| 39 | 1 | 1µs | 1 | 1.04ms | has 'rollback' => ( # spent 1.04ms making 1 call to Moose::has |
| 40 | is => 'rw', | ||||
| 41 | isa => 'Bool', | ||||
| 42 | default => 1 | ||||
| 43 | ); | ||||
| 44 | |||||
| 45 | sub do { | ||||
| 46 | my ($self, $code, $attr, @bind_values) = @_; | ||||
| 47 | |||||
| 48 | my ( $statements, $placeholders ) | ||||
| 49 | = ! ref($code) | ||||
| 50 | ? $self->split_with_placeholders($code) | ||||
| 51 | : ref( $code->[0] ) eq 'ARRAY' | ||||
| 52 | ? @$code | ||||
| 53 | : ( $code, undef ); | ||||
| 54 | |||||
| 55 | my @compound_bind_values; | ||||
| 56 | if ( @bind_values >= 1 ) { | ||||
| 57 | if ( ! ref $bind_values[0] ) { | ||||
| 58 | # @bind_values was a FLAT LIST | ||||
| 59 | ref($placeholders) ne 'ARRAY' and croak( | ||||
| 60 | q[Bind values as a flat list require the placeholder numbers listref to be passed as well] | ||||
| 61 | ); | ||||
| 62 | push @compound_bind_values, [ splice @bind_values, 0, $_ ] | ||||
| 63 | foreach @$placeholders | ||||
| 64 | } else { | ||||
| 65 | @compound_bind_values = @{ $bind_values[0] } | ||||
| 66 | } | ||||
| 67 | } | ||||
| 68 | |||||
| 69 | |||||
| 70 | my $dbh = $self->dbh; | ||||
| 71 | my @results; | ||||
| 72 | |||||
| 73 | if ( $self->rollback ) { | ||||
| 74 | local $dbh->{AutoCommit} = 0; | ||||
| 75 | local $dbh->{RaiseError} = 1; | ||||
| 76 | eval { | ||||
| 77 | @results = $self->_do_statements( | ||||
| 78 | $statements, $attr, \@compound_bind_values | ||||
| 79 | ); | ||||
| 80 | $dbh->commit; | ||||
| 81 | 1 | ||||
| 82 | } or eval { | ||||
| 83 | $dbh->rollback | ||||
| 84 | } | ||||
| 85 | } else { | ||||
| 86 | @results = $self->_do_statements( | ||||
| 87 | $statements, $attr, \@compound_bind_values | ||||
| 88 | ) | ||||
| 89 | } | ||||
| 90 | |||||
| 91 | return @results if wantarray; # List context. | ||||
| 92 | return 1 if @results == @$statements; # Scalar context and success. | ||||
| 93 | return # Scalar context and failure. | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | sub _do_statements { | ||||
| 97 | my ($self, $statements, $attr, $compound_bind_values) = @_; | ||||
| 98 | |||||
| 99 | my @results; | ||||
| 100 | my $dbh = $self->dbh; | ||||
| 101 | |||||
| 102 | for my $statement ( @$statements ) { | ||||
| 103 | my $result = $dbh->do( | ||||
| 104 | $statement, $attr, @{ shift(@$compound_bind_values) || [] } | ||||
| 105 | ); | ||||
| 106 | last unless $result; | ||||
| 107 | push @results, $result | ||||
| 108 | } | ||||
| 109 | |||||
| 110 | return @results | ||||
| 111 | } | ||||
| 112 | |||||
| 113 | 2 | 22µs | 2 | 118µs | # spent 62µs (7+55) within DBIx::MultiStatementDo::BEGIN@113 which was called:
# once (7µs+55µs) by BenchmarkAnything::Storage::Frontend::Lib::BEGIN@280 at line 113 # spent 62µs making 1 call to DBIx::MultiStatementDo::BEGIN@113
# spent 55µs making 1 call to Moose::unimport |
| 114 | 1 | 5µs | 2 | 17.3ms | __PACKAGE__->meta->make_immutable; # spent 17.3ms making 1 call to Class::MOP::Class::make_immutable
# spent 8µs making 1 call to DBIx::MultiStatementDo::meta |
| 115 | |||||
| 116 | 1 | 22µs | 1; | ||
| 117 | |||||
| 118 | __END__ |