| 1 | package DBIx::Class::QueryLog::Transaction; | ||||||||||
| 2 | 6 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 6 | extends 'DBIx::Class::QueryLog::Query'; | |||||||||
| 5 | |||||||||||
| 6 | 6 | has committed => ( | |||||||||
| 7 | is => 'rw', | ||||||||||
| 8 | isa => 'Bool' | ||||||||||
| 9 | ); | ||||||||||
| 10 | |||||||||||
| 11 | has queries => ( | ||||||||||
| 12 | traits => [qw(Array)], | ||||||||||
| 13 | is => 'rw', | ||||||||||
| 14 | isa => 'ArrayRef', | ||||||||||
| 15 | 5 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 6 | handles => { | |||||||||
| 17 | count => 'count', | ||||||||||
| 18 | add_to_queries => 'push' | ||||||||||
| 19 | } | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 6 | has rolledback => ( | |||||||||
| 23 | is => 'rw', | ||||||||||
| 24 | isa => 'Bool' | ||||||||||
| 25 | ); | ||||||||||
| 26 | |||||||||||
| 27 | =head1 NAME | ||||||||||
| 28 | |||||||||||
| 29 | DBIx::Class::QueryLog::Transaction - A Transaction | ||||||||||
| 30 | |||||||||||
| 31 | =head1 SYNOPSIS | ||||||||||
| 32 | |||||||||||
| 33 | Represents a transaction. All queries executed with the context of this | ||||||||||
| 34 | transaction are stored herein, as well as a start time, end time and flag | ||||||||||
| 35 | for committed or rolledback. | ||||||||||
| 36 | |||||||||||
| 37 | =head1 METHODS | ||||||||||
| 38 | |||||||||||
| 39 | =head2 new | ||||||||||
| 40 | |||||||||||
| 41 | Create a new DBIx::Class::QueryLog::Transcation | ||||||||||
| 42 | |||||||||||
| 43 | =head2 bucket | ||||||||||
| 44 | |||||||||||
| 45 | The bucket this tranaction is in. | ||||||||||
| 46 | |||||||||||
| 47 | =head2 queries | ||||||||||
| 48 | |||||||||||
| 49 | Arrayref containing all queries executed, in order of execution. | ||||||||||
| 50 | |||||||||||
| 51 | =head2 committed | ||||||||||
| 52 | |||||||||||
| 53 | Flag indicating if this transaction was committed. | ||||||||||
| 54 | |||||||||||
| 55 | =head2 rolledback | ||||||||||
| 56 | |||||||||||
| 57 | Flag indicating if this transaction was rolled back. | ||||||||||
| 58 | |||||||||||
| 59 | =head2 start_time | ||||||||||
| 60 | |||||||||||
| 61 | Time this transaction started. | ||||||||||
| 62 | |||||||||||
| 63 | =head2 end_time | ||||||||||
| 64 | |||||||||||
| 65 | Time this transaction ended. | ||||||||||
| 66 | |||||||||||
| 67 | =head2 time_elapsed | ||||||||||
| 68 | |||||||||||
| 69 | Time this transaction took to execute. start - end. | ||||||||||
| 70 | |||||||||||
| 71 | =cut | ||||||||||
| 72 | sub time_elapsed { | ||||||||||
| 73 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
time_elapsed: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 74 | |||||||||||
| 75 | 0 | my $total = 0; | |||||||||
| 76 | 0 | foreach my $q (@{ $self->queries }) { | |||||||||
| 77 | 0 | $total += $q->time_elapsed; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 0 | return $total; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | =head2 add_to_queries | ||||||||||
| 84 | |||||||||||
| 85 | Add the provided query to this transactions list. | ||||||||||
| 86 | |||||||||||
| 87 | =head2 count | ||||||||||
| 88 | |||||||||||
| 89 | Returns the number of queries in this Transaction | ||||||||||
| 90 | |||||||||||
| 91 | =head2 get_sorted_queries([ $sql ]) | ||||||||||
| 92 | |||||||||||
| 93 | Returns all the queries in this Transaction, sorted by elapsed time. | ||||||||||
| 94 | (descending). | ||||||||||
| 95 | |||||||||||
| 96 | If given an argument of an SQL statement, only queries matching that statement | ||||||||||
| 97 | will be considered. | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||
| 100 | sub get_sorted_queries { | ||||||||||
| 101 | 4 | ▶ | my ($self, $sql) = @_; | ||||||||
|
Subroutine
get_sorted_queries: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 102 | |||||||||||
| 103 | 4 | my @qs; | |||||||||
| 104 | 4 | ▶ | if($sql) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 3 | @qs = grep({ $_->sql eq $sql } @{ $self->queries }); | |||||||||
| 106 | } else { | ||||||||||
| 107 | 1 | @qs = @{ $self->queries }; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 4 | return [ reverse sort { $a->time_elapsed <=> $b->time_elapsed } @qs ]; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | =head1 AUTHOR | ||||||||||
| 114 | |||||||||||
| 115 | Cory G Watson, C<< <gphat at cpan.org> >> | ||||||||||
| 116 | |||||||||||
| 117 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 118 | |||||||||||
| 119 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 120 | |||||||||||
| 121 | Copyright 2009 Cory G Watson, all rights reserved. | ||||||||||
| 122 | |||||||||||
| 123 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 124 | under the same terms as Perl itself. | ||||||||||
| 125 | |||||||||||
| 126 | =cut | ||||||||||
| 127 | |||||||||||
| 128 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||
| 129 | |||||||||||
| 130 | 6 | 1; | |||||||||