Created
October 22, 2010 06:37
-
-
Save kazeburo/640062 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Scope::Container; | |
use strict; | |
use warnings; | |
use Guard; | |
use Log::Minimal; | |
use base qw/Exporter/; | |
our @EXPORT = /start_scope_container scope_container/; | |
our $CONTEXT; | |
sub start_scope_container { | |
$CONTEXT = {}; | |
return guard { | |
undef $CONTEXT; | |
}; | |
} | |
sub scope_container { | |
my $key = shift; | |
die "undefined key" if ! defined $key; | |
debugf("scope_container is not initilized") if ! defined $CONTEXT; | |
if ( @_ ) { | |
return $CONTEXT->{$key} = shift; | |
} | |
return if ! exitst $CONTEXT->{$key}; | |
$CONTEXT->{$key}; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment