Permalink
Browse files

Checking in changes prior to tagging of version 0.02.

Changelog diff is:
  • Loading branch information...
1 parent f98ead0 commit 1e7a9df08ba93d107a95695a2a2b22e3165a789c @kazeburo committed Nov 4, 2010
Showing with 33 additions and 6 deletions.
  1. +4 −0 Changes
  2. +20 −6 lib/Scope/Container.pm
  3. +9 −0 t/01_basic.t
View
@@ -1,4 +1,8 @@
Revision history for Perl extension Scope::Container
+0.02 Thu Nov 01 17:24:14 2010
+ - added in_scope_container for check $CONTEXT
+ - clear $CONTEXT if race condition found
+
0.01 Tue Oct 26 00:20:24 2010
- original version
View
@@ -5,8 +5,8 @@ use warnings;
use Carp qw//;
use base qw/Exporter/;
-our $VERSION = '0.01';
-our @EXPORT = qw/start_scope_container scope_container/;
+our $VERSION = '0.02';
+our @EXPORT = qw/start_scope_container scope_container in_scope_container/;
my $CONTEXT;
my $C = 0;
@@ -27,11 +27,20 @@ sub start_scope_container {
sub DESTROY {
my($self) = @_;
- Carp::carp("nested scope_container found") if $self->{c} != --$C;
- $CONTEXT = $self->{old};
+ if ( $self->{c} != --$C ) {
+ Carp::carp("nested scope_container found, remove all data");
+ undef $CONTEXT;
+ }
+ else {
+ $CONTEXT = $self->{old};
+ }
return;
}
+sub in_scope_container {
+ defined $CONTEXT;
+}
+
sub scope_container {
my $key = shift;
die "undefined key" if ! defined $key;
@@ -87,7 +96,7 @@ Scope::Container is scope based container for temporary items and Database Conne
=item my $scope_container = start_scope_container([-clear => 1]);
-initializing container. The default behavior is inherited all the previous container's data.
+Initializing container. The default behavior is inherited all the previous container's data.
If set -clear arguments, save previous container's data and create new data.
return values is Scope::Container object. if this object scope exits, current container will be removed, return to the previous state.
@@ -96,11 +105,16 @@ return values is Scope::Container object. if this object scope exits, current co
getter, setter of container data.
+=item in_scope_container
+
+Check if context is initialized
+
=back
=head1 LIMITATION
-There is a limit to the order in which the Scope::Container object is deleted
+There is a limit to the order in which the Scope::Container object is deleted.
+If race condition found, remove all data.
my $sc = start_scope_container();
scope_container('bar', 'foo');
View
@@ -102,6 +102,15 @@ sub bar {
}
is(scope_container('foo'), 'foo2');
}
+{
+ ok( !in_scope_container() );
+}
+
+{
+ my $sc = start_scope_container();
+ ok( in_scope_container() );
+}
+
done_testing;

0 comments on commit 1e7a9df

Please sign in to comment.