blib/lib/Net/UPnP/Device.pm

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