ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Specific.pm
Revision: 1.1
Committed: Sat Jul 14 22:14:21 2001 UTC (22 years, 11 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     Coro::Specific - manage coroutone-specific variables.
4    
5     =head1 SYNOPSIS
6    
7     use Coro::Specific;
8    
9     my $ref = new Coro::Specific;
10    
11     $$ref = 5;
12     print $$ref;
13    
14     =head1 DESCRIPTION
15    
16     This module can be used to create variables (or better: references to
17     them) that are specific to the currently executing coroutine. This module
18     does not automatically load the Coro module (so the overhead will be small
19     when no coroutines are used).
20    
21     =over 4
22    
23     =cut
24    
25     package Coro::Specific;
26    
27     no warnings;
28    
29     $VERSION = 0.01;
30    
31     =item new
32    
33     Create a new coroutine-specific scalar and return a reference to it.
34    
35     =cut
36    
37     my $idx;
38     my @idx;
39    
40     sub new {
41     my $var;
42     tie $var, Coro::Specific::;
43     \$var;
44     }
45    
46     sub TIESCALAR {
47     my $idx = @idx ? pop @idx : $idx++;
48     bless \$idx, $_[0];
49     }
50    
51     sub FETCH {
52     $Coro::current->{specific}[$$_[0]];
53     }
54    
55     sub STORE {
56     $Coro::current->{specific}[$$_[0]] = $_[1];
57     }
58    
59     sub DESTROY {
60     push @idx, $$_[0];
61     }
62    
63     1;
64    
65     =back
66    
67     =head1 BUGS
68    
69     The actual coroutine specific values do not automatically get destroyed
70     when the Coro::Specific object gets destroyed.
71    
72     =head1 AUTHOR
73    
74     Marc Lehmann <pcg@goof.com>
75     http://www.goof.com/pcg/marc/
76    
77     =cut
78