ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Specific.pm
Revision: 1.61
Committed: Mon Nov 10 04:37:23 2008 UTC (15 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-4_91, rel-4_901, rel-4_911
Changes since 1.60: +1 -1 lines
Log Message:
4.91

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3 root 1.34 Coro::Specific - manage coroutine-specific variables.
4 root 1.1
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 pcg 1.25 BEGIN { eval { require warnings } && warnings->unimport ("uninitialized") }
28 root 1.1
29 root 1.61 $VERSION = 4.91;
30 root 1.1
31     =item new
32    
33 root 1.8 Create a new coroutine-specific scalar and return a reference to it. The
34     scalar is guarenteed to be "undef". Once such a scalar has been allocated
35     you cannot deallocate it (yet), so allocate only when you must.
36 root 1.1
37     =cut
38    
39     my $idx;
40    
41     sub new {
42     my $var;
43     tie $var, Coro::Specific::;
44     \$var;
45     }
46    
47     sub TIESCALAR {
48 root 1.8 my $idx = $idx++;
49 root 1.1 bless \$idx, $_[0];
50     }
51    
52     sub FETCH {
53 root 1.43 $Coro::current->{_specific}[${$_[0]}];
54 root 1.1 }
55    
56     sub STORE {
57 root 1.43 $Coro::current->{_specific}[${$_[0]}] = $_[1];
58 root 1.1 }
59    
60 root 1.8 #sub DESTROY {
61     # push @idx, $$_[0];
62     #}
63 root 1.1
64     1;
65    
66     =back
67    
68     =head1 BUGS
69    
70     The actual coroutine specific values do not automatically get destroyed
71     when the Coro::Specific object gets destroyed.
72    
73     =head1 AUTHOR
74    
75 root 1.33 Marc Lehmann <schmorp@schmorp.de>
76 root 1.31 http://home.schmorp.de/
77 root 1.1
78     =cut
79