Skip to content

Instantly share code, notes, and snippets.

@mix3
Created December 28, 2012 15:09
Show Gist options
  • Save mix3/4398698 to your computer and use it in GitHub Desktop.
Save mix3/4398698 to your computer and use it in GitHub Desktop.
package Scope;
sub new {
my $class = shift;
my $hash = { v => 0 };
$hash->{r} = "$hash";
return bless $hash, $class;
}
sub txn {
my $self = shift;
my $sub = shift;
eval {
print "start\n" unless ($self->{v});
print "[", $self->{r}, "] ", $self->{v}, " => ";
$self->{v}++;
print $self->{v}, "\n";
$sub->(@_);
print "[", $self->{r}, "] ", $self->{v}, " => ";
$self->{v}--;
print $self->{v}, "\n";
print "end\n" unless ($self->{v});
};
if ($@) {
print "[", $self->{r}, "] ", $self->{v}, " => ";
$self->{v}--;
print $self->{v}, "\n";
print "end\n" unless ($self->{v});
}
}
package main;
my $scope = Scope->new();
$scope->txn(sub{
# die "die";
$scope->txn(sub{
# die "die";
});
# die "die";
});
#my $scope1 = Scope->new();
#my $scope2 = Scope->new();
#
#$scope1->txn(sub{
# $scope2->txn(sub{
# die "die"
# });
#});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment