File Coverage

blib/lib/Scope/local_OnExit.pm
Criterion Covered Total %
statement 26 26 100.0
branch 4 4 100.0
condition n/a
subroutine 9 9 100.0
pod n/a
total 39 39 100.0


line stmt bran cond sub pod time code
1             package Scope::local_OnExit;
2              
3 1     1   8154 use 5.006000;
  1         3  
  1         136  
4             $VERSION = 0.01;
5 1     1   7 use strict;
  1         2  
  1         36  
6 1     1   7 use warnings;
  1         7  
  1         346  
7             sub TIESCALAR { bless [
8             sub {
9 1     1   5799 require Carp;
10 1         254 Carp::croak( __PACKAGE__." stack underflow")
11             }
12 2     2   2327 ] }
13             sub DEBUG() { 0 }
14             sub STORE {
15             # my $stack = shift;
16             # my $newval = shift;
17 10     10   404 DEBUG and warn "STORING: @_";
18             # if(ref $newval){
19             # push @$stack, $newval
20             # }else{
21 10 100       26 if(ref $_[1]){
22 3         4 push @{$_[0]}, $_[1]
  3         12  
23             }else{
24             # eval { &{pop @$stack}; 1 }
25             # or warn "running top of stack failed: $@--"
26 7 100       28 $_[1] > 0 and (pop @{$_[0]})->()
  4         12  
27             }
28             }
29             sub FETCH {
30 3     3   738 DEBUG and warn "FETCHING: @_ (@{$_[0]})";
31 3         4 0+@{$_[0]}
  3         22  
32             }
33              
34             sub import{
35 1     1   7 no strict 'refs';
  1         3  
  1         63  
36 1     1   8 tie ${caller().'::OnExit'}, __PACKAGE__;
  1         11  
37             }
38              
39             1;
40             __END__