.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "AnyEvent::ForkObject 3pm" .TH AnyEvent::ForkObject 3pm "2021-01-08" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" AnyEvent::ForkObject \- Async access on objects. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use AnyEvent::ForkObject; \& use DBI; \& \& my $fo = new AnyEvent::ForkObject; \& \& $fo\->do( \& module => \*(AqDBI\*(Aq, \& method => \*(Aqconnect\*(Aq, \& args => [ \*(Aqdbi:mysql...\*(Aq ], \& cb => sub { \& my ($status, $dbh) = @_; \& \& \& $dbh\->selectrow_array(\*(AqSELECT ?\*(Aq, undef, 1 + 1, sub { \& my ($status, $result) = @_; \& print "$result\en"; # prints 2 \& }); \& } \& ); \& \& \& use AnyEvent::Tools qw(async_repeat); \& \& $dbh\->prepare(\*(AqSELECT * FROM tbl\*(Aq, sub { \& my ($status, $sth) = @_; \& $sth\->execute(sub { \& my ($status, $rv) = @_; \& \& # fetch 30 rows \& async_repeat 30 => sub { \& my ($guard) = @_; \& \& $sth\->fetchrow_hashref(sub { \& my ($status, $row) = @_; \& undef $guard; \& \& # do something with $row \& }); \& }; \& \& }); \& }); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" There are a lot of modules that provide object interface. Using the module You can use them in async mode. .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" Constructor. Creates an instance that contains fork jail. .SS "do" .IX Subsection "do" Creates an object inside jail. It receives the following named arguments: .IP "\fBrequire\fR" 4 .IX Item "require" Do \fBrequire\fR inside jail. If the argument is exists, \fBmodule\fR, \fBmethod\fR and \fBwantarray\fR arguments will be ignored. .IP "\fBmodule\fR" 4 .IX Item "module" Module name. For example '\fB\s-1DBI\s0\fR'. .IP "\fBmethod\fR" 4 .IX Item "method" Constructor name. Default value is '\fBnew\fR'. .IP "\fBwantarray\fR" 4 .IX Item "wantarray" Context for method. Default is \fB0\fR (\s-1SCALAR\s0). .IP "\fBcb\fR" 4 .IX Item "cb" Done callback. The first argument is a status: .RS 4 .IP "\fBdie\fR" 4 .IX Item "die" The method has thrown exception. The next argument contains \fB$@\fR. .IP "\fBfatal\fR" 4 .IX Item "fatal" A fatal error was occured (for example fork jail was killed). .IP "\fBok\fR" 4 .IX Item "ok" Method has done. The following arguments contain all data that were returned by the method. .RE .RS 4 .RE .PP If \*(L"method\*(R" returns blessed object, it will provide all its methods in modified form. Each method will receive one or two additional arguments: .IP "\fBresult callback\fR" 4 .IX Item "result callback" A callback that will be called after method has done. .IP "\fBwantarray\fR" 4 .IX Item "wantarray" Context flag for method. Default value is \fB0\fR (\s-1SCALAR\s0). .PP All objects provide additional method \fBfo_attr\fR to access their field. Example: .PP .Vb 2 \& # set attribute \& $dbh\->fo_attr(RaiseError => 1, sub { my ($status, $attr) = @_; ... }); \& \& # get attribute \& $dbh\->fo_attr(\*(AqRaiseError\*(Aq, sub { my ($status, $attr) = @_; ... }); .Ve .SH "AUTHOR" .IX Header "AUTHOR" Dmitry E. Oboukhov, .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2011 by Dmitry E. Oboukhov .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. .SH "VCS" .IX Header "VCS" The project is placed in my git repo: