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.250 by root, Mon Jul 20 07:12:38 2009 UTC vs.
Revision 1.253 by root, Tue Jul 21 06:00:47 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
1067 1084
1068BEGIN { AnyEvent::common_sense } 1085BEGIN { AnyEvent::common_sense }
1069 1086
1070use Carp (); 1087use Carp ();
1071 1088
1072our $VERSION = 4.85; 1089our $VERSION = 4.86;
1073our $MODEL; 1090our $MODEL;
1074 1091
1075our $AUTOLOAD; 1092our $AUTOLOAD;
1076our @ISA; 1093our @ISA;
1077 1094
1135 my ($cb) = @_; 1152 my ($cb) = @_;
1136 1153
1137 if ($MODEL) { 1154 if ($MODEL) {
1138 $cb->(); 1155 $cb->();
1139 1156
1140 1 1157 undef
1141 } else { 1158 } else {
1142 push @post_detect, $cb; 1159 push @post_detect, $cb;
1143 1160
1144 defined wantarray 1161 defined wantarray
1145 ? bless \$cb, "AnyEvent::Util::postdetect" 1162 ? bless \$cb, "AnyEvent::Util::postdetect"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines