Skip to content

Instantly share code, notes, and snippets.

@kazeburo
Created October 22, 2010 06:37
Show Gist options
  • Save kazeburo/640062 to your computer and use it in GitHub Desktop.
Save kazeburo/640062 to your computer and use it in GitHub Desktop.
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