line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Shoutcast::Admin::Listener; |
2
|
|
|
|
|
|
|
# $Id: Listener.pm 315 2008-03-19 00:07:39Z davidp $ |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
18
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
53
|
|
5
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
58
|
|
6
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
108
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
10
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
644
|
|
9
|
|
|
|
|
|
|
$VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Net::Shoutcast::Admin::Listener - object to represent a listener |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
An object representing a listener, returned by Net::Shoutcast::Admin. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Net::Shoutcast::Admin; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $shoutcast = Net::Shoutcast::Admin->new( |
27
|
|
|
|
|
|
|
host => 'server hostname', |
28
|
|
|
|
|
|
|
port => 8000, |
29
|
|
|
|
|
|
|
admin_password => 'mypassword', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if ($shoutcast->source_connected) { |
33
|
|
|
|
|
|
|
my @listeners = $shoutcast->listeners; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
for my $listener (@listeners) { |
36
|
|
|
|
|
|
|
printf "Listener from %s, listening for %s", |
37
|
|
|
|
|
|
|
$listener->host, $listener->listen_time |
38
|
|
|
|
|
|
|
; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} else { |
41
|
|
|
|
|
|
|
print "No source is currently connected."; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DESCRIPTION |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Object representing a listener, returned by Net::Shoutcast::Admin |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 INTERFACE |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=over 4 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item new |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
There's no reason to create instances of Net::Shoutcast::Admin::Listener |
57
|
|
|
|
|
|
|
directly; Net::Shoutcast::Admin creates and returns instances for you. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Having said that: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$song = Net::Shoutcast::Admin::Listener->new( %params ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Creates a new Net::Shoutcast::Admin::Listener object. Takes a hash of options |
64
|
|
|
|
|
|
|
as follows: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=over 4 |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item I |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The host from which this listener is connected |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item I |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The number of seconds this listener has been connected |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item I |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The number of buffer underruns this listener has suffered |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item I |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The software this user is reportedly using to listen |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=back |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub new { |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
0
|
1
|
|
my ($class, %params) = @_; |
91
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$self->{last_update} = 0; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my %acceptable_params = map { $_ => 1 } |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
qw(host connect_time underruns agent); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# make sure we haven't been given any bogus parameters: |
99
|
0
|
0
|
|
|
|
|
if (my @bad_params = grep { ! $acceptable_params{$_} } keys %params) { |
|
0
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
carp "Net::Shoutcast::Admin::Listener does not recognise param(s) " |
101
|
|
|
|
|
|
|
. join ',', @bad_params; |
102
|
0
|
|
|
|
|
|
return; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$self->{$_} = $params{$_} for keys %acceptable_params; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
if (my @missing_params = grep { ! $self->{$_} } keys %acceptable_params) { |
|
0
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
carp "Net::Shoutcast::Admin::Listener->new() must be supplied with " |
109
|
|
|
|
|
|
|
. "params: " |
110
|
|
|
|
|
|
|
. join ',', @missing_params; |
111
|
0
|
|
|
|
|
|
return; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
return $self; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item host |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Returns the hostname this listener is connected from |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
0
|
1
|
|
sub host { return shift->{host} } |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item listen_time |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Returns the number of seconds this listener has been connected |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
0
|
1
|
|
sub listen_time { return shift->{connect_time} } |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item underruns |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Returns the number of buffer underruns this listener has suffered |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
0
|
1
|
|
sub underruns { return shift->{underruns} } |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item agent |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Returns the agent this listener is reportedly using |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
0
|
1
|
|
sub agent { return shift->{agent} } |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
157
|
|
|
|
|
|
|
__END__ |