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 {
