Fix RT#59738, show_internal_actions produces warnings in debug mode
Tomas Doran [Wed, 25 Aug 2010 22:53:20 +0000 (22:53 +0000)]
Changes
lib/Catalyst.pm
t/lib/TestAppShowInternalActions.pm [new file with mode: 0644]
t/lib/TestAppShowInternalActions/Controller/Root.pm [new file with mode: 0644]
t/live_show_internal_actions_warnings.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 36175c6..7705f00 100644 (file)
--- a/Changes
+++ b/Changes
@@ -6,6 +6,8 @@
     to always be parsed for logging at the end of the request when in
     debug mode. This has been fixed so that if the body has not been parsed
     by the time the request is logged, then the body is omitted.
+  - Fix show_internal_actions config setting producing warnings in debug
+    mode (RT#59738)
 
 5.80025 2010-07-29 01:50:00
 
index e310bd8..56ed57f 100644 (file)
@@ -1701,7 +1701,7 @@ sub _stats_start_execute {
         my $parent = $c->stack->[-1];
 
         # forward, locate the caller
-        if ( exists $c->counter->{"$parent"} ) {
+        if ( defined $parent && exists $c->counter->{"$parent"} ) {
             $c->stats->profile(
                 begin  => $action,
                 parent => "$parent" . $c->counter->{"$parent"},
diff --git a/t/lib/TestAppShowInternalActions.pm b/t/lib/TestAppShowInternalActions.pm
new file mode 100644 (file)
index 0000000..250730f
--- /dev/null
@@ -0,0 +1,20 @@
+package TestAppShowInternalActions;
+use Moose;
+use namespace::autoclean;
+
+use Catalyst::Runtime 5.80;
+
+use Catalyst qw/ -Debug /; # Debug must remain on for
+                           # t/live_show_internal_actions_warnings.t
+
+extends 'Catalyst';
+
+__PACKAGE__->config(
+    name => 'TestAppShowInternalActions',
+    disable_component_resolution_regex_fallback => 1,
+    show_internal_actions => 1,
+);
+
+__PACKAGE__->setup();
+
+1;
diff --git a/t/lib/TestAppShowInternalActions/Controller/Root.pm b/t/lib/TestAppShowInternalActions/Controller/Root.pm
new file mode 100644 (file)
index 0000000..c36df9c
--- /dev/null
@@ -0,0 +1,19 @@
+package TestAppShowInternalActions::Controller::Root;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller' }
+
+__PACKAGE__->config(namespace => '');
+
+sub index :Path :Args(0) {
+    my ( $self, $c ) = @_;
+
+    $c->response->body( 'hello world' );
+}
+
+sub end : Action {}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/t/live_show_internal_actions_warnings.t b/t/live_show_internal_actions_warnings.t
new file mode 100644 (file)
index 0000000..e68edca
--- /dev/null
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+use FindBin '$Bin';
+use lib "$Bin/lib";
+use Test::More;
+use File::Spec;
+BEGIN { # Shut up debug output, app needs debug on for the issue to
+        # appear, but we don't want the spraff to the screen
+
+    my $devnull = File::Spec->devnull;
+    open my $fh, '>', $devnull or die "Cannot write to $devnull: $!";
+
+    *STDERR = $fh;
+}
+
+use Catalyst::Test 'TestAppShowInternalActions';
+
+my $last_warning;
+{
+    local $SIG{__WARN__} = sub { $last_warning = shift };
+    get('/');
+}
+is( $last_warning, undef, 'there should be no warnings about uninitialized value' );
+
+done_testing;