Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Scope-Guard CPAN distribution.

Report information
The Basics
Id: 56543
Status: resolved
Priority: 0/
Queue: Scope-Guard

People
Owner: CHOCOLATE [...] cpan.org
Requestors: haarg [...] haarg.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.10
Fixed in: (no value)



Subject: Documentation incorrect for guard/scope_guard in void context
The documentation says that calling guard or scope_guard in void context creates a guard for the current scope. What actually happens is that the guard sub is called immediately.
Unless a) I'm misunderstanding you and b) my tests (scope.t and scope_guard.t) are wrong (quite possible), it's the same thing. The guard is installed as a transient variable in the scope's pad. It gets garbage-collected at the end of the scope (and not before) whether it's bound to a variable or not. I do need to tweak the documentation to emphasize the fact that the guard is anonymous in both cases, but not quite in the way you suggest. I'm more than happy to be wrong, though :-) chocolateboy
s/transient variable/transient value/
From: haaarg [...] gmail.com
Attached is a failing test to demonstrate the problem. The return value of guard doesn't get stored anywhere in void context, so it gets garbage collected immediately.
Subject: guard-void.t
use strict; use warnings; use Test::More tests => 2; use Scope::Guard qw(guard); { my $last_line_has_run; my $g = guard { ok $last_line_has_run, 'Last line of scope run before guard sub with guard variable' }; $last_line_has_run = 1; } { my $last_line_has_run; guard { ok $last_line_has_run, 'Last line of scope run before guard sub in void context' }; $last_line_has_run = 1; }
Many thanks. This should be fixed in 0.20. chocolateboy