ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Specific.pm
Revision: 1.38
Committed: Mon Dec 12 17:49:07 2005 UTC (18 years, 5 months ago) by root
Branch: MAIN
Changes since 1.37: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 Coro::Specific - manage coroutine-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 BEGIN { eval { require warnings } && warnings->unimport ("uninitialized") }
28
29 $VERSION = 1.51;
30
31 =item new
32
33 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
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 my $idx = $idx++;
49 bless \$idx, $_[0];
50 }
51
52 sub FETCH {
53 $Coro::current->{specific}[${$_[0]}];
54 }
55
56 sub STORE {
57 $Coro::current->{specific}[${$_[0]}] = $_[1];
58 }
59
60 #sub DESTROY {
61 # push @idx, $$_[0];
62 #}
63
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 Marc Lehmann <schmorp@schmorp.de>
76 http://home.schmorp.de/
77
78 =cut
79