DB-Evented

 view release on metacpan or  search on metacpan

lib/DB/Evented.pm  view on Meta::CPAN

    $self->{cv}->recv;
    delete $self->{cv};
    $self->clear_queue;
  }
  return;
}

sub _add_to_queue {
  my ( $self, $sql, $attr, $key_field, @args) = @_;

  my $cb = delete $attr->{response};
  my $item = [$sql, $attr, $key_field, @args, __PACKAGE__ . '::_req_dispatch', $cb]; 

  push @{$self->{_queue}}, $item;
}

sub _req_dispatch {
  my (undef, $st, $attr, $key_field, @args) = @{+shift};
  my $method_name = pop @args;
  my $result = $AnyEvent::DBI::DBH->$method_name($key_field ? ($st, $key_field, $attr, @args) : ($st, $attr, @args) );
  [1, $result ? $result : undef];
}

=head2 selectall_arrayref ($sql, \%attr, @binds )

This method functions in the same way as DBI::selectall_arrayref. The key difference
being it delays the execution until execute_in_parallel has been called. The results
can be accessed in the response attribute call back 

=cut

=head2 selectall_hashref ($sql, $key_field, \%attr, @binds )

This method functions in the same way as DBI::selectall_hashref. The key difference
being it delays the execution until execute_in_parallel has been called. The results
can be accessed in the response attribute call back 

=cut

=head2 selectrow_arrayref ($sql, \%attr, @binds )

This method functions in the same way as DBI::selectrow_arrayref. The key difference
being it delays the execution until execute_in_parallel has been called. The results
can be accessed in the response attribute call back 

=cut

=head2 selectrow_hashref ($sql, \%attr, @binds )

This method functions in the same way as DBI::selectrow_hashref. The key difference
being it delays the execution until execute_in_parallel has been called. The results
can be accessed in the response attribute call back 

=cut

for my $method_name ( qw(selectrow_hashref selectcol_arrayref selectall_hashref selectall_arrayref) ) {
  no strict 'refs';
  *{$method_name} = sub {
    my $self = shift;
    my ($sql, $key_field, $attr, @args) = (shift, ($method_name eq 'selectall_hashref' ? (shift) : (undef)), shift, @_);
    $self->_add_to_queue($sql, $attr, $key_field, @args, $method_name, (caller)[1,2]);
  };
}

# TODO: Investigate if this is the bet way to handle this.
# The child processes are technically held by AnyEvent::DBI
# by clearing the known handlers these children *should* be reaped
sub DESTROY {
  my $error = do {
    local $@;
    eval {
      DB::Evented->clear_handlers;
    };
    $@;
  };
  $? = 0 unless $error;
}

=head1 AUTHOR

Logan Bell, C<< <logie at cpan.org> >>

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc DB::Evented

You can also look for information at:

=head1 ACKNOWLEDGEMENTS

Aaron Cohen and Belden Lyman.

=head1 LICENSE

Copyright (c) 2013 Logan Bell and Shutterstock Inc (http://shutterstock.com).  All rights reserved.  This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

=cut

1; # End of DB::Evented



( run in 0.549 second using v1.01-cache-2.11-cpan-63c85eba8c4 )