| 1 | #$Id: Downloads.pm 805 2010-07-05 13:20:49Z zag $ | ||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||
| 3 | package Net::RTorrent::Downloads; | ||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 8 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 9 | 2 | ▶ | use Collection; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 10 | 2 | ▶ | use Net::RTorrent::DItem; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 11 | 2 | ▶ | use constant { | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 12 | 2 | D_ATTRIBUTES => [ | |||||||||||||||||||||||
| 13 | 'd.get_hash=' => 'hash', | ||||||||||||||||||||||||
| 14 | 'd.get_base_filename=' => 'base_filename', | ||||||||||||||||||||||||
| 15 | 'd.get_base_path=' => 'base_path', | ||||||||||||||||||||||||
| 16 | 'd.get_bytes_done=' => 'bytes_done', | ||||||||||||||||||||||||
| 17 | 'd.get_chunk_size=' => 'chunk_size', | ||||||||||||||||||||||||
| 18 | 'd.get_chunks_hashed=' => 'chunks_hashed', | ||||||||||||||||||||||||
| 19 | 'd.get_complete=' => 'complete', | ||||||||||||||||||||||||
| 20 | 'd.get_completed_bytes=' => 'completed_bytes', | ||||||||||||||||||||||||
| 21 | 'd.get_completed_chunks=' => 'completed_chunks', | ||||||||||||||||||||||||
| 22 | 'd.get_connection_current=' => 'connection_current', | ||||||||||||||||||||||||
| 23 | 'd.get_connection_leech=' => 'connection_leech', | ||||||||||||||||||||||||
| 24 | 'd.get_connection_seed=' => 'connection_seed', | ||||||||||||||||||||||||
| 25 | 'd.get_creation_date=' => 'creation_date', | ||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||
| 27 | 'd.get_directory=' => 'directory', | ||||||||||||||||||||||||
| 28 | 'd.get_down_rate=' => 'down_rate', | ||||||||||||||||||||||||
| 29 | 'd.get_down_total=' => 'down_total', | ||||||||||||||||||||||||
| 30 | 'd.get_free_diskspace=' => 'free_diskspace', | ||||||||||||||||||||||||
| 31 | 'd.get_hashing=' => 'hashing', | ||||||||||||||||||||||||
| 32 | 'd.get_ignore_commands=' => 'ignore_commands', | ||||||||||||||||||||||||
| 33 | 'd.get_left_bytes=' => 'left_bytes', | ||||||||||||||||||||||||
| 34 | 'd.get_local_id=' => 'local_id', | ||||||||||||||||||||||||
| 35 | 'd.get_local_id_html=' => 'local_id_html', | ||||||||||||||||||||||||
| 36 | 'd.get_max_file_size=' => 'max_file_size', | ||||||||||||||||||||||||
| 37 | # 'd.get_max_peers=' => 'max_peers', | ||||||||||||||||||||||||
| 38 | 'd.get_max_size_pex=' => 'max_size_pex', | ||||||||||||||||||||||||
| 39 | # 'd.get_max_uploads=' => 'max_uploads', | ||||||||||||||||||||||||
| 40 | 'd.get_message=' => 'message', | ||||||||||||||||||||||||
| 41 | # 'd.get_min_peers=' => 'min_peers', | ||||||||||||||||||||||||
| 42 | 'd.get_name=' => 'name', | ||||||||||||||||||||||||
| 43 | 'd.get_peer_exchange=' => 'peer_exchange', | ||||||||||||||||||||||||
| 44 | 'd.get_peers_accounted=' => 'peers_accounted', | ||||||||||||||||||||||||
| 45 | 'd.get_peers_complete=' => 'peers_complete', | ||||||||||||||||||||||||
| 46 | 'd.get_peers_connected=' => 'peers_connected', | ||||||||||||||||||||||||
| 47 | 'd.get_peers_max=' => 'peers_max', | ||||||||||||||||||||||||
| 48 | 'd.get_peers_min=' => 'peers_min', | ||||||||||||||||||||||||
| 49 | 'd.get_peers_not_connected=' => 'peers_not_connected', | ||||||||||||||||||||||||
| 50 | 'd.get_priority=' => 'priority', | ||||||||||||||||||||||||
| 51 | 'd.get_priority_str=' => 'priority_str', | ||||||||||||||||||||||||
| 52 | 'd.get_ratio=' => 'ratio', | ||||||||||||||||||||||||
| 53 | 'd.get_size_bytes=' => 'size_bytes', | ||||||||||||||||||||||||
| 54 | 'd.get_size_chunks=' => 'size_chunks', | ||||||||||||||||||||||||
| 55 | 'd.get_size_files=' => 'size_files', | ||||||||||||||||||||||||
| 56 | 'd.get_size_pex=' => 'size_pex', | ||||||||||||||||||||||||
| 57 | 'd.get_skip_rate=' => 'skip_rate', | ||||||||||||||||||||||||
| 58 | 'd.get_skip_total=' => 'skip_total', | ||||||||||||||||||||||||
| 59 | 'd.get_state=' => 'state', | ||||||||||||||||||||||||
| 60 | 'd.get_state_changed=' => 'state_changed', | ||||||||||||||||||||||||
| 61 | 'd.get_tied_to_file=' => 'tied_to_file', | ||||||||||||||||||||||||
| 62 | 'd.get_tracker_focus=' => 'tracker_focus', | ||||||||||||||||||||||||
| 63 | 'd.get_tracker_numwant=' => 'tracker_numwant', | ||||||||||||||||||||||||
| 64 | 'd.get_tracker_size=' => 'tracker_size', | ||||||||||||||||||||||||
| 65 | 'd.get_up_rate=' => 'up_rate', | ||||||||||||||||||||||||
| 66 | 'd.get_up_total=' => 'up_total', | ||||||||||||||||||||||||
| 67 | 'd.get_uploads_max=' => 'uploads_max', | ||||||||||||||||||||||||
| 68 | 'd.get_custom2=' => 'custom2', | ||||||||||||||||||||||||
| 69 | 'd.is_active=' => 'is_active', | ||||||||||||||||||||||||
| 70 | 'd.is_open=' => 'is_open' | ||||||||||||||||||||||||
| 71 | ] | ||||||||||||||||||||||||
| 72 | 2 | }; | |||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||
| 74 | 2 | ▶ | use 5.005; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 75 | 2 | our @ISA = qw(Collection); | |||||||||||||||||||||||
| 76 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||
| 77 | 2 | my $attrs = { _cli => undef, _view => 'default' }; | |||||||||||||||||||||||
| 78 | ### install get/set accessors for this object. | ||||||||||||||||||||||||
| 79 | 2 | for my $key ( keys %$attrs ) { | |||||||||||||||||||||||
| 80 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 81 | 4 | ▶ | *{ __PACKAGE__ . "::$key" } = sub { | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=14.6
| |||||||||||||||||||||||||
| 82 | 0 | my $self = shift; | |||||||||||||||||||||||
| 83 | 0 | ▶ | $self->{$key} = $_[0] if @_; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 84 | 0 | return $self->{$key}; | |||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||
| 86 | 4 | } | |||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||
| 88 | 0 | ▶ | sub _init { | ||||||||||||||||||||||
|
Subroutine
_init: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||||||||||||||
| 90 | 0 | $self->_cli(shift); | |||||||||||||||||||||||
| 91 | 0 | ▶ | if ( my $view_name = shift ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 92 | 0 | $self->_view($view_name); | |||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||
| 94 | 0 | return $self->SUPER::_init(@_); | |||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||
| 97 | =head2 delete (<info_hash1>[, <info_hash2> ... ]) | ||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||
| 99 | Call d.erase on I<info_hashes>. | ||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||
| 101 | return { <info_hashes> => <xml-rpc response value> } | ||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||
| 105 | 0 | ▶ | sub _delete { | ||||||||||||||||||||||
|
Subroutine
_delete: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||
| 106 | 0 | my $self = shift; | |||||||||||||||||||||||
| 107 | 0 | ▶ | my (@ids) = map { ref($_) ? $_->{id} : $_ } @_; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 108 | 0 | my %res = (); | |||||||||||||||||||||||
| 109 | 0 | for (@ids) { | |||||||||||||||||||||||
| 110 | 0 | my $resp = $self->_cli->send_request( 'd.erase', $_ ); | |||||||||||||||||||||||
| 111 | 0 | ▶ | if ( ref $resp ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 112 | 0 | $res{$_} = $resp->value; | |||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||
| 115 | 0 | return \%res; | |||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||
| 118 | 0 | ▶ | sub _fetch { | ||||||||||||||||||||||
|
Subroutine
_fetch: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||
| 119 | 0 | my $self = shift; | |||||||||||||||||||||||
| 120 | 0 | my @ids = @_; | |||||||||||||||||||||||
| 121 | 0 | my ( @methods, @attr_names ) = (); | |||||||||||||||||||||||
| 122 | 0 | my $r = D_ATTRIBUTES; | |||||||||||||||||||||||
| 123 | 0 | my @meth2attr = @{$r}; | |||||||||||||||||||||||
| 124 | 0 | ▶ | while ( my ( $method, $attr_name ) = splice @meth2attr, 0, 2 ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 125 | 0 | push @methods, $method; | |||||||||||||||||||||||
| 126 | 0 | push @attr_names, $attr_name; | |||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||
| 128 | 0 | my $cli = $self->_cli; | |||||||||||||||||||||||
| 129 | 0 | ▶ | my $resp = | ||||||||||||||||||||||
|
Condition0%0/2
$self->_view || 'default'
MC/DC0%0/1
$self->_view || 'default'
$self->_view
Truth table0%0/2
A
A= $self->_view
| |||||||||||||||||||||||||
| 130 | $cli->send_request( 'd.multicall', $self->_view || "default", @methods ); | ||||||||||||||||||||||||
| 131 | 0 | ▶ | if ( ref $resp ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 132 | 0 | my $res = $resp->value; | |||||||||||||||||||||||
| 133 | 0 | my %result = (); | |||||||||||||||||||||||
| 134 | 0 | foreach my $rec (@$res) { | |||||||||||||||||||||||
| 135 | 0 | my %attr; | |||||||||||||||||||||||
| 136 | 0 | @attr{@attr_names} = @$rec; | |||||||||||||||||||||||
| 137 | 0 | my $id = $attr{hash}; | |||||||||||||||||||||||
| 138 | 0 | $result{$id} = \%attr; | |||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||
| 140 | 0 | return \%result; | |||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||
| 142 | 0 | return {}; | |||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||
| 145 | =head2 fetch_one <info_hash> | ||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||
| 147 | Return L<Net::RTorrent::DItem> object for given I<info_hash>. | ||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||
| 149 | Or undef if I<info_hash> not exists. | ||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||
| 153 | 0 | ▶ | sub fetch_one { | ||||||||||||||||||||||
|
Subroutine
fetch_one: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||
| 154 | 0 | my $self = shift; | |||||||||||||||||||||||
| 155 | 0 | my ($obj) = values %{ $self->fetch(@_) }; | |||||||||||||||||||||||
| 156 | 0 | $obj; | |||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||
| 159 | =head2 fetch <info_hash1>[, <info_hash2> ... ] | ||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||
| 161 | Return info about torrents for given I<info_hashes>. | ||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||
| 163 | Result: ref to hash of L<Net::RTorrent::DItem> objects | ||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||
| 167 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||
|
Subroutine
fetch: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||
| 168 | 0 | my $self = shift; | |||||||||||||||||||||||
| 169 | 0 | my @ids = @_; | |||||||||||||||||||||||
| 170 | 0 | ▶ | unless ( scalar @_ ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 171 | 0 | @ids = @{$self->list_ids} | |||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||
| 173 | 0 | my $res = $self->SUPER::fetch(@ids); | |||||||||||||||||||||||
| 174 | 0 | my %res = (); | |||||||||||||||||||||||
| 175 | 0 | foreach my $key (@ids) { | |||||||||||||||||||||||
| 176 | 0 | ▶ | $res{$key} = $res->{$key} if exists $res->{$key}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||
| 178 | 0 | return \%res; | |||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||
| 182 | 0 | ▶ | sub list_ids { | ||||||||||||||||||||||
|
Subroutine
list_ids: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||
| 183 | 0 | my $self = shift; | |||||||||||||||||||||||
| 184 | 0 | my $cli = $self->_cli; | |||||||||||||||||||||||
| 185 | 0 | ▶ | my $resp = $cli->send_request('download_list',shift || $self->_view || "default"); | ||||||||||||||||||||||
|
Condition0%0/5
shift() || $self->_view || 'default'
shift() or $self->_view
MC/DC0%0/2
shift() || $self->_view || 'default'
shift()
$self->_view
Truth table0%0/3
A or B
A= shift()B= $self->_view
| |||||||||||||||||||||||||
| 186 | 0 | ▶ | return ref($resp) ? $resp->value : []; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||
| 189 | =head2 start <info_hash1>[, <info_hash2> ... ] | ||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||
| 191 | Start torrents | ||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||
| 193 | =cut | ||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||
| 195 | 0 | ▶ | sub start { | ||||||||||||||||||||||
|
Subroutine
start: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||
| 196 | 0 | my $self = shift; | |||||||||||||||||||||||
| 197 | 0 | my $cli = $self->_cli; | |||||||||||||||||||||||
| 198 | 0 | my %res = (); | |||||||||||||||||||||||
| 199 | 0 | for (@_) { | |||||||||||||||||||||||
| 200 | 0 | my $resp = $self->_cli->send_request( 'd.start', $_ ); | |||||||||||||||||||||||
| 201 | 0 | ▶ | if ( ref $resp ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 202 | 0 | $res{$_} = $resp->value; | |||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||
| 205 | 0 | return \%res; | |||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||
| 208 | =head2 stop <info_hash1>[, <info_hash2> ... ] | ||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||
| 210 | Stop torrents | ||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||
| 212 | =cut | ||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||
| 214 | 0 | ▶ | sub stop { | ||||||||||||||||||||||
|
Subroutine
stop: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||
| 215 | 0 | my $self = shift; | |||||||||||||||||||||||
| 216 | 0 | my $cli = $self->_cli; | |||||||||||||||||||||||
| 217 | 0 | my %res = (); | |||||||||||||||||||||||
| 218 | 0 | for (@_) { | |||||||||||||||||||||||
| 219 | 0 | my $resp = $self->_cli->send_request( 'd.stop', $_ ); | |||||||||||||||||||||||
| 220 | 0 | ▶ | if ( ref $resp ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 221 | 0 | $res{$_} = $resp->value; | |||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||
| 224 | 0 | return \%res; | |||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||
| 227 | 0 | ▶ | sub _prepare_record { | ||||||||||||||||||||||
|
Subroutine
_prepare_record: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||
| 228 | 0 | my $self = shift; | |||||||||||||||||||||||
| 229 | 0 | my ( $key, $ref ) = @_; | |||||||||||||||||||||||
| 230 | 0 | return new Net::RTorrent::DItem:: $ref, $self->_cli; | |||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||
| 233 | 2 | 1; | |||||||||||||||||||||||
| 234 | __END__ | ||||||||||||||||||||||||