| 1 | # Net::SDEE::Common.pm | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # $Id: Common.pm,v 1.1 2004/12/23 12:02:30 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::SDEE::Common; | ||||||||||||||||||||||||||||
| 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 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||||
| 18 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||||
| 19 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | my %_eventTypes = ( | |||||||||||||||||||||||||||
| 24 | 'evIdsError', 1, | ||||||||||||||||||||||||||||
| 25 | 'evIdsAlert', 1, | ||||||||||||||||||||||||||||
| 26 | 'evIdsStatus', 1, | ||||||||||||||||||||||||||||
| 27 | 'evIdsLogTransaction', 1, | ||||||||||||||||||||||||||||
| 28 | 'evIdsShunRqst', 1 | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | my %_idsAlertSeverities = ( | |||||||||||||||||||||||||||
| 32 | 'informational', 1, | ||||||||||||||||||||||||||||
| 33 | 'low', 1, | ||||||||||||||||||||||||||||
| 34 | 'medium', 1, | ||||||||||||||||||||||||||||
| 35 | 'high', 1 | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 1 | my %_errorSeverities = ( | |||||||||||||||||||||||||||
| 39 | 'warning', 1, | ||||||||||||||||||||||||||||
| 40 | 'error', 1, | ||||||||||||||||||||||||||||
| 41 | 'fatal', 1 | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | ########################################################################################## | ||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||
| 46 | # AUTOLOAD get/set methods when they're generic | ||||||||||||||||||||||||||||
| 47 | # | ||||||||||||||||||||||||||||
| 48 | 1 | ▶ | use vars '$AUTOLOAD'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=4 SCAR=27.3
| |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | my $method =($AUTOLOAD =~ /.*::([_\w]+)$/)[0]; | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | return if $method eq 'DESTROY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | unless(defined($method) and exists($self->{ $method })) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $method and exists $self->{$method}
MC/DC0%0/2
defined $method and exists $self->{$method}
defined $method
exists $self->{$method}
Truth table0%0/3
A and B
A= defined $methodB= exists $self->{$method}
| |||||||||||||||||||||||||||||
| 57 | 0 | $self->error(1); | |||||||||||||||||||||||||||
| 58 | 0 | $self->errorString("No such parameter $method"); | |||||||||||||||||||||||||||
| 59 | 0 | return undef; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # set this up for next time | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | *{$AUTOLOAD} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 64 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | if (defined($value)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | return $self->{ $method } = $value; | |||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return defined($self->{ $method })?$self->{ $method }:undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 0 | }; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | goto &$AUTOLOAD; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | ########################################################################################## | ||||||||||||||||||||||||||||
| 76 | # | ||||||||||||||||||||||||||||
| 77 | # Non-generic get/set methods | ||||||||||||||||||||||||||||
| 78 | # | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub errorSeverities { | ||||||||||||||||||||||||||
|
Subroutine
errorSeverities: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 0 | my ($self, $error) = @_; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | $self->error(undef); | |||||||||||||||||||||||||||
| 83 | 0 | $self->errorString(undef); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | unless(defined($error)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | # if no parameter, the treat as "get" method | ||||||||||||||||||||||||||||
| 87 | 0 | return $self->{ 'errorSeverities' }; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | $error = lc($error); | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | if(exists($_errorSeverities{ $error })) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | return $self->{ 'errorSeverities' } = $error | |||||||||||||||||||||||||||
| 93 | } else { | ||||||||||||||||||||||||||||
| 94 | 0 | $self->error(1); | |||||||||||||||||||||||||||
| 95 | 0 | $self->errorString("Invalid error severity: $error"); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | return undef; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub idsAlertSeverities { | ||||||||||||||||||||||||||
|
Subroutine
idsAlertSeverities: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | $self->error(undef); | |||||||||||||||||||||||||||
| 105 | 0 | $self->errorString(undef); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | unless(defined($_[0])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | # if no parameter, the treat as "get" method | ||||||||||||||||||||||||||||
| 109 | 0 | return $self->{ 'idsAlertSeverities' }; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my @alertseverities; | |||||||||||||||||||||||||||
| 113 | 0 | foreach my $s ( @_ ) { | |||||||||||||||||||||||||||
| 114 | 0 | my $severity = lc($s); | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | if(exists($_idsAlertSeverities{ $severity })) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | push(@alertseverities, $severity); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if($#alertseverities > -1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | return $self->{ 'idsAlertSeverities' } = join('+', @alertseverities); | |||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||
| 123 | 0 | $self->error(1); | |||||||||||||||||||||||||||
| 124 | 0 | $self->errorString("No valid alert severities: " . join(',', @_)); | |||||||||||||||||||||||||||
| 125 | 0 | return undef; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub events { | ||||||||||||||||||||||||||
|
Subroutine
events: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 130 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | unless(defined($_[0])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | # if no parameter, the treat as "get" method | ||||||||||||||||||||||||||||
| 134 | 0 | return $self->{ 'events' }; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | $self->error(undef); | |||||||||||||||||||||||||||
| 138 | 0 | $self->errorString(undef); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | my @eventList; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | my %dedup; | ||||||||||||||||||||||||||||
| 143 | 0 | foreach my $eventtype ( grep( !$dedup{ $_ }++, @_ ) ) { | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | if(exists($_eventTypes{ $eventtype })) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | push(@eventList, $eventtype); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if($#eventList > -1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 0 | return $self->{ 'events' } = join('+', @eventList); | |||||||||||||||||||||||||||
| 151 | } else { | ||||||||||||||||||||||||||||
| 152 | 0 | $self->error(1); | |||||||||||||||||||||||||||
| 153 | 0 | $self->errorString("No valid event types: " . join(',', @_)); | |||||||||||||||||||||||||||
| 154 | 0 | return undef; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # | ||||||||||||||||||||||||||||
| 159 | ########################################################################################## | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | ########################################################################################## | ||||||||||||||||||||||||||||
| 162 | # | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub getParameters { | ||||||||||||||||||||||||||
|
Subroutine
getParameters: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 164 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | my %parameters; | |||||||||||||||||||||||||||
| 167 | my @wanted_parameters; | ||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if($#_ > -1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | # requesting particular parameters | ||||||||||||||||||||||||||||
| 170 | 0 | @wanted_parameters = @_; | |||||||||||||||||||||||||||
| 171 | } else { | ||||||||||||||||||||||||||||
| 172 | # requesting ALL parameters | ||||||||||||||||||||||||||||
| 173 | 0 | @wanted_parameters = keys %$self; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | %parameters = map { $_, $self->{ $_ }} grep { $self->{ $_ } } @wanted_parameters; | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | return \%parameters; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | ▶ | sub printAttributes { | ||||||||||||||||||||||||||
|
Subroutine
printAttributes: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 182 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | ▶ | my %parameters = map { $_, ($self->{ $_ } or 'undef') } keys %$self; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{$_} || 'undef'
MC/DC0%0/1
$self->{$_} || 'undef'
$self->{$_}
Truth table0%0/2
A
A= $self->{$_}
| |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | foreach my $attr (sort keys %parameters) { | |||||||||||||||||||||||||||
| 187 | 0 | print "ATTRIBUTE: $attr\tVALUE: $parameters{ $attr }\n"; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | # | ||||||||||||||||||||||||||||
| 192 | ########################################################################################## | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 1 | 1; | |||||||||||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||||||||||