AnyEve...Object(3pm)
π AnyEvent::ForkObject π
okay so real talk bestie β this page lives in the User Contributed Perl Documentation section of your man setup, and the whole vibe is: you've got a module that hands you an object interface, and you want it to do its thing asynchronously. That's the tea. Let's go π«Ά
β¨ NAME β¨
AnyEvent::ForkObject β async access on objects. yep that's it, that's the whole name, slay π
π SYNOPSIS π
use AnyEvent::ForkObject;
use DBI;
my $fo = new AnyEvent::ForkObject;
$fo->do(
module => 'DBI',
method => 'connect',
args => [ 'dbi:mysql...' ],
cb => sub {
my ($status, $dbh) = @_;
$dbh->selectrow_array('SELECT ?', undef, 1 + 1, sub {
my ($status, $result) = @_;
print "$result\n"; # prints 2
});
}
);
use AnyEvent::Tools qw(async_repeat);
$dbh->prepare('SELECT * FROM tbl', 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
});
};
});
});
like, look at that. a whole DBI session, but make it async. no cap, it's giving main character energy πΈ
π¦ DESCRIPTION π¦
so there are soooo many modules out there that give you an object interface β the whole blessed-reference, method-calling lifestyle. and what this module does is let you use them in async mode. that's the entire plot. periodt β¨
π METHODS π
π new
Constructor, bestie. It creates an instance that contains a fork jail. That's where your object is gonna live. π°
π do
Creates an object inside the jail. It takes these named arguments:
requireβ dorequireinside the jail. And heads up: if this argument exists, themodule,methodandwantarrayarguments will be ignored. it said what it said πmoduleβ the module name. for example'DBI'.methodβ the constructor name. the default value is'new'.wantarrayβ the context for the method. default is0(SCALAR).cbβ the done callback. the first argument it gets is a status:dieβ the method threw an exception. the next argument contains$@. πfatalβ a fatal error occurred (for example, the fork jail was killed). πokβ the method finished successfully. the following arguments contain all the data that were returned by the method. π
If method returns a blessed object, it will provide all its methods in modified form. Each of those methods receives one or two additional arguments:
- result callback β a callback that gets called after the method is done.
- wantarray β the context flag for the method. default is
0(SCALAR).
And every single one of these objects also gets an extra method called fo_attr so you can reach in and touch their fields. iconic, honestly. example:
# set attribute
$dbh->fo_attr(RaiseError => 1, sub { my ($status, $attr) = @_; ... });
# get attribute
$dbh->fo_attr('RaiseError', sub { my ($status, $attr) = @_; ... });
π§ AUTHOR π§
Dmitry E. Oboukhov, <unera@debian.org> β thank you for your service, king π«Ά
π COPYRIGHT AND LICENSE π
Copyright (C) 2011 by Dmitry E. Oboukhov
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.
(so basically: same terms as Perl, version 5.10.1 or anything newer you've got lying around. free software stays free software π)
β VCS β
The project is placed in my git repo: <http://git.uvw.ru/?p=anyevent-forkobject;a=summary>
go peek if you wanna π
and that's the whole page, bestie!! this was perl v5.32.0 and the page itself is dated 2021-01-08, so if you're reading this way later β hi from the past, hope your fork jail is thriving ππ bye pookie, go write some async code β¨
π¦ where this page comes from
- debian bookworm: libanyevent-forkobject-perl 0.09-1.1
- debian trixie: libanyevent-forkobject-perl 0.09-1.1
- ubuntu jammy: libanyevent-forkobject-perl 0.09-1.1
- ubuntu noble: libanyevent-forkobject-perl 0.09-1.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms