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
|
1
|
|
|
1
|
|
1497
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Transmission::Types ':all'; |
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
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
BEGIN { |
46
|
|
|
|
|
|
|
my %both = ( |
47
|
|
|
|
|
|
|
activeTorrentCount => number, |
48
|
|
|
|
|
|
|
downloadSpeed => number, |
49
|
|
|
|
|
|
|
pausedTorrentCount => number, |
50
|
|
|
|
|
|
|
torrentCount => number, |
51
|
|
|
|
|
|
|
uploadSpeed => number, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
for my $camel (keys %both) { |
55
|
|
|
|
|
|
|
(my $name = $camel) =~ s/([A-Z]+)/{ "_" .lc($1) }/ge; |
56
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute($name => ( |
57
|
|
|
|
|
|
|
is => 'ro', |
58
|
|
|
|
|
|
|
isa => $both{$camel}, |
59
|
|
|
|
|
|
|
coerce => 1, |
60
|
|
|
|
|
|
|
writer => "_set_$name", |
61
|
|
|
|
|
|
|
clearer => "clear_$name", |
62
|
|
|
|
|
|
|
lazy => 1, |
63
|
|
|
|
|
|
|
default => sub { |
64
|
|
|
|
|
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
my $val = delete $self->_tmp_store->{$name}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
if(defined $val) { |
68
|
|
|
|
|
|
|
return $val; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
|
|
|
|
|
|
$self->_clear_tmp_store; |
72
|
|
|
|
|
|
|
return delete $self->_tmp_store->{$name}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
}, |
75
|
|
|
|
|
|
|
)); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute(_tmp_store => ( |
79
|
|
|
|
|
|
|
is => 'ro', |
80
|
|
|
|
|
|
|
isa => 'HashRef', |
81
|
|
|
|
|
|
|
lazy => 1, |
82
|
|
|
|
|
|
|
builder => 'read_all', |
83
|
|
|
|
|
|
|
clearer => '_clear_tmp_store', |
84
|
|
|
|
|
|
|
)); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__PACKAGE__->meta->add_method(read_all => sub { |
87
|
|
|
|
|
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
my $lazy = $self->lazy_write; |
89
|
|
|
|
|
|
|
my(%res, $rpc); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$rpc = $self->client->rpc('session-stats') or return; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$self->lazy_write(1); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
for my $camel (keys %both) { |
96
|
|
|
|
|
|
|
my $name = __PACKAGE__->_camel2Normal($camel); |
97
|
|
|
|
|
|
|
my $writer = "_set_$name"; |
98
|
|
|
|
|
|
|
$res{$name} = $rpc->{$camel}; |
99
|
|
|
|
|
|
|
$self->$writer($rpc->{$camel}); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$self->lazy_write($lazy); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
return \%res; |
105
|
|
|
|
|
|
|
}); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 LICENSE |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
See L<Transmission::Client> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |