1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
Description: Add sprintf method to return the profiling data instead of print it
Author: Ivan Kohler <ivan@debian.org>
Bug: https://rt.cpan.org/Public/Bug/Display.html?id=738
Forwarded: https://rt.cpan.org/Public/Bug/Display.html?id=738
Reviewed-By: Xavier Guimard <x.guimard@free.fr>
Last-Update: 2012-12-23
--- a/Profile.pm
+++ b/Profile.pm
@@ -225,9 +225,16 @@
# JEFF - The printing and the print code is kinda (er... very) ugly!
#
+#like printProfile, except returns the results instead of printing them.
+sub sprintProfile {
+ my $self = shift;
+ $self->printProfile({'sprint'=>1});
+}
+
sub printProfile {
my $self = shift;
+ my $args = shift;
my %result;
my $total = 0;
no integer;
@@ -292,13 +299,18 @@
$result{$total} = $text;
} # each query
+ my $results;
foreach my $qry (sort stripsort keys %result) {
- if ($DBIx::Profile::DBIXFILE eq "" ) {
+ if ( $args->{'sprint'} ) {
+ $results .= $result{$qry} . "\n";
+ } elsif ($DBIx::Profile::DBIXFILE eq "" ) {
warn $result{$qry} . "\n";
} else {
print $DBIx::Profile::DBIXFILEHANDLE $result{$qry} . "\n";
}
}
+
+ return $results if $args->{'sprint'};
}
sub stripsort {
|