Net/RDEP.pm

filter: Statementstmt 19.5% 48 / 245 Branchbran 7.0% 7 / 100 Conditioncond 4.4% 2 / 45 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 47.8% 11 / 23 Podpod 100% 11 / 11 totaltotal 17.5% 79 / 449 CC 70 SCAR 46.3
CC
70
Cov
15%
open
272.0
_processTraits
210.0
get
132.0
CRAP 103.0
↑ Summary XML/Idiom.pm »
1 # Net::RDEP.pm
2 #
3 # $Id: RDEP.pm,v 1.1 2004/12/23 12:05:58 jminieri Exp $
4 #
5 # Copyright (c) 2004 Joe Minieri <jminieri@mindspring.com> and OpenService (www.open.com).
6 # All rights reserved.
7 # This program is free software; you can redistribute it and/or modify it under the same
8 # terms as Perl itself.
9 #
10  
11 package Net::RDEP;
12  
13 1 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # Items to export into callers namespace by default. Note: do not export
21 # names by default without a very good reason. Use EXPORT_OK instead.
22 # Do not simply export all your public functions/methods/constants.
23  
24 1 our $VERSION = '0.03';
25  
26 1 my %_eventTypes = (
27 'evError', 1,
28 'evAlert', 1,
29 'evStatus', 1,
30 'evLogTransaction', 1,
31 'evShunRqst', 1
32 );
33  
34 1 my %_alertSeverities = (
35 'informational', 1,
36 'low', 1,
37 'medium', 1,
38 'high', 1
39 );
40  
41 1 my %_errorSeverities = (
42 'warning', 1,
43 'error', 1,
44 'fatal', 1
45 );
46  
47 ##########################################################################################
48 #
49 # AUTOLOAD get/set methods when they're generic
50 #
51 1 ▶use vars '$AUTOLOAD';
Subroutine BEGIN: called CC=1 SCAR=0.0
52 5 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=5 SCAR=17.6
53 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
54 5 my ($self, $value) = @_;
55  
56 5 my $key =($AUTOLOAD =~ /.*::([_\w]+)$/)[0];
57  
58 5 ▶ unless(defined($key) and exists($self->{ $key })) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $key and exists $self->{$key}) 0 5 5
Condition33%1/3
defined $key and exists $self->{$key}
!ll&&!rl&&r
005
MC/DC0%0/2
defined $key and exists $self->{$key}
defined $key exists $self->{$key}
Truth table33%1/3
A and B
A= defined $keyB= exists $self->{$key}
ABresult
0X0
100
111
59 0 $self->error(1);
60 0 $self->errorString("No such parameter $key");
61 0 return undef;
62 }
63  
64 # set this up for next time
65 5 ▶ *{$AUTOLOAD} = sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
66 2 my ($self, $value) = @_;
67 2 ▶ if (defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 0 2 2
68 0 return $self->{ $key } = $value;
69 } else {
70 2 ▶ return defined($self->{ $key })?$self->{ $key }:undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{$key} ? : 2 0 2
71 }
72 5 };
73  
74 # go ahead and execute it this time
75 5 ▶ if ( defined( $value )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 2 3 5
76 # set operation
77 2 return $self->{ $key } = $value;
78 } else {
79 # get operation
80 3 ▶ return defined($self->{ $key })?$self->{ $key }:undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{$key} ? : 0 3 3
81 }
82 }
83  
84 ##########################################################################################
85 #
86 # Helper methods
87 #
88 0 ▶sub _make_uri {
Subroutine _make_uri: not called CC=1 SCAR=6.9
89 0 my $self = shift;
90  
91 0 my $URI = URI->new();
92 0 $URI->scheme('https');
93 0 $URI->host( $self->Server );
94 0 $URI->port( $self->Port );
95 0 $URI->path( $self->Path );
96  
97 0 return $URI->as_string;
98 }
99  
100 ##########################################################################################
101 #
102 # Non-generic get/set methods
103 #
104 0 ▶sub _processTraits {
Subroutine _processTraits: not called CC=14 SCAR=53.5
105 0 my $self = shift;
106 0 my $whichTraits = shift;
107  
108 0 $self->error(undef);
109 0 $self->errorString(undef);
110  
111 0 ▶ unless(defined($whichTraits) and exists($self->{ $whichTraits })) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $whichTraits and exists $self->{$whichTraits}) 0 0 0
Condition0%0/3
defined $whichTraits and exists $self->{$whichTraits}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $whichTraits and exists $self->{$whichTraits}
defined $whichTraits exists $self->{$whichTraits}
Truth table0%0/3
A and B
A= defined $whichTraitsB= exists $self->{$whichTraits}
ABresult
0X0
100
111
112 0 $self->error(1);
113 0 $self->errorString("No such trait attribute: $whichTraits");
114 0 return undef;
115 }
116  
117 # the spec for this parameter isn't clear -- I'm going to assume this
118 # goes from 0-15 instead of 1-16.
119  
120 0 my @traits;
121 0 foreach my $trait ( @_ ) {
122 0 ▶ if( $trait =~ /^\d+$/ and $trait <16 and $trait >-1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($trait =~ /^\d+$/ and $trait < 16 and $trait > -1) { } 0 0 0
elsif ($trait =~ /^(\d+)-(\d+)$/ and $1 < 16 and $1 > -1 and $2 < 16 and $2 > -1 and $1 < $2) { } 0 0 0
Condition0%0/6
$trait =~ /^\d+$/ and $trait < 16 and $trait > -1
!ll&&!rl&&r
000
$trait =~ /^\d+$/ and $trait < 16
!ll&&!rl&&r
000
MC/DC0%0/3
$trait =~ /^\d+$/ and $trait < 16 and $trait > -1
$trait =~ /^\d+$/ $trait < 16 $trait > -1
Truth table0%0/4
A and B and C
A= $trait =~ /^\d+$/B= $trait < 16C= $trait > -1
ABCresult
0XX0
10X0
1100
1111
123 # individual trait
124 0 push(@traits, $trait);
125 ▶ } elsif ( $trait =~ /^(\d+)-(\d+)$/ and
Condition0%0/15
$trait =~ /^(\d+)-(\d+)$/ and $1 < 16 and $1 > -1 and $2 < 16 and $2 > -1 and $1 < $2
!ll&&!rl&&r
000
$trait =~ /^(\d+)-(\d+)$/ and $1 < 16 and $1 > -1 and $2 < 16 and $2 > -1
!ll&&!rl&&r
000
$trait =~ /^(\d+)-(\d+)$/ and $1 < 16 and $1 > -1 and $2 < 16
!ll&&!rl&&r
000
$trait =~ /^(\d+)-(\d+)$/ and $1 < 16 and $1 > -1
!ll&&!rl&&r
000
$trait =~ /^(\d+)-(\d+)$/ and $1 < 16
!ll&&!rl&&r
000
MC/DC0%0/6
$trait =~ /^(\d+)-(\d+)$/ and $1 < 16 and $1 > -1 and $2 < 16 and $2 > -1 and $1 < $2
$trait =~ /^(\d+)-(\d+)$/ $1 < 16 $1 > -1 $2 < 16 $2 > -1 $1 < $2
Truth table0%0/7
A and B and C and D and E and F
A= $trait =~ /^(\d+)-(\d+)$/B= $1 < 16C= $1 > -1D= $2 < 16E= $2 > -1F= $1 < $2
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
126 $1 <16 and $1>-1 and
127 $2 <16 and $2>-1 and
128 $1 < $2 ) {
129 # trait range
130 0 push(@traits, $trait);
131 }
132 }
133  
134 0 ▶ if($#traits > -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#traits > -1) { } 0 0 0
135 # note -- the spec shows examines with a ',' separating the traits
136 # and specifies a '+' between them. I'm going with the example.
137 0 return $self->{ $whichTraits } = join(',', @traits);
138 } else {
139 0 $self->error(1);
140 0 $self->errorString("No valid alarm traits: " . join(',', @_));
141 0 return undef;
142 }
143 }
144  
145 0 ▶sub mustHaveAlarmTraits {
Subroutine mustHaveAlarmTraits: not called CC=2 SCAR=17.9
Pod documented
146 0 my $self = shift;
147  
148 0 ▶ unless(defined($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 0 0 0
149 # if no parameter, the treat as "get" method
150 0 return $self->{ 'mustHaveAlarmTraits' };
151 }
152  
153 0 return $self->_processTraits('mustHaveAlarmTraits', @_);
154 }
155  
156 0 ▶sub mustNotHaveAlarmTraits {
Subroutine mustNotHaveAlarmTraits: not called CC=2 SCAR=17.9
Pod documented
157 0 my $self = shift;
158  
159 0 ▶ unless(defined($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 0 0 0
160 # if no parameter, the treat as "get" method
161 0 return $self->{ 'mustNotHaveAlarmTraits' };
162 }
163  
164 0 return $self->_processTraits('mustNotHaveAlarmTraits', @_);
165 }
166  
167  
168 0 ▶sub errorSeverities {
Subroutine errorSeverities: not called CC=3 SCAR=24.8
Pod documented
169 0 my $self = shift;
170 0 my $error = shift;
171  
172 0 $self->error(undef);
173 0 $self->errorString(undef);
174  
175 0 ▶ unless(defined($error)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $error) 0 0 0
176 # if no parameter, the treat as "get" method
177 0 return $self->{ 'errorSeverities' };
178 }
179  
180 0 $error = lc($error);
181 0 ▶ if(exists($_errorSeverities{ $error })) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_errorSeverities{$error}) { } 0 0 0
182 0 return $self->{ 'errorSeverities' } = $error
183 } else {
184 0 $self->error(1);
185 0 $self->errorString("Invalid error severity: $error");
186  
187 0 return undef;
188 }
189 }
190  
191 0 ▶sub alertSeverities {
Subroutine alertSeverities: not called CC=5 SCAR=34.0
Pod documented
192 0 my $self = shift;
193  
194 0 $self->error(undef);
195 0 $self->errorString(undef);
196  
197 0 ▶ unless(defined($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 0 0 0
198 # if no parameter, the treat as "get" method
199 0 return $self->{ 'alertSeverities' };
200 }
201  
202 0 my @alertseverities;
203 0 foreach my $s ( @_ ) {
204 0 my $severity = lc($s);
205 0 ▶ if(exists($_alertSeverities{ $severity })) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_alertSeverities{$severity}) 0 0 0
206 0 push(@alertseverities, $severity);
207 }
208 }
209  
210 0 ▶ if($#alertseverities > -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#alertseverities > -1) { } 0 0 0
211 0 return $self->{ 'alertSeverities' } = join('+', @alertseverities);
212 } else {
213 0 $self->error(1);
214 0 $self->errorString("No valid alert severities: " . join(',', @_));
215 0 return undef;
216 }
217 }
218  
219 0 ▶sub events {
Subroutine events: not called CC=5 SCAR=34.0
Pod documented
220 0 my $self = shift;
221  
222 0 ▶ unless(defined($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 0 0 0
223 # if no parameter, the treat as "get" method
224 0 return $self->{ 'events' };
225 }
226  
227 0 $self->error(undef);
228 0 $self->errorString(undef);
229  
230 0 my @eventList;
231  
232 my %dedup;
233 0 foreach my $eventtype ( grep( !$dedup{ $_ }++, @_ ) ) {
234 0 ▶ if(exists($_eventTypes{ $eventtype })) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_eventTypes{$eventtype}) 0 0 0
235 0 push(@eventList, $eventtype);
236 }
237 }
238  
239 0 ▶ if($#eventList > -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#eventList > -1) { } 0 0 0
240 0 return $self->{ 'events' } = join('+', @eventList);
241 } else {
242 0 $self->error(1);
243 0 $self->errorString("No valid event types: " . join(',', @_));
244 0 return undef;
245 }
246 }
247  
248 0 ▶sub confirm {
Subroutine confirm: not called CC=4 SCAR=30.0
Pod documented
249 0 my $self = shift;
250 0 my $confirm = shift;
251  
252 0 ▶ unless(defined($confirm)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $confirm) 0 0 0
253 # if no parameter, the treat as "get" method
254 0 return $self->{ 'confirm' };
255 }
256  
257 0 $self->error(undef);
258 0 $self->errorString(undef);
259  
260 0 $confirm = lc($confirm);
261 0 ▶ if($confirm eq 'no' or $confirm eq 'yes') {
Branch: 1 branch
BranchTrueFalseTotal
if ($confirm eq 'no' or $confirm eq 'yes') { } 0 0 0
Condition0%0/3
$confirm eq "no" or $confirm eq "yes"
l!l&&r!l&&!r
000
MC/DC0%0/2
$confirm eq "no" or $confirm eq "yes"
$confirm eq "no" $confirm eq "yes"
Truth table0%0/3
A or B
A= $confirm eq "no"B= $confirm eq "yes"
ABresult
1X1
011
000
262 0 return $self->{ 'confirm' } = $confirm;
263 } else {
264 0 $self->error(1);
265 0 $self->errorString("Invalid confirm value: $confirm");
266 0 return undef;
267 }
268 }
269  
270 0 ▶sub Type {
Subroutine Type: not called CC=4 SCAR=30.0
Pod documented
271 0 my $self = shift;
272 0 my $type = shift;
273  
274 0 ▶ unless(defined($type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type) 0 0 0
275 # if no parameter, the treat as "get" method
276 0 return $self->{ 'Type' };
277 }
278  
279 0 $self->error(undef);
280 0 $self->errorString(undef);
281  
282 0 $type = lc($type);
283 0 ▶ if($type eq 'subscription' or $type eq 'query') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'subscription' or $type eq 'query') { } 0 0 0
Condition0%0/3
$type eq "subscription" or $type eq "query"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "subscription" or $type eq "query"
$type eq "subscription" $type eq "query"
Truth table0%0/3
A or B
A= $type eq "subscription"B= $type eq "query"
ABresult
1X1
011
000
284 0 return $self->{ 'Type' } = $type;
285 } else {
286 0 $self->error(1);
287 0 $self->errorString("Invalid RDEP connection type: $type");
288 0 return undef;
289 }
290 }
291  
292 ##########################################################################################
293 #
294 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.3
Pod documented
295 1 my $caller = shift;
296 1 my %attr = @_;
297  
298 1 ▶ my $class = (ref($caller) or $caller);
Condition33%1/3
ref $caller || $caller
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $caller || $caller
ref $caller $caller
Truth table33%1/3
A || B
A= ref $callerB= $caller
ABresult
1X1
011
000
299 1 my $self = bless {
300 # connection parameters
301 'Server', => '127.0.0.1',
302 'Port', => 443,
303 'UserAgent', => 'RDEP Client/4.0',
304 'Username', => 'username',
305 'Password', => 'password',
306 'Path', => '/cgi-bin/event-server',
307 'state', => 'closed',
308 # subscription parameters
309 'Type', => 'subscription',
310 'Cookie', => undef,
311 'Authorization', => undef,
312 'subscriptionId', => undef,
313 # retrieval parameters
314 'startTime', => undef,
315 'stopTime', => undef, # only for queries
316 'events', => 'evAlert',
317 'alertSeverities', => undef,
318 'errorSeverities', => undef,
319 'mustHaveAlarmTraits', => undef,
320 'mustNotHaveAlarmTraits', => undef,
321 'timeout', => 1,
322 'maxNbrOfEvents', => 20, # set this just so we don't crush the box
323 'confirm', => 'yes',
324 # results
325 'missedEvents', => undef,
326 'error', => undef,
327 'errorString', => undef
328 }, $class;
329  
330 1 foreach my $attribute ( keys %attr ) {
331 0 $self->$attribute( $attr{ $attribute });
332 }
333  
334 1 $self->state('closed');
335 1 $self->missedEvents(undef);
336 1 $self->error(undef);
337 1 $self->errorString(undef);
338  
339 1 return $self;
340  
341 }
342  
343 0 ▶sub open {
Subroutine open: not called CC=16 SCAR=56.1
Pod documented
344 0 my $self = shift;
345  
346 0 $self->error(undef);
347 0 $self->errorString(undef);
348  
349 0 my $http_auth = $self->Username . ':' . $self->Password;
350 0 $self->Authorization('Basic ' . MIME::Base64::encode( $http_auth, ''));
351  
352 0 my %headers = (
353 'User-Agent' => $self->UserAgent,
354 'Authorization' => $self->Authorization
355 );
356  
357 # manditory parameters for subscription
358 0 my %form_parameters = (
359 events => $self->events
360 );
361  
362 0 ▶ if ($self->Type eq 'subscription') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Type eq "subscription") 0 0 0
363 0 $form_parameters{ 'action' } = 'open';
364 0 ▶ if (defined($self->timeout)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->timeout) 0 0 0
365 0 $form_parameters{ 'timeout' } = $self->timeout;
366 }
367 0 ▶ if (defined($self->confirm)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->confirm) 0 0 0
368 0 $form_parameters{ 'confirm' } = $self->confirm;
369 }
370 }
371  
372 0 ▶ if (defined($self->startTime)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->startTime) 0 0 0
373 0 $form_parameters{ 'startTime' } = $self->startTime;
374 }
375  
376 0 ▶ if (defined($self->maxNbrOfEvents)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->maxNbrOfEvents) 0 0 0
377 0 $form_parameters{ 'maxNbrOfEvents' } = $self->maxNbrOfEvents;
378 }
379  
380 0 ▶ if (defined($self->mustHaveAlarmTraits)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->mustHaveAlarmTraits) 0 0 0
381 0 $form_parameters{ 'mustHaveAlarmTraits' } = $self->mustHaveAlarmTraits;
382 }
383  
384 0 ▶ if (defined($self->mustNotHaveAlarmTraits)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->mustNotHaveAlarmTraits) 0 0 0
385 0 $form_parameters{ 'mustNotHaveAlarmTraits' } = $self->mustNotHaveAlarmTraits;
386 }
387  
388 0 ▶ if (defined($self->alertSeverities)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->alertSeverities) 0 0 0
389 0 $form_parameters{ 'alertSeverities' } = $self->alertSeverities;
390 }
391  
392 0 ▶ if (defined($self->errorSeverities)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->errorSeverities) 0 0 0
393 0 $form_parameters{ 'errorSeverities' } = $self->errorSeverities;
394 }
395  
396 0 ▶ if ($self->Type eq 'query' and defined($self->stopTime)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Type eq "query" and defined $self->stopTime) 0 0 0
Condition0%0/3
$self->Type eq "query" and defined $self->stopTime
!ll&&!rl&&r
000
MC/DC0%0/2
$self->Type eq "query" and defined $self->stopTime
$self->Type eq "query" defined $self->stopTime
Truth table0%0/3
A and B
A= $self->Type eq "query"B= defined $self->stopTime
ABresult
0X0
100
111
397 0 $form_parameters{ 'stopTime' } = $self->stopTime;
398 }
399  
400 0 my $LWP = LWP::UserAgent->new();
401 0 my $result = $LWP->post($self->_make_uri, \%form_parameters, %headers);
402  
403 0 ▶ if($result->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->is_success) { } 0 0 0
404 0 ▶ if($self->Type eq 'subscription' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Type eq "subscription") 0 0 0
405 0 ▶ if(my $cookie = $result->header('Set-Cookie')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cookie = $result->header('Set-Cookie')) { } 0 0 0
406 0 $self->Cookie((split(';', $cookie))[0]);
407 } else {
408 0 $self->error(1);
409 0 $self->errorString( "No Cookie in header: " . $result->status_line);
410 0 return undef;
411 }
412  
413 0 ▶ if(my $parameter = $result->header('X-CISCO-RDEP-PARAMETERS')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parameter = $result->header('X-CISCO-RDEP-PARAMETERS')) { } 0 0 0
414 0 $self->subscriptionId((split('=',$parameter))[1]);
415 } else {
416 0 $self->error(1);
417 0 $self->errorString( "No subscription ID in header: " . $result->status_line);
418 0 return undef;
419 }
420  
421 0 $self->state('opened');
422 }
423 } else {
424 0 $self->error(1);
425 0 $self->errorString( "Query failed: " . $result->status_line);
426 }
427  
428 # on a subscription open, there is no content. On a query, the content is the events
429 0 return $result->content;
430 }
431  
432 0 ▶sub get {
Subroutine get: not called CC=11 SCAR=48.8
Pod documented
433 0 my $self = shift;
434  
435 0 $self->error(undef);
436 0 $self->errorString(undef);
437  
438 # if we're just doing a query, return the "open";
439 0 ▶ if( $self->Type eq 'query' ) { return $self->open() }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Type eq "query") 0 0 0
440  
441 # if we're doing a subscription, open first, the proceed
442 0 ▶ if( $self->state eq 'closed' ) { $self->open() }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->state eq "closed") 0 0 0
443  
444 #
445 # only event subscriptions should be here
446 0 my %headers = (
447 'User-Agent' => $self->UserAgent,
448 'Authorization' => $self->Authorization,
449 'Cookie' => $self->Cookie
450 );
451  
452 0 my %form_parameters = (
453 'action' => 'get',
454 'subscriptionId' => $self->subscriptionId
455 );
456  
457 0 ▶ if (defined($self->timeout)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->timeout) 0 0 0
458 0 $form_parameters{ 'timeout' } = $self->timeout;
459 }
460  
461 0 ▶ if (defined($self->confirm)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->confirm) 0 0 0
462 0 $form_parameters{ 'confirm' } = $self->confirm;
463 }
464  
465 0 ▶ if (defined($self->maxNbrOfEvents)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->maxNbrOfEvents) 0 0 0
466 0 $form_parameters{ 'maxNbrOfEvents' } = $self->maxNbrOfEvents;
467 }
468  
469 0 my $LWP = LWP::UserAgent->new();
470 0 my $result = $LWP->post($self->_make_uri, \%form_parameters, %headers);
471  
472 0 ▶ if($result->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->is_success) { } 0 0 0
473 0 ▶ if(my $cookie = $result->header('Set-Cookie')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cookie = $result->header("Set-Cookie")) 0 0 0
474 0 $self->Cookie((split(';', $cookie))[0]);
475 }
476  
477 0 ▶ if(my $parameter = $result->header('X-CISCO-RDEP-PARAMETERS')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parameter = $result->header("X-CISCO-RDEP-PARAMETERS")) 0 0 0
478 0 my ($name, $value) = split('=', $parameter);
479 0 ▶ if($name eq 'missedEvents') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "missedEvents") 0 0 0
480 0 ▶ if($value eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq 'true') { } 0 0 0
481 0 $self->missedEvents(1);
482 0 $self->error(1);
483 0 $self->errorString( "Events were dropped between polls");
484 } else {
485 0 $self->missedEvents(undef);
486 }
487 }
488 }
489 0 $self->state('opened');
490 0 return $result->content;
491 } else {
492 0 $self->error(1);
493 0 $self->errorString( "Query failed: " . $result->status_line);
494 0 $self->state('closed');
495 0 return undef;
496 }
497 }
498  
499 0 ▶sub close {
Subroutine close: not called CC=5 SCAR=34.0
Pod documented
500 0 my $self = shift;
501  
502 0 $self->error(undef);
503 0 $self->errorString(undef);
504  
505 0 ▶ return if( $self->state eq 'closed' or $self->Type eq 'query' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->state eq "closed" or $self->Type eq "query" 0 0 0
Condition0%0/3
$self->state eq "closed" or $self->Type eq "query"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->state eq "closed" or $self->Type eq "query"
$self->state eq "closed" $self->Type eq "query"
Truth table0%0/3
A or B
A= $self->state eq "closed"B= $self->Type eq "query"
ABresult
1X1
011
000
506  
507 0 my %headers = (
508 'User-Agent' => $self->UserAgent,
509 'Authorization' => $self->Authorization,
510 'Cookie' => $self->Cookie
511 );
512  
513 # manditory parameters for subscription
514 0 my %form_parameters = (
515 action => 'close',
516 subscriptionId => $self->subscriptionId
517 );
518  
519 0 my $LWP = LWP::UserAgent->new();
520 0 my $result = $LWP->post($self->_make_uri, \%form_parameters, %headers);
521  
522 0 $self->state('closed');
523 0 ▶ if(defined($result) and $result->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result and $result->is_success) { } 0 0 0
Condition0%0/3
defined $result and $result->is_success
!ll&&!rl&&r
000
MC/DC0%0/2
defined $result and $result->is_success
defined $result $result->is_success
Truth table0%0/3
A and B
A= defined $resultB= $result->is_success
ABresult
0X0
100
111
524 0 return $result->content;
525 } else {
526 0 $self->error(1);
527 0 $self->errorString( "Query failed: " . $result->status_line);
528 0 return undef;
529 }
530 }
531  
532 #
533 # close connection, just in case we forgot to call close() properly
534 1 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=8.1
535 1 my $self = shift;
536  
537 0 ▶ if($self->state eq 'opened') { $self->close() }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->state eq "opened") 0 1 1
538 }
539  
540 #
541 ##########################################################################################
542  
543 1 1;
544 __END__
↑ Summary XML/Idiom.pm »