Revision: | 1.43 |
Committed: | Tue Oct 2 23:16:24 2007 UTC (16 years, 8 months ago) by root |
Branch: | MAIN |
CVS Tags: | rel-4_22, rel-4_21, rel-4_0, rel-4_3, rel-4_13, rel-4_11, rel-4_01, rel-4_03, rel-4_02, rel-4_50, rel-4_51, rel-4_4, rel-4_45, rel-4_49, rel-4_48, rel-4_1, rel-4_2, rel-4_47, rel-4_46, rel-4_31, rel-4_32, rel-4_33, rel-4_34, rel-4_35, rel-4_36, rel-4_37 |
Changes since 1.42: | +2 -2 lines |
Log Message: | *** empty log message *** |
# | 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.42 | $VERSION = 1.9; |
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 |