Bug patch. The bug is that if you have any profile() calls with a
Jay Hannah [Tue, 18 Nov 2008 21:29:45 +0000 (21:29 +0000)]
begin =>   but no   end =>   and you call ->report() multiple
times, profile() will throw garbage items into the Tree::Simple.

By removing the map() from Stats.pm the bug no longer occurs.

I added a test item which fails until the Stats.pm patch is applied.

To see the bug in action, uncomment the   print scalar($stats->report);
line I added without the Stats.pm patch applied. You'll see ugly blank
lines show up in the report().

You can also see that   begin =>   with no   end =>   works fine without
the map() code. The map actually breaks it, it doesn't fix anything as
far as I can tell.

Possibly cleaner would be to patch profile() so that the garbage can
never happen, but I spent several hours on that and couldn't track it
down. This solves the problem and all tests pass. And removes code that
does nothing.

Cheers,

jhannah
jay(at)jays(dot)net

lib/Catalyst/Stats.pm
t/unit_stats.t

index 303e2de..9e24108 100644 (file)
@@ -87,10 +87,6 @@ sub elapsed {
 sub report {
     my $self = shift;
 
-    # close any remaining open nodes
-    map { $self->profile(end => $_->getNodeValue->{action}) }
-      (reverse @{ $self->stack })[1 .. $#{$self->stack}];
-
     my $t = Text::SimpleTable->new( [ 62, 'Action' ], [ 9, 'Time' ] );
     my @results;
     $self->tree->traverse(
index e46baf4..928b48e 100644 (file)
@@ -69,6 +69,10 @@ BEGIN { use_ok("Catalyst::Stats") };
     $stats->profile(comment => "interleave 2");
     push(@expected, [ 4, "- interleave 2", 0.2, 0 ]);
 
+    $fudge_t[1] = 550000;
+    $stats->profile(begin => "begin with no end");
+    push(@expected, [ 4, "begin with no end", 0.05, 1 ]);
+
     $fudge_t[1] = 600000; # end badly nested block time
     $stats->profile(end => "badly nested block 1");
 
@@ -85,6 +89,8 @@ BEGIN { use_ok("Catalyst::Stats") };
     my @report = $stats->report;
     is_deeply(\@report, \@expected, "report");
 
+    # print scalar($stats->report);
+
     is ($stats->elapsed, 14, "elapsed");
 }