MRS.pm

filter: Statementstmt 25.5% 24 / 94 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 6 / 15 Podpod 83.3% 5 / 6 totaltotal 24.8% 35 / 141 CC 14 SCAR 42.3
CC
14
Cov
20%
MSISDNResolve
156.0
new
12.0
envelope
2.0
CRAP 68.9
↑ Summary demo.pl »
1 package promessaging::MRS;
2  
3 1 ▶use SOAP::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 require Exporter;
12  
13 1 our @ISA = qw(Exporter);
14  
15 # Items to export into callers namespace by default. Note: do not export
16 # names by default without a very good reason. Use EXPORT_OK instead.
17 # Do not simply export all your public functions/methods/constants.
18  
19 # This allows declaration use promessaging::MRS ':all';
20 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
21 # will save memory.
22 1 our %EXPORT_TAGS = ( 'all' => [ qw(
23 envelope get_xml MSISDNResolve getError get_xml_request get_xml_response MRSinfo
24 ) ] );
25  
26 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
27  
28 1 our @EXPORT = qw(
29 envelope get_xml MSISDNResolve getError get_xml_request get_xml_response MRSinfo
30 );
31  
32 1 our $VERSION = '1.01';
33  
34  
35 # location of the WSDL-description of the SOAP-service
36 1 my $wsdl = "http://www.promessaging.net/End2EndMRS.wsdl";
37  
38  
39 # serializer class
40 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 package My::Serializer;
43 1 @My::Serializer::ISA = 'SOAP::Serializer';
44  
45 0 ▶ sub envelope {
Subroutine envelope: not called CC=1 SCAR=6.9
46 0 my $self = shift;
47  
48 0 $self->{'xml_request'} = $self->SUPER::envelope(@_);
49 0 return ( $self->{'xml_request'} );
50 }
51  
52 0 ▶ sub get_xml {
Subroutine get_xml: not called CC=1 SCAR=6.9
53 0 my $self = shift;
54  
55 0 return ( $self->{'xml_request'} );
56 }
57 }
58  
59 # constructor, no parameters needed
60 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
61 0 my $class = shift;
62 0 my $self = {};
63  
64 0 $self->{'error'} = "";
65 0 $self->{'xml_response'} = "";
66 0 eval {
67 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"soapservice"} = "SOAP::Lite"->new->service($wsdl)->outputxml("true")->on_fault(sub { return; } )) 0 0 0
68 !(
69 $self->{'soapservice'} =
70 new SOAP::Lite->service($wsdl)->outputxml('true')
71 0 ▶ ->on_fault( sub { return; } )
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 )
73 )
74 {
75 0 return (0);
76 }
77 0 $self->{'soapservice'}->serializer( My::Serializer->new );
78 };
79 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
80 0 return(0);
81 }
82  
83 0 bless $self, $class;
84 }
85  
86 0 ▶sub MSISDNResolve {
Subroutine MSISDNResolve: not called CC=12 SCAR=50.5
Pod documented
87 0 my $self = shift;
88  
89 # my ( $msisdn, $userid, $password, $serviceprofile, $max_retries,
90 # $interval_timeout, $interval_na ) = @_;
91  
92 0 my ($userid, $password, $serviceprofile, $msisdn, $max_retries, $interval_timeout, $interval_na) = @_;
93  
94  
95 0 my $soapservice = $self->{'soapservice'};
96 0 $self->{'error'} = "";
97  
98 0 my $retry = 0;
99 0 my $result;
100 my $interval;
101  
102 0 ▶ if ( !defined( $max_retries ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $max_retries) 0 0 0
103 0 $max_retries = 0;
104 }
105 0 ▶ if ( !defined( $interval_timeout ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $interval_timeout) 0 0 0
106 # default: 0 seconds because immediately retry is allowed
107 0 $interval_timeout = 0;
108 }
109 0 ▶ if ( !defined( $interval_na ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $interval_na) 0 0 0
110 # default: 300 seconds (5 minutes)
111 0 $interval_na = 300;
112 }
113  
114 0 ▶ while ( $retry <= $max_retries ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retry <= $max_retries) 0 0 0
115 0 ▶ if ( $retry > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retry > 0) 0 0 0
116 0 sleep $interval;
117 }
118  
119 0 my $answer;
120
121 0 eval {
122 0 $answer = $self->{'soapservice'}->MSISDNResolve( $userid,
123 $password,
124 $serviceprofile,
125 $msisdn );
126
127 0 ▶ if ( substr( $answer, 0, 5 ) eq "<?xml" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($answer, 0, 5) eq '<?xml') { } 0 0 0
128 0 $self->{'xml_response'} = $answer;
129 0 my $xs = new XML::Simple( suppressempty => "" );
130 0 my $parsed = $xs->XMLin($answer);
131 0 my $xmlbody = $parsed->{'SOAP-ENV:Body'};
132
133 0 ▶ if ( defined( $xmlbody->{'SOAP-ENV:Fault'} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $xmlbody->{'SOAP-ENV:Fault'}) { } 0 0 0
elsif (defined $xmlbody->{'SOAP-ENV:MSISDNResolveResponse'}) { } 0 0 0
134 0 my $fault = $xmlbody->{'SOAP-ENV:Fault'};
135 0 my $faultcode = $fault->{'faultcode'};
136 0 $result = $fault;
137
138 0 ▶ if ( $faultcode == 91 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($faultcode == 91) { } 0 0 0
elsif ($faultcode == 99) { } 0 0 0
139 0 $interval = $interval_timeout;
140 }
141 elsif ( $faultcode == 99 ) {
142 0 $interval = $interval_na;
143 }
144 else {
145 0 last;
146 }
147
148 }
149 elsif ( defined( $xmlbody->{'SOAP-ENV:MSISDNResolveResponse'} ) ) {
150 $result->{"response"} =
151 0 $xmlbody->{'SOAP-ENV:MSISDNResolveResponse'};
152 0 last;
153 }
154 else {
155 0 $self->{'error'} = "no Fault or MSISDNResolveResponse in XML";
156 0 $interval = $interval_na;
157 0 $result = -1;
158 }
159 }
160 else {
161 0 chomp $answer;
162 0 $self->{'error'} = $answer;
163 0 $interval = $interval_na;
164 0 $result = -2;
165 }
166 };
167 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
168 0 $self->{'error'} = $@;
169 0 $interval = $interval_na;
170 0 $result = -3;
171 }
172
173 0 $retry++;
174 }
175  
176 0 return ($result);
177 }
178  
179 0 ▶sub getError {
Subroutine getError: not called CC=1 SCAR=6.9
Pod documented
180 0 my $self = shift;
181  
182 0 return ( $self->{'error'} );
183 }
184  
185 0 ▶sub get_xml_request {
Subroutine get_xml_request: not called CC=1 SCAR=6.9
Pod documented
186 0 my $self = shift;
187  
188 0 return ( $self->{'soapservice'}->serializer->get_xml );
189 }
190  
191 0 ▶sub get_xml_response {
Subroutine get_xml_response: not called CC=1 SCAR=6.9
Pod documented
192 0 my $self = shift;
193  
194 0 return ( $self->{'xml_response'} );
195 }
196  
197 # just to show basic functionality
198 0 ▶sub MRSinfo {
Subroutine MRSinfo: not called CC=1 SCAR=6.9
Pod undocumented
199  
200 0 print "\nThis shows that you installed MRS.pm succesfully!\n";
201  
202 }
203  
204 # Preloaded methods go here.
205  
206 1 1;
207 __END__
↑ Summary demo.pl »