| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ex:ts=4:sw=4:sts=4:et |
|
2
|
|
|
|
|
|
|
package Transmission::Stats; |
|
3
|
|
|
|
|
|
|
# See Transmission::Client for copyright statement. |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Transmission::Stats - Transmission session statistics |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
See "4.2 Sesion statistics" from |
|
12
|
|
|
|
|
|
|
L<https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt> |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
|
105385
|
use Moose; |
|
|
5
|
|
|
|
|
501393
|
|
|
|
5
|
|
|
|
|
32
|
|
|
17
|
5
|
|
|
5
|
|
34110
|
use Transmission::Types ':all'; |
|
|
5
|
|
|
|
|
19
|
|
|
|
5
|
|
|
|
|
35
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
with 'Transmission::AttributeRole'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 active_torrent_count |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$num = $self->active_torrent_count; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 download_speed |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$num = $self->download_speed; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 paused_torrent_count |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$num = $self->paused_torrent_count; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 torrent_count |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$num = $self->torrent_count; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 upload_speed |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$num = $self->upload_speed; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 read_all |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Initialize/update stats attributes using Transmission RPC (C<session-stats>). |
|
48
|
|
|
|
|
|
|
Also returns all attributes as a hash reference (named as per the attributes of |
|
49
|
|
|
|
|
|
|
the class). |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my %both = ( |
|
54
|
|
|
|
|
|
|
activeTorrentCount => number, |
|
55
|
|
|
|
|
|
|
downloadSpeed => number, |
|
56
|
|
|
|
|
|
|
pausedTorrentCount => number, |
|
57
|
|
|
|
|
|
|
torrentCount => number, |
|
58
|
|
|
|
|
|
|
uploadSpeed => number, |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
for my $camel (keys %both) { |
|
62
|
|
|
|
|
|
|
(my $name = $camel) =~ s/([A-Z]+)/{ "_" .lc($1) }/ge; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has $name => ( |
|
65
|
|
|
|
|
|
|
is => 'ro', |
|
66
|
|
|
|
|
|
|
isa => $both{$camel}, |
|
67
|
|
|
|
|
|
|
coerce => 1, |
|
68
|
|
|
|
|
|
|
writer => "_set_$name", |
|
69
|
|
|
|
|
|
|
clearer => "clear_$name", |
|
70
|
|
|
|
|
|
|
lazy => 1, |
|
71
|
|
|
|
|
|
|
default => sub { |
|
72
|
|
|
|
|
|
|
my $self = shift; |
|
73
|
|
|
|
|
|
|
my $val = delete $self->_tmp_store->{$name}; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return $val if defined $val; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$self->_clear_tmp_store; |
|
78
|
|
|
|
|
|
|
return delete $self->_tmp_store->{$name}; |
|
79
|
|
|
|
|
|
|
}, |
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
has _tmp_store => ( |
|
84
|
|
|
|
|
|
|
is => 'ro', |
|
85
|
|
|
|
|
|
|
isa => 'HashRef', |
|
86
|
|
|
|
|
|
|
lazy => 1, |
|
87
|
|
|
|
|
|
|
builder => 'read_all', |
|
88
|
|
|
|
|
|
|
clearer => '_clear_tmp_store', |
|
89
|
|
|
|
|
|
|
); |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub read_all { |
|
92
|
3
|
|
|
3
|
1
|
12323
|
my $self = shift; |
|
93
|
3
|
|
|
|
|
82
|
my $lazy = $self->lazy_write; |
|
94
|
3
|
|
|
|
|
7
|
my(%res, $rpc); |
|
95
|
|
|
|
|
|
|
|
|
96
|
3
|
50
|
|
|
|
79
|
$rpc = $self->client->rpc('session-stats') or return; |
|
97
|
|
|
|
|
|
|
|
|
98
|
3
|
|
|
|
|
88
|
$self->lazy_write(1); |
|
99
|
|
|
|
|
|
|
|
|
100
|
3
|
|
|
|
|
13
|
for my $camel (keys %both) { |
|
101
|
15
|
|
|
|
|
49
|
my $name = __PACKAGE__->_camel2Normal($camel); |
|
102
|
15
|
|
|
|
|
56
|
my $writer = "_set_$name"; |
|
103
|
15
|
|
|
|
|
35
|
$res{$name} = $rpc->{$camel}; |
|
104
|
15
|
|
|
|
|
526
|
$self->$writer($rpc->{$camel}); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
3
|
|
|
|
|
84
|
$self->lazy_write($lazy); |
|
108
|
|
|
|
|
|
|
|
|
109
|
3
|
|
|
|
|
12
|
return \%res; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 LICENSE |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
See L<Transmission::Client> |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |