… | |
… | |
36 | |
36 | |
37 | use Coro::State; |
37 | use Coro::State; |
38 | |
38 | |
39 | use base Exporter; |
39 | use base Exporter; |
40 | |
40 | |
41 | $VERSION = 0.12; |
41 | $VERSION = 0.13; |
42 | |
42 | |
43 | @EXPORT = qw(async cede schedule terminate current); |
43 | @EXPORT = qw(async cede schedule terminate current); |
44 | @EXPORT_OK = qw($current); |
44 | @EXPORT_OK = qw($current); |
45 | |
45 | |
46 | { |
46 | { |
47 | my @async; |
47 | my @async; |
|
|
48 | my $init; |
48 | |
49 | |
49 | # this way of handling attributes simply is NOT scalable ;() |
50 | # this way of handling attributes simply is NOT scalable ;() |
50 | sub import { |
51 | sub import { |
51 | Coro->export_to_level(1, @_); |
52 | Coro->export_to_level(1, @_); |
52 | my $old = *{(caller)[0]."::MODIFY_CODE_ATTRIBUTES"}{CODE}; |
53 | my $old = *{(caller)[0]."::MODIFY_CODE_ATTRIBUTES"}{CODE}; |
… | |
… | |
54 | my ($package, $ref) = (shift, shift); |
55 | my ($package, $ref) = (shift, shift); |
55 | my @attrs; |
56 | my @attrs; |
56 | for (@_) { |
57 | for (@_) { |
57 | if ($_ eq "Coro") { |
58 | if ($_ eq "Coro") { |
58 | push @async, $ref; |
59 | push @async, $ref; |
|
|
60 | unless ($init++) { |
|
|
61 | eval q{ |
|
|
62 | sub INIT { |
|
|
63 | &async(pop @async) while @async; |
|
|
64 | } |
|
|
65 | }; |
|
|
66 | } |
59 | } else { |
67 | } else { |
60 | push @attrs, $_; |
68 | push @attrs, $_; |
61 | } |
69 | } |
62 | } |
70 | } |
63 | return $old ? $old->($package, $ref, @attrs) : @attrs; |
71 | return $old ? $old->($package, $ref, @attrs) : @attrs; |
64 | }; |
72 | }; |
65 | } |
73 | } |
66 | |
74 | |
67 | sub INIT { |
|
|
68 | &async(pop @async) while @async; |
|
|
69 | } |
|
|
70 | } |
75 | } |
71 | |
76 | |
72 | =item $main |
77 | =item $main |
73 | |
78 | |
74 | This coroutine represents the main program. |
79 | This coroutine represents the main program. |
… | |
… | |
257 | |
262 | |
258 | =head1 SEE ALSO |
263 | =head1 SEE ALSO |
259 | |
264 | |
260 | L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>, |
265 | L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>, |
261 | L<Coro::Signal>, L<Coro::State>, L<Coro::Event>, L<Coro::RWLock>, |
266 | L<Coro::Signal>, L<Coro::State>, L<Coro::Event>, L<Coro::RWLock>, |
262 | L<Coro::L<Coro::Handle>, L<Coro::Socket>. |
267 | L<Coro::Handle>, L<Coro::Socket>. |
263 | |
268 | |
264 | =head1 AUTHOR |
269 | =head1 AUTHOR |
265 | |
270 | |
266 | Marc Lehmann <pcg@goof.com> |
271 | Marc Lehmann <pcg@goof.com> |
267 | http://www.goof.com/pcg/marc/ |
272 | http://www.goof.com/pcg/marc/ |