| 1 | package WWW::Correios::SIGEP::Common; | ||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use XML::Compile::WSDL11; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 2 | ▶ | use XML::Compile::SOAP11; # <-- loads the soap namespace | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 2 | ▶ | use XML::Compile::Transport::SOAPHTTP; # <-- sends messages over HTTP | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 2 | ▶ | use LWP::UserAgent; # <-- see "Note" on build_transport(); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 2 | ▶ | use File::ShareDir; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | sub call { | ||||||||||||||
| 11 | 0 | ▶ | my ($self, $operation, $params) = @_; | ||||||||||||
|
Subroutine
call: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 12 | 0 | my $call = compiled_client($self, $operation); | |||||||||||||
| 13 | 0 | return process_return($self, $operation, $call->($params)); | |||||||||||||
| 14 | } | ||||||||||||||
| 15 | |||||||||||||||
| 16 | sub process_return { | ||||||||||||||
| 17 | 0 | ▶ | my ($self, $operation, $return, $trace) = @_; | ||||||||||||
|
Subroutine
process_return: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 18 | |||||||||||||||
| 19 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 20 | 0 | $trace->printErrors; | |||||||||||||
| 21 | 0 | $trace->printRequest; | |||||||||||||
| 22 | 0 | $trace->printResponse; | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | 0 | ▶ | if (exists $return->{parameters}{return}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 25 | 0 | return $return->{parameters}{return}; | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | elsif (exists $return->{parameters}{$operation}) { | ||||||||||||||
| 28 | 0 | ▶ | if (exists $return->{parameters}{$operation}{resultado_solicitacao}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 29 | 0 | return $return->{parameters}{$operation}{resultado_solicitacao}; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | else { | ||||||||||||||
| 32 | 0 | return $return->{parameters}{$operation}; | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | } | ||||||||||||||
| 35 | else { | ||||||||||||||
| 36 | 0 | return $return; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | sub compiled_client { | ||||||||||||||
| 41 | 0 | ▶ | my ($self, $operation) = @_; | ||||||||||||
|
Subroutine
compiled_client: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 42 | |||||||||||||||
| 43 | 0 | my $key = '_compiled' . $operation; | |||||||||||||
| 44 | 0 | ▶ | if (!$self->{$key}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | $self->{$key} = $self->{wsdl}->compileClient( | ||||||||||||||
| 46 | operation => $operation, | ||||||||||||||
| 47 | transport => $self->{transport}, | ||||||||||||||
| 48 | 0 | ); | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | 0 | return $self->{$key}; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | # FIXME: (fixed in XML::Compile::SOAP 3.07) | ||||||||||||||
| 54 | # Use of uninitialized value $ns in hash element at XML/Compile/Cache.pm line 125. | ||||||||||||||
| 55 | # Use of uninitialized value $ns in hash element at XML/Compile/Cache.pm line 134. | ||||||||||||||
| 56 | # Use of uninitialized value $ns in concatenation (.) or string at XML/Compile/Cache.pm line 135. | ||||||||||||||
| 57 | # Use of uninitialized value in string eq at XML/Compile/Cache.pm line 166. | ||||||||||||||
| 58 | # Use of uninitialized value $ns in string eq at XML/Compile/Cache.pm line 166. | ||||||||||||||
| 59 | sub build_transport { | ||||||||||||||
| 60 | 5 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
build_transport: called CC=5 SCAR=18.3
Pod
undocumented
| |||||||||||||||
| 61 | |||||||||||||||
| 62 | my $local_file = File::ShareDir::dist_file( | ||||||||||||||
| 63 | 'WWW-Correios-SIGEP', | ||||||||||||||
| 64 | $self->{wsdl_local_file} | ||||||||||||||
| 65 | 5 | ); | |||||||||||||
| 66 | 5 | $self->{wsdl} = XML::Compile::WSDL11->new( $local_file ); | |||||||||||||
| 67 | |||||||||||||||
| 68 | ############################################################ | ||||||||||||||
| 69 | ### Note: | ||||||||||||||
| 70 | ### ----- | ||||||||||||||
| 71 | ### Of course Correios does *NOT* have a valid certificate, | ||||||||||||||
| 72 | ### Otherwise we'd be able to skip all this and just do: | ||||||||||||||
| 73 | ### | ||||||||||||||
| 74 | ### my $call = $wsdl->compileClient( 'method' ); | ||||||||||||||
| 75 | ### | ||||||||||||||
| 76 | ### but if we do that we get: | ||||||||||||||
| 77 | ### "Can't connect to apphom.correios.com.br:443 (certificate verify failed)" | ||||||||||||||
| 78 | ### | ||||||||||||||
| 79 | ### which is why we need to customize our transport here :( | ||||||||||||||
| 80 | 5 | ▶ | my @timeout = $self->{timeout} ? (timeout => $self->{timeout}) : (); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 81 | 5 | my $ua = LWP::UserAgent->new( | |||||||||||||
| 82 | @timeout, | ||||||||||||||
| 83 | ssl_opts => { verify_hostname => 0 }, | ||||||||||||||
| 84 | # $self->{usuario}, $self->{senha} | ||||||||||||||
| 85 | ); | ||||||||||||||
| 86 | 5 | ▶ | $ua->credentials( @{$self->{ua_auth}} ) if exists $self->{ua_auth}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 87 | |||||||||||||||
| 88 | $self->{transport} = XML::Compile::Transport::SOAPHTTP->new( | ||||||||||||||
| 89 | address => $self->{wsdl}->endPoint, | ||||||||||||||
| 90 | 5 | @timeout, | |||||||||||||
| 91 | user_agent => $ua | ||||||||||||||
| 92 | )->compileClient(); | ||||||||||||||
| 93 | |||||||||||||||
| 94 | 5 | ▶ | if ($self->{precompile}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 95 | 0 | foreach my $operation (@{$self->{precompile}}) { | |||||||||||||
| 96 | 0 | compiled_client($self, $operation); | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | } | ||||||||||||||
| 99 | 5 | return $self; | |||||||||||||
| 100 | } | ||||||||||||||
| 101 | |||||||||||||||
| 102 | 2 | 42; | |||||||||||||