AnyEvent-RTPG

 view release on metacpan or  search on metacpan

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

package AnyEvent::RTPG;
our $VERSION = "0.01";

use 5.008;

use common::sense 2.02;
use parent        0.223 "Object::Event";
use AnyEvent      5.202;
use RTPG          0.3;

sub new {
   my $this  = shift;
   my $class = ref($this) || $this;
   my $self  = $class->SUPER::new(@_);
   $self->{_rtpg} = RTPG->new(url=>$self->{url});
   return $self
}

sub _tick {
    my $self = shift;
    my $list=$self->{_rtpg}->torrents_list;
    $self->event("refresh_status"=>\@$list);
}

sub start {
    my $self = shift;
    $self->{_tick_timer} = AE::timer(0, 10, sub { $self->_tick });
}

sub rpc_command {
    my $self = shift;
    my ($result, $error)=$self->{_rtpg}->rpc_command(@_);
    my $cmd=shift;
    if ($cmd =~ /^d.erase$/) {
        my $hash=shift;
        print $cmd,$hash;
        $self->event("rtorrent_remove_torrent"=>$hash);
    }else{
        $self->_tick;
    }
}

1;

=head1 NAME

AnyEvent::RTPG - A RTPG interface for AE

=head1 SYNOPSIS

    # Add "scgi_port = localhost:5000" to your ~/.rtorrent.rc first

    my $rtorrent = AnyEvent::RTPG->new(url => "localhost:5000");

    $rtorrent->reg_cb(
        refresh_status => sub {
            my ($rtorrent, $lists) = @_;
            ...
        },
        rtorrent_remove_torrent => sub {
            my ($rtorrent, $torrent_hash) = @_;
            ...
        }
    );

    $rtorrent->start;

=head1 METHODS

=over 4

=item new(url => "localhost:5000")

=item reg_cb(event_name => $cb, ...)

=item start

=back

=head1 EVENTS

=over 4

=item refresh_status

=item rtorrent_remove_torrent



( run in 1.116 second using v1.01-cache-2.11-cpan-39bf76dae61 )