Skip to content

Commit

Permalink
allow unimporting of a certain hook, and in general try to be cleaner…
Browse files Browse the repository at this point in the history
… about how leavescope is called, esp. on multiple use B::OPCheck imports per scope
  • Loading branch information
nothingmuch committed Aug 4, 2008
1 parent b2c208d commit 7670557
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/B/OPCheck.pm
Expand Up @@ -19,18 +19,25 @@ sub import {

$^H |= 0x120000; # set HINT_LOCALIZE_HH + an unused bit to work around a %^H bug

my $leave_scope = sub {
leavescope();
};

my $sg = Scope::Guard->new($leave_scope);
$^H{OPCHECK_leavescope} = $sg;
my $by_opname = $^H{OPCHECK_leavescope} ||= {};
my $guards = $by_opname->{$opname} ||= [];
push @$guards, Scope::Guard->new(sub {
leavescope($opname, $sub);
});

enterscope($opname, $sub );
}

sub unimport {
my ($class) = @_;
my ($class, $opname) = @_;

if ( defined $opname ) {
my $by_opname = $^H{OPCHECK_leavescope};
delete $by_opname->{$opname};
return if scalar keys %$by_opname; # don't delete other things
}

delete $^H{OPCHECK_leavescope};
$^H &= ~0x120000;
}

Expand Down

0 comments on commit 7670557

Please sign in to comment.