| 1 | package XML::SDEE; | ||||||||||||||
| 2 | # | ||||||||||||||
| 3 | # $Id: SDEE.pm,v 1.1 2004/12/23 12:02:30 jminieri Exp $ | ||||||||||||||
| 4 | # | ||||||||||||||
| 5 | |||||||||||||||
| 6 | 1 | ▶ | use 5.006001; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 1 | ▶ | use XML::Simple; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 1 | our $VERSION = '0.01'; | |||||||||||||
| 13 | |||||||||||||||
| 14 | ################################################################################ | ||||||||||||||
| 15 | # | ||||||||||||||
| 16 | 0 | ▶ | sub sessionId { my $self = shift; return $self->{ _sessionId }; } | ||||||||||||
|
Subroutine
sessionId: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 17 | 0 | ▶ | sub subscriptionId { my $self = shift; return $self->{ _subscriptionId }; } | ||||||||||||
|
Subroutine
subscriptionId: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 18 | # | ||||||||||||||
| 19 | ################################################################################ | ||||||||||||||
| 20 | |||||||||||||||
| 21 | ################################################################################ | ||||||||||||||
| 22 | # | ||||||||||||||
| 23 | # Error reporting methods | ||||||||||||||
| 24 | 0 | ▶ | sub isError{ my $self = shift; return $self->{ _isError };} | ||||||||||||
|
Subroutine
isError: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 25 | 0 | ▶ | sub getError{ my $self = shift; return $self->{ _errorMessage }; } | ||||||||||||
|
Subroutine
getError: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 26 | 0 | ▶ | sub getErrorReason{ | ||||||||||||
|
Subroutine
getErrorReason: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 27 | 0 | my $self = shift; | |||||||||||||
| 28 | |||||||||||||||
| 29 | 0 | ▶ | if(exists($self->{ _errorMessage}{ Reason })) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | return $self->{ _errorMessage}{ Reason } | ||||||||||||||
| 31 | 0 | } else { | |||||||||||||
| 32 | return undef | ||||||||||||||
| 33 | 0 | } | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 0 | ▶ | sub getErrorSubcode{ | ||||||||||||
|
Subroutine
getErrorSubcode: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||
| 38 | |||||||||||||||
| 39 | 0 | ▶ | if(exists($self->{ _errorMessage }{ Subcode })) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 40 | return $self->{ _errorMessage }{ Subcode } | ||||||||||||||
| 41 | 0 | } else { | |||||||||||||
| 42 | return undef | ||||||||||||||
| 43 | 0 | } | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 0 | ▶ | sub getErrorCode{ | ||||||||||||
|
Subroutine
getErrorCode: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||
| 48 | 0 | ▶ | if(exists($self->{ _errorMessage }{ Code })) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | return $self->{ _errorMessage }{ Code } | ||||||||||||||
| 50 | 0 | } else { | |||||||||||||
| 51 | return undef | ||||||||||||||
| 52 | 0 | } | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 0 | ▶ | sub getErrorString { | ||||||||||||
|
Subroutine
getErrorString: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 56 | 0 | my $self = shift; | |||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | return $self->getErrorCode . ':' . $self->getErrorSubcode . ':' . $self->getErrorReason; | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | # | ||||||||||||||
| 61 | ################################################################################ | ||||||||||||||
| 62 | |||||||||||||||
| 63 | ################################################################################ | ||||||||||||||
| 64 | # | ||||||||||||||
| 65 | # Event retrieval methods | ||||||||||||||
| 66 | 0 | ▶ | sub getEvent { my $self = shift; return pop @{ $self->{ _eventList }}; } | ||||||||||||
|
Subroutine
getEvent: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 67 | 0 | ▶ | sub getEvents { my $self = shift; return $self->{ _events }; } | ||||||||||||
|
Subroutine
getEvents: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 68 | # | ||||||||||||||
| 69 | ################################################################################ | ||||||||||||||
| 70 | |||||||||||||||
| 71 | ################################################################################ | ||||||||||||||
| 72 | # | ||||||||||||||
| 73 | # XML retrieval methods | ||||||||||||||
| 74 | 0 | ▶ | sub XML { my $self = shift; return $self->{ _raw_xml }; } | ||||||||||||
|
Subroutine
XML: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 75 | 0 | ▶ | sub SDEE { my $self = shift; return $self->{ SDEE }; } | ||||||||||||
|
Subroutine
SDEE: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 76 | # | ||||||||||||||
| 77 | ################################################################################ | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 0 | ▶ | sub reset { | ||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||
| 81 | |||||||||||||||
| 82 | 0 | $self->{ _raw_xml } = undef; | |||||||||||||
| 83 | 0 | $self->{ SDEE } = undef; | |||||||||||||
| 84 | 0 | $self->{ _sessionId } = undef; | |||||||||||||
| 85 | 0 | $self->{ _subscriptionId } = undef; | |||||||||||||
| 86 | 0 | $self->{ _isError } = undef; | |||||||||||||
| 87 | 0 | $self->{ _errorMessage } = {}; | |||||||||||||
| 88 | 0 | @{$self->{ _eventsList }} = (); | |||||||||||||
| 89 | 0 | $self->{ _events } = undef; | |||||||||||||
| 90 | |||||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | # | ||||||||||||||
| 94 | # document processor | ||||||||||||||
| 95 | 0 | ▶ | sub consume { | ||||||||||||
|
Subroutine
consume: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||
| 96 | 0 | my ($self, $raw_xml) = @_; | |||||||||||||
| 97 | |||||||||||||||
| 98 | 0 | ▶ | unless(defined($raw_xml)) { return undef; } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 99 | |||||||||||||||
| 100 | 0 | $self->reset; | |||||||||||||
| 101 | |||||||||||||||
| 102 | 0 | $self->{ _raw_xml } = $raw_xml; | |||||||||||||
| 103 | 0 | $self->{ SDEE } = XMLin($raw_xml); | |||||||||||||
| 104 | |||||||||||||||
| 105 | 0 | ▶ | if (exists($self->{ SDEE }->{ 'env:Header' }->{ 'sd:oobInfo' }->{ 'sd:sessionId' } )) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 106 | 0 | ▶ | $self->{ _sessionId } = ($self->{ SDEE }->{ 'env:Header' }->{ 'sd:oobInfo' }->{ 'sd:sessionId' } or undef); | ||||||||||||
|
Condition0%0/2
$self->{'SDEE'}{'env:Header'}{'sd:oobInfo'}{'sd:sessionId'} || undef
MC/DC0%0/1
$self->{'SDEE'}{'env:Header'}{'sd:oobInfo'}{'sd:sessionId'} || undef
$self->{'SDEE'}{'env:Header'}{'sd:oobInfo'}{'sd:sessionId'}
Truth table0%0/2
A
A= $self->{'SDEE'}{'env:Header'}{'sd:oobInfo'}{'sd:sessionId'}
| |||||||||||||||
| 107 | } | ||||||||||||||
| 108 | |||||||||||||||
| 109 | 0 | ▶ | if(exists($self->{ SDEE }->{ 'env:Body' }->{ 'sd:subscriptionId' })) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 110 | 0 | $self->{ _subscriptionId } = $self->{ SDEE }->{ 'env:Body' }->{ 'sd:subscriptionId' }; | |||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | # | ||||||||||||||
| 114 | # SDEE is made to process a bunch of types of events. 'evIdsAlert' is just one | ||||||||||||||
| 115 | # I should probably store the events in a hash with the event type as a key | ||||||||||||||
| 116 | # | ||||||||||||||
| 117 | 0 | ▶ | if(exists($self->{ SDEE }->{ 'env:Body' }->{ 'sd:events' })) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 118 | 0 | $self->{ _events } = $self->{ SDEE }->{ 'env:Body' }->{ 'sd:events' }; | |||||||||||||
| 119 | |||||||||||||||
| 120 | 0 | my $events_ref = $self->{ SDEE }->{ 'env:Body' }->{ 'sd:events' }; | |||||||||||||
| 121 | 0 | foreach my $event_type (keys %$events_ref) { | |||||||||||||
| 122 | 0 | my $events = $events_ref->{ $event_type }; | |||||||||||||
| 123 | 0 | ▶ | if(ref($events) eq 'ARRAY') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 124 | 0 | foreach my $event (@$events) { | |||||||||||||
| 125 | 0 | $event->{ eventType } = $event_type; | |||||||||||||
| 126 | 0 | push( @{ $self->{ _eventList }}, $event); | |||||||||||||
| 127 | } | ||||||||||||||
| 128 | } elsif (ref($events) eq 'HASH') { | ||||||||||||||
| 129 | 0 | $events->{ eventType } = $event_type; | |||||||||||||
| 130 | 0 | push( @{ $self->{ _eventList }}, $events); | |||||||||||||
| 131 | } | ||||||||||||||
| 132 | } | ||||||||||||||
| 133 | } | ||||||||||||||
| 134 | |||||||||||||||
| 135 | 0 | ▶ | if(exists($self->{ SDEE }->{ 'env:Body' }->{ 'env:Fault' })) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 136 | $self->{ _errorMessage }{ Code } = | ||||||||||||||
| 137 | 0 | ($self->{ SDEE }->{ 'env:Body' }->{ 'env:Fault' }->{ 'env:Code' }->{ 'env:Value' } =~ /^env:(.+)$/)[0]; | |||||||||||||
| 138 | $self->{ _errorMessage }{ Subcode } = | ||||||||||||||
| 139 | 0 | ($self->{ SDEE }->{ 'env:Body' }->{ 'env:Fault' }->{ 'env:Code' }->{ 'env:Subcode' }->{ 'env:Value' } =~ /^sd:(.+)$/)[0]; | |||||||||||||
| 140 | $self->{ _errorMessage }{ Reason } = | ||||||||||||||
| 141 | 0 | $self->{ SDEE }->{ 'env:Body' }->{ 'env:Fault' }->{ 'env:Reason' }; | |||||||||||||
| 142 | 0 | $self->{ _isError }=1; | |||||||||||||
| 143 | } | ||||||||||||||
| 144 | |||||||||||||||
| 145 | 0 | return 1; | |||||||||||||
| 146 | |||||||||||||||
| 147 | } | ||||||||||||||
| 148 | |||||||||||||||
| 149 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 150 | 0 | my ($class, $document) = @_; | |||||||||||||
| 151 | |||||||||||||||
| 152 | 0 | my $self = {}; | |||||||||||||
| 153 | |||||||||||||||
| 154 | 0 | bless( $self, $class ); | |||||||||||||
| 155 | 0 | ▶ | if(defined($document)) { $self->consume($document) } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 156 | |||||||||||||||
| 157 | 0 | return $self; | |||||||||||||
| 158 | } | ||||||||||||||
| 159 | |||||||||||||||
| 160 | 1 | 1; | |||||||||||||
| 161 | |||||||||||||||