AnyEvent-ForkObject

 view release on metacpan or  search on metacpan

lib/AnyEvent/ForkObject.pm  view on Meta::CPAN

            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
                });
            };

        });
    });

=head1 DESCRIPTION

There are a lot of modules that provide object interface. Using the module
You can use them in async mode.

=head1 METHODS

=head2 new

Constructor. Creates an instance that contains fork jail.

=head2 do

Creates an object inside jail. It receives the following named arguments:

=over


=item B<require>

Do B<require> inside jail. If the argument is exists, B<module>, B<method>
and B<wantarray> arguments will be ignored.

=item B<module>

Module name. For example 'B<DBI>'.

=item B<method>

Constructor name. Default value is 'B<new>'.

=item B<wantarray>

Context for method. Default is B<0> (SCALAR).

=item B<cb>

Done callback. The first argument is a status:

=over

=item B<die>

The method has thrown exception. The next argument contains B<$@>.

=item B<fatal>

A fatal error was occured (for example fork jail was killed).

=item B<ok>

Method has done. The following arguments contain all data that were returned
by the method.

=back

=back

If L</method> returns blessed object, it will provide all its methods in
modified form. Each method will receive one or two additional arguments:

=over

=item B<result callback>

A callback that will be called after method has done.

=item B<wantarray>

Context flag for method. Default value is B<0> (SCALAR).

=back

All objects provide additional method B<fo_attr> to access their field.
Example:

    # set attribute
    $dbh->fo_attr(RaiseError => 1, sub { my ($status, $attr) = @_; ... });

    # get attribute
    $dbh->fo_attr('RaiseError', sub { my ($status, $attr) = @_; ... });

=head1 AUTHOR

Dmitry E. Oboukhov, E<lt>unera@debian.orgE<gt>

=head1 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.

=head1 VCS

The project is placed in my git repo:
L<http://git.uvw.ru/?p=anyevent-forkobject;a=summary>

=cut



( run in 0.312 second using v1.01-cache-2.11-cpan-5511b514fd6 )