line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Icecast2; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Net::Icecast2::VERSION = '0.005'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Icecast2 Server API |
6
|
4
|
|
|
4
|
|
49019
|
use Moo; |
|
4
|
|
|
|
|
47102
|
|
|
4
|
|
|
|
|
27
|
|
7
|
4
|
|
|
4
|
|
7655
|
use MooX::Types::MooseLike::Base qw(Str Int); |
|
4
|
|
|
|
|
22700
|
|
|
4
|
|
|
|
|
414
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
41
|
use Carp; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
231
|
|
10
|
4
|
|
|
4
|
|
3854
|
use Safe::Isa; |
|
4
|
|
|
|
|
1921
|
|
|
4
|
|
|
|
|
557
|
|
11
|
4
|
|
|
4
|
|
2492
|
use Sub::Quote qw( quote_sub ); |
|
4
|
|
|
|
|
11257
|
|
|
4
|
|
|
|
|
252
|
|
12
|
4
|
|
|
4
|
|
4400
|
use LWP::UserAgent; |
|
4
|
|
|
|
|
274665
|
|
|
4
|
|
|
|
|
166
|
|
13
|
4
|
|
|
4
|
|
6062
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Net::Icecast2 - Icecast2 Server API |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Net::Icecast2; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $net_icecast = Net::Icecast2->new( |
24
|
|
|
|
|
|
|
host => 192.168.1.10, |
25
|
|
|
|
|
|
|
port => 8008, |
26
|
|
|
|
|
|
|
protocol => 'https', |
27
|
|
|
|
|
|
|
login => 'source', |
28
|
|
|
|
|
|
|
password => 'hackme', |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Make request to "/admin/stats" |
32
|
|
|
|
|
|
|
$net_icecast->request( '/stats' ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Make requsts and parse XML response from Icecast2 API |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 host |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Description : Icecast2 Server hostname |
43
|
|
|
|
|
|
|
Default : localhost |
44
|
|
|
|
|
|
|
Required : 0 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
has host => ( |
48
|
|
|
|
|
|
|
is => 'ro', |
49
|
|
|
|
|
|
|
isa => Str, |
50
|
|
|
|
|
|
|
default => quote_sub(q{ 'localhost' }), |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 port |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Description : Icecast2 Server port |
56
|
|
|
|
|
|
|
Default : 8000 |
57
|
|
|
|
|
|
|
Required : 0 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
has port => ( |
61
|
|
|
|
|
|
|
is => 'ro', |
62
|
|
|
|
|
|
|
isa => Int, |
63
|
|
|
|
|
|
|
default => quote_sub(q{ 8000 }), |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 protocol |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Description : Icecast2 Server protocol ( scheme ) |
69
|
|
|
|
|
|
|
Default : http |
70
|
|
|
|
|
|
|
Required : 0 |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
has protocol => ( |
74
|
|
|
|
|
|
|
is => 'ro', |
75
|
|
|
|
|
|
|
isa => Str, |
76
|
|
|
|
|
|
|
default => quote_sub(q{ 'http' }), |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 login |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Description : Icecast2 Server API login |
82
|
|
|
|
|
|
|
Required : 1 |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
has login => ( |
86
|
|
|
|
|
|
|
is => 'ro', |
87
|
|
|
|
|
|
|
isa => Str, |
88
|
|
|
|
|
|
|
required => 1, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 password |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Description : Icecast2 Server API password |
94
|
|
|
|
|
|
|
Required : 1 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
has password => ( |
98
|
|
|
|
|
|
|
is => 'ro', |
99
|
|
|
|
|
|
|
isa => Str, |
100
|
|
|
|
|
|
|
required => 1, |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
has _user_agent => ( |
104
|
|
|
|
|
|
|
is => 'ro', |
105
|
|
|
|
|
|
|
isa => quote_sub( q{ |
106
|
|
|
|
|
|
|
use Safe::Isa; |
107
|
|
|
|
|
|
|
$_[0]->$_isa('LWP::UserAgent') |
108
|
|
|
|
|
|
|
or die "_user_agent should be 'LWP::UserAgent'"; |
109
|
|
|
|
|
|
|
}), |
110
|
|
|
|
|
|
|
lazy => 1, |
111
|
|
|
|
|
|
|
builder => '_build__user_agent', |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _build__user_agent { |
115
|
|
|
|
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
my $user = $self->login; |
117
|
|
|
|
|
|
|
my $pass = $self->password; |
118
|
|
|
|
|
|
|
my $url = $self->host . ':' . $self->port; |
119
|
|
|
|
|
|
|
my $realm = 'Icecast2 Server'; |
120
|
|
|
|
|
|
|
my $agent = LWP::UserAgent->new; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$agent->credentials( $url, $realm, $user, $pass ); |
123
|
|
|
|
|
|
|
$agent; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 METHODS |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 request |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Usage : $net_icecast->request( '/stats' ); |
131
|
|
|
|
|
|
|
Arguments : Path to API action that goes after '/admin' |
132
|
|
|
|
|
|
|
Description : Method for making request to Icecast2 Server API |
133
|
|
|
|
|
|
|
Return : Parsed XML server request |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
sub request { |
137
|
|
|
|
|
|
|
my $self = shift; |
138
|
|
|
|
|
|
|
my $path = shift; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
defined $path or croak '$path should be defined in request'; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $url = $self->protocol .'://'. $self->host .':'. $self->port; |
143
|
|
|
|
|
|
|
my $response = $self->_user_agent->get( $url .'/admin'. $path, @_ ); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$response->is_success or croak 'Error on request: ' . |
146
|
|
|
|
|
|
|
( $response->code eq 401 ? 'wrong credentials' : $response->status_line ); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
XML::Simple->new->XMLin( $response->content ); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
no Moo; |
152
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
153
|
|
|
|
|
|
|
1; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SEE ALSO |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Icecast2 server: http://www.icecast.org |
158
|
|
|
|
|
|
|
Icecast2 API Docs: http://www.icecast.org/docs/icecast-trunk/icecast2_admin.html |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Related modules L L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 AUTHOR |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Pavel R3VoLuT1OneR Zhytomirsky |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Pavel R3VoLuT1OneR Zhytomirsky. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
171
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|