blib/lib/Net/UPnP/Device.pm

filter: Statementstmt 78.3% 76 / 97 Branchbran 78.5% 11 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 67.8% 19 / 28 Podpod 52.1% 12 / 23 totaltotal 72.8% 118 / 162 CC 9 SCAR 6.3
CC
9
Cov
78%
getdescription
3.1
getservicebyname
3.1
setservicefromdescription
3.0
CRAP 1.9
« blib/lib/Net/UPnP/AV/Content.pm ↑ Summary blib/lib/Net/UPnP/HTTPResponse.pm »
1 package Net::UPnP::Device;
2  
3 #-----------------------------------------------------------------
4 # Net::UPnP::Device
5 #-----------------------------------------------------------------
6  
7 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶use Net::UPnP::HTTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Net::UPnP::Service;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶use vars qw($_SSDP $_DESCRIPTION $_SERVICELIST);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 $_SSDP = 'ssdp';
16 6 $_DESCRIPTION = 'description';
17 6 $_SERVICELIST = 'serviceList';
18  
19 #------------------------------
20 # new
21 #------------------------------
22  
23 7 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
24 7 my($class) = shift;
25 7 my($this) = {
26 $Net::UPnP::Device::_SSDP => '',
27 $Net::UPnP::Device::_DESCRIPTION => '',
28 @Net::UPnP::Device::_SERVICELIST => (),
29 };
30 7 bless $this, $class;
31 }
32  
33 #------------------------------
34 # ssdp
35 #------------------------------
36  
37 6 ▶sub setssdp() {
Subroutine setssdp: called CC=1 SCAR=0.0
Pod undocumented
38 6 my($this) = shift;
39 6 $this->{$Net::UPnP::Device::_SSDP} = $_[0];
40 }
41  
42 0 ▶sub getssdp() {
Subroutine getssdp: not called CC=1 SCAR=6.9
Pod undocumented
43 0 my($this) = shift;
44 0 $this->{$Net::UPnP::Device::_SSDP};
45 }
46  
47 # Undefined means a manually constructed, caller-trusted device. Discovery
48 # always stores an explicit policy, including an empty (deny-all) list.
49 5 ▶sub setallowedaddresses {
Subroutine setallowedaddresses: called CC=1 SCAR=0.0
Pod undocumented
50 5 my ($this, $addresses) = @_;
51 5 $this->{allowed_addresses} = Net::UPnP::HTTP::_address_list($addresses);
52 }
53  
54 15 ▶sub getallowedaddresses {
Subroutine getallowedaddresses: called CC=2 SCAR=6.9
Pod undocumented
55 15 my ($this) = @_;
56 15 ▶ return undef unless exists $this->{allowed_addresses};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $this->{"allowed_addresses"} 3 12 15
57 12 return [@{$this->{allowed_addresses}}];
58 }
59  
60 #------------------------------
61 # description
62 #------------------------------
63  
64 7 ▶sub setdescription() {
Subroutine setdescription: called CC=1 SCAR=0.0
Pod undocumented
65 7 my($this) = shift;
66 7 my($description) = $_[0];
67 7 $this->{$Net::UPnP::Device::_DESCRIPTION} = $description;
68 7 $this->setservicefromdescription($description);
69 }
70  
71 17 ▶sub getdescription() {
Subroutine getdescription: called CC=3 SCAR=11.2
Pod documented
72 17 my($this) = shift;
73 17 my %args = (
74 name => undef,
75 @_,
76 );
77 17 ▶ if ($args{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"name"}) 17 0 17
78 # Thanks for Tim Engler <engler at gmail.com> (2009/06/10)
79 17 ▶ unless ($this->{$Net::UPnP::Device::_DESCRIPTION} =~ m/<$args{name}>(.*?)<\/$args{name}>/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{$Net::UPnP::Device::_DESCRIPTION} =~ m[<$args{"name"}>(.*?)</$args{"name"}>]i) 4 13 17
80 4 return '';
81 }
82 13 return $1;
83 }
84 0 $this->{$Net::UPnP::Device::_DESCRIPTION};
85 }
86  
87 #------------------------------
88 # service
89 #------------------------------
90  
91 7 ▶sub setservicefromdescription() {
Subroutine setservicefromdescription: called CC=3 SCAR=11.0
Pod undocumented
92 7 my($this) = shift;
93 my(
94 7 $description,
95 $servicelist_description,
96 @serviceList,
97 $service,
98 );
99  
100
101 7 $description = $_[0];
102
103 7 ▶ unless ($description =~ m/<serviceList>(.*)<\/serviceList>/si) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($description =~ m[<serviceList>(.*)</serviceList>]is) 3 4 7
104 3 return;
105 }
106  
107 4 $servicelist_description = $1;
108  
109 4 @{$this->{$Net::UPnP::Device::_SERVICELIST}} = ();
110 4 ▶ while ($servicelist_description =~ m/<service>(.*?)<\/service>/sgi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($servicelist_description =~ m[<service>(.*?)</service>]sig) 4 4 8
111 4 $service = Net::UPnP::Service->new();
112 4 $service->setdevicedescription($1);
113 4 $service->setdevice($this);
114 4 push (@{$this->{$Net::UPnP::Device::_SERVICELIST}}, $service);
115 }
116 }
117  
118 #------------------------------
119 # serviceList
120 #------------------------------
121  
122 4 ▶sub getservicelist() {
Subroutine getservicelist: called CC=1 SCAR=0.0
Pod documented
123 4 my($this) = shift;
124 4 @{$this->{$Net::UPnP::Device::_SERVICELIST}};
125 }
126  
127 #------------------------------
128 # getservicebyname
129 #------------------------------
130  
131 1 ▶sub getservicebyname() {
Subroutine getservicebyname: called CC=3 SCAR=11.2
Pod undocumented
132 1 my($this) = shift;
133 1 my ($service_name) = @_;
134 my (
135 1 @serviceList,
136 $service,
137 $service_type,
138 );
139 1 @serviceList = $this->getservicelist();
140 1 foreach $service (@serviceList) {
141 1 $service_type = $service->getservicetype();
142 1 ▶ if ($service_type eq $service_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($service_type eq $service_name) 1 0 1
143 1 return $service;
144 }
145 }
146 0 return undef;
147 }
148  
149 #------------------------------
150 # getlocation
151 #------------------------------
152  
153 12 ▶sub getlocation() {
Subroutine getlocation: called CC=2 SCAR=7.6
Pod undocumented
154 12 my($this) = shift;
155 12 ▶ unless ($this->{$Net::UPnP::Device::_SSDP} =~ m/LOCATION[ :]+(.*)\r/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{$Net::UPnP::Device::_SSDP} =~ /LOCATION[ :]+(.*)\r/i) 0 12 12
156 0 return '';
157 }
158 12 return $1;
159 }
160  
161 #------------------------------
162 # getdevicetype
163 #------------------------------
164  
165 1 ▶sub getdevicetype() {
Subroutine getdevicetype: called CC=1 SCAR=0.0
Pod documented
166 1 my($this) = shift;
167 1 $this->getdescription(name => 'deviceType');
168 }
169  
170 #------------------------------
171 # getfriendlyname
172 #------------------------------
173  
174 3 ▶sub getfriendlyname() {
Subroutine getfriendlyname: called CC=1 SCAR=0.0
Pod documented
175 3 my($this) = shift;
176 3 $this->getdescription(name => 'friendlyName');
177 }
178  
179 #------------------------------
180 # getmanufacturer
181 #------------------------------
182  
183 0 ▶sub getmanufacturer() {
Subroutine getmanufacturer: not called CC=1 SCAR=6.9
Pod documented
184 0 my($this) = shift;
185 0 $this->getdescription(name => 'manufacturer');
186 }
187  
188 #------------------------------
189 # getmanufacturerurl
190 #------------------------------
191  
192 0 ▶sub getmanufacturerurl() {
Subroutine getmanufacturerurl: not called CC=1 SCAR=6.9
Pod undocumented
193 0 my($this) = shift;
194 0 $this->getdescription(name => 'manufacturerURL');
195 }
196  
197 #------------------------------
198 # getmodeldescription
199 #------------------------------
200  
201 0 ▶sub getmodeldescription() {
Subroutine getmodeldescription: not called CC=1 SCAR=6.9
Pod documented
202 0 my($this) = shift;
203 0 $this->getdescription(name => 'modelDescription');
204 }
205  
206 #------------------------------
207 # getmodelname
208 #------------------------------
209  
210 0 ▶sub getmodelname() {
Subroutine getmodelname: not called CC=1 SCAR=6.9
Pod documented
211 0 my($this) = shift;
212 0 $this->getdescription(name => 'modelName');
213 }
214  
215 #------------------------------
216 # getmodelnumber
217 #------------------------------
218  
219 0 ▶sub getmodelnumber() {
Subroutine getmodelnumber: not called CC=1 SCAR=6.9
Pod documented
220 0 my($this) = shift;
221 0 $this->getdescription(name => 'modelNumber');
222 }
223  
224 #------------------------------
225 # getmodelurl
226 #------------------------------
227  
228 0 ▶sub getmodelurl() {
Subroutine getmodelurl: not called CC=1 SCAR=6.9
Pod documented
229 0 my($this) = shift;
230 0 $this->getdescription(name => 'modelURL');
231 }
232  
233 #------------------------------
234 # getserialnumber
235 #------------------------------
236  
237 0 ▶sub getserialnumber() {
Subroutine getserialnumber: not called CC=1 SCAR=6.9
Pod documented
238 0 my($this) = shift;
239 0 $this->getdescription(name => 'serialNumber');
240 }
241  
242 #------------------------------
243 # getudn
244 #------------------------------
245  
246 1 ▶sub getudn() {
Subroutine getudn: called CC=1 SCAR=0.0
Pod documented
247 1 my($this) = shift;
248 1 $this->getdescription(name => 'UDN');
249 }
250  
251 #------------------------------
252 # getupc
253 #------------------------------
254  
255 0 ▶sub getupc() {
Subroutine getupc: not called CC=1 SCAR=6.9
Pod documented
256 0 my($this) = shift;
257 0 $this->getdescription(name => 'UPC');
258 }
259  
260 #------------------------------
261 # geturlbase
262 #------------------------------
263  
264 12 ▶sub geturlbase() {
Subroutine geturlbase: called CC=1 SCAR=0.0
Pod undocumented
265 12 my($this) = shift;
266 12 $this->getdescription(name => 'URLBase');
267 }
268  
269 6 1;
270  
271 __END__
« blib/lib/Net/UPnP/AV/Content.pm ↑ Summary blib/lib/Net/UPnP/HTTPResponse.pm »