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

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.251 by root, Mon Jul 20 22:39:57 2009 UTC vs.
Revision 1.252 by root, Tue Jul 21 03:30:02 2009 UTC

879event module detection too early, for example, L<AnyEvent::AIO> creates 879event module detection too early, for example, L<AnyEvent::AIO> creates
880and installs the global L<IO::AIO> watcher in a C<post_detect> block to 880and installs the global L<IO::AIO> watcher in a C<post_detect> block to
881avoid autodetecting the event module at load time. 881avoid autodetecting the event module at load time.
882 882
883If called in scalar or list context, then it creates and returns an object 883If called in scalar or list context, then it creates and returns an object
884that automatically removes the callback again when it is destroyed. See 884that automatically removes the callback again when it is destroyed (or
885C<undef> when the hook was immediately executed). See L<AnyEvent::AIO> for
885L<Coro::BDB> for a case where this is useful. 886a case where this is useful.
887
888Example: Create a watcher for the IO::AIO module and store it in
889C<$WATCHER>. Only do so after the event loop is initialised, though.
890
891 our WATCHER;
892
893 my $guard = AnyEvent::post_detect {
894 $WATCHER = AnyEvent->io (fh => IO::AIO::poll_fileno, poll => 'r', cb => \&IO::AIO::poll_cb);
895 };
896
897 # the ||= is important in case post_detect immediately runs the block,
898 # as to not clobber the newly-created watcher. assigning both watcher and
899 # post_detect guard to the same variable has the advantage of users being
900 # able to just C<undef $WATCHER> if the watcher causes them grief.
901
902 $WATCHER ||= $guard;
886 903
887=item @AnyEvent::post_detect 904=item @AnyEvent::post_detect
888 905
889If there are any code references in this array (you can C<push> to it 906If there are any code references in this array (you can C<push> to it
890before or after loading AnyEvent), then they will called directly after 907before or after loading AnyEvent), then they will called directly after

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines