| 1 | package Net::Shoutcast::Admin::Listener; | ||||||||||
| 2 | # $Id: Listener.pm 315 2008-03-19 00:07:39Z davidp $ | ||||||||||
| 3 | |||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | $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<host> | ||||||||||
| 69 | |||||||||||
| 70 | The host from which this listener is connected | ||||||||||
| 71 | |||||||||||
| 72 | =item I<connect_time> | ||||||||||
| 73 | |||||||||||
| 74 | The number of seconds this listener has been connected | ||||||||||
| 75 | |||||||||||
| 76 | =item I<underruns> | ||||||||||
| 77 | |||||||||||
| 78 | The number of buffer underruns this listener has suffered | ||||||||||
| 79 | |||||||||||
| 80 | =item I<agent> | ||||||||||
| 81 | |||||||||||
| 82 | The software this user is reportedly using to listen | ||||||||||
| 83 | |||||||||||
| 84 | =back | ||||||||||
| 85 | |||||||||||
| 86 | =cut | ||||||||||
| 87 | |||||||||||
| 88 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 89 | |||||||||||
| 90 | 0 | my ($class, %params) = @_; | |||||||||
| 91 | 0 | my $self = bless {}, $class; | |||||||||
| 92 | |||||||||||
| 93 | 0 | $self->{last_update} = 0; | |||||||||
| 94 | |||||||||||
| 95 | 0 | my %acceptable_params = map { $_ => 1 } | |||||||||
| 96 | qw(host connect_time underruns agent); | ||||||||||
| 97 | |||||||||||
| 98 | # make sure we haven't been given any bogus parameters: | ||||||||||
| 99 | 0 | ▶ | if (my @bad_params = grep { ! $acceptable_params{$_} } keys %params) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | if (my @missing_params = grep { ! $self->{$_} } keys %acceptable_params) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | sub host { return shift->{host} } | ||||||||
|
Subroutine
host: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 126 | |||||||||||
| 127 | |||||||||||
| 128 | =item listen_time | ||||||||||
| 129 | |||||||||||
| 130 | Returns the number of seconds this listener has been connected | ||||||||||
| 131 | |||||||||||
| 132 | =cut | ||||||||||
| 133 | |||||||||||
| 134 | 0 | ▶ | sub listen_time { return shift->{connect_time} } | ||||||||
|
Subroutine
listen_time: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 135 | |||||||||||
| 136 | |||||||||||
| 137 | |||||||||||
| 138 | =item underruns | ||||||||||
| 139 | |||||||||||
| 140 | Returns the number of buffer underruns this listener has suffered | ||||||||||
| 141 | |||||||||||
| 142 | =cut | ||||||||||
| 143 | |||||||||||
| 144 | 0 | ▶ | sub underruns { return shift->{underruns} } | ||||||||
|
Subroutine
underruns: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 145 | |||||||||||
| 146 | |||||||||||
| 147 | =item agent | ||||||||||
| 148 | |||||||||||
| 149 | Returns the agent this listener is reportedly using | ||||||||||
| 150 | |||||||||||
| 151 | =cut | ||||||||||
| 152 | |||||||||||
| 153 | 0 | ▶ | sub agent { return shift->{agent} } | ||||||||
|
Subroutine
agent: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 154 | |||||||||||
| 155 | |||||||||||
| 156 | 3 | 1; # Magic true value required at end of module | |||||||||
| 157 | __END__ | ||||||||||