ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Util.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Util.pm (file contents):
Revision 1.24 by root, Fri May 23 22:52:31 2008 UTC vs.
Revision 1.27 by root, Sun May 25 01:10:54 2008 UTC

33 33
34BEGIN { 34BEGIN {
35 *socket_inet_aton = \&Socket::inet_aton; # take a copy, in case Coro::LWP overrides it 35 *socket_inet_aton = \&Socket::inet_aton; # take a copy, in case Coro::LWP overrides it
36} 36}
37 37
38BEGIN {
39 my $af_inet6 = eval { &Socket::AF_INET6 };
40 eval "sub AF_INET6() { $af_inet6 }"; die if $@;
41
42 delete $AnyEvent::PROTOCOL{ipv6} unless $af_inet6;
43}
44
45BEGIN {
46 # broken windows perls use undocumented error codes...
47 if ($^O =~ /mswin32/i) {
48 eval "sub WSAEAGAIN() { 10035 }";
49 } else {
50 eval "sub WSAEAGAIN() { -1e99 }"; # should never match any errno value
51 }
52}
53
38our @EXPORT = qw(fh_nonblocking guard); 54our @EXPORT = qw(fh_nonblocking guard);
55our @EXPORT_OK = qw(AF_INET6 WSAEAGAIN);
39 56
40our $VERSION = '1.0'; 57our $VERSION = '1.0';
41 58
42our $MAXPARALLEL = 16; # max. number of parallel jobs 59our $MAXPARALLEL = 16; # max. number of parallel jobs
43 60
123code block. 140code block.
124 141
125This is often handy in continuation-passing style code to clean up some 142This is often handy in continuation-passing style code to clean up some
126resource regardless of where you break out of a process. 143resource regardless of where you break out of a process.
127 144
145You can call one method on the returned object:
146
147=item $guard->cancel
148
149This simply causes the code block not to be invoked: it "cancels" the
150guard.
151
128=cut 152=cut
129 153
130sub AnyEvent::Util::Guard::DESTROY { 154sub AnyEvent::Util::Guard::DESTROY {
131 ${$_[0]}->(); 155 ${$_[0]}->();
156}
157
158sub AnyEvent::Util::Guard::cancel($) {
159 ${$_[0]} = sub { };
132} 160}
133 161
134sub guard(&) { 162sub guard(&) {
135 bless \(my $cb = shift), AnyEvent::Util::Guard:: 163 bless \(my $cb = shift), AnyEvent::Util::Guard::
136} 164}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines