AvaTax/Role/Service.pm

filter: Statementstmt 64.2% 45 / 70 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 12 / 16 Podpod n/a totaltotal 63.3% 57 / 90 CC 3 SCAR 11.0
CC
3
Cov
61%
_build_clients
12.0
__ANON__
2.0
_build__transport
2.0
CRAP 3.0
« AvaTax/Service/Address.pm ↑ Summary AvaTax/Service/Tax.pm »
1 package WebService::Avalara::AvaTax::Role::Service;
2  
3 # ABSTRACT: Common attributes and methods for AvaTax services
4  
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 our $VERSION = '0.020'; # VERSION
9 9 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 #pod =head1 SYNOPSIS
12 #pod
13 #pod use Moo;
14 #pod with 'WebService::Avalara::AvaTax::Role::Service';
15 #pod
16 #pod =head1 DESCRIPTION
17 #pod
18 #pod This role factors out the common attributes and methods used by the
19 #pod Avalara AvaTax (C<http://developer.avalara.com/api-docs/soap>)
20 #pod web service interface.
21 #pod
22 #pod =cut
23  
24 9 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 9 ▶use Types::Standard qw(Bool CodeRef HashRef InstanceOf Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 9 ▶use Types::URI 'Uri';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 9 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 9 ▶use XML::Compile::SOAP::WSS;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 9 ▶use XML::Compile::Transport::SOAPHTTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 9 ▶use XML::Compile::WSDL11;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 9 ▶use XML::Compile::WSS;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 9 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 #pod =attr uri
35 #pod
36 #pod The L<URI|URI> of the WSDL file used to define the web service.
37 #pod Consumer classes are expected to set this attribute.
38 #pod As a convenience this can also be set with anything that
39 #pod L<Types::URI|Types::URI> can coerce into a C<Uri>.
40 #pod
41 #pod =cut
42  
43 9 has uri => ( is => 'lazy', isa => Uri, coerce => 1 );
44  
45 #pod =attr port
46 #pod
47 #pod The SOAP port identifier (not to be confused with the TCP/IP port) used in the
48 #pod WSDL file at L</uri>.
49 #pod Consumer classes are expected to set this attribute.
50 #pod
51 #pod =cut
52  
53 9 has port => ( is => 'lazy', isa => Str );
54  
55 #pod =attr service
56 #pod
57 #pod The SOAP service name used in the WSDL file at L</uri>.
58 #pod Consumer classes are expected to set this attribute.
59 #pod
60 #pod =cut
61  
62 9 has service => ( is => 'ro', isa => Str );
63  
64 #pod =attr wsdl
65 #pod
66 #pod After construction, you can retrieve the created
67 #pod L<XML::Compile::WSDL11|XML::Compile::WSDL11> instance.
68 #pod
69 #pod Example:
70 #pod
71 #pod my $wsdl = $avatax->wsdl;
72 #pod my @soap_operations = map { $_->name } $wsdl->operations;
73 #pod
74 #pod =cut
75  
76 has wsdl => (
77 is => 'lazy',
78 isa => InstanceOf ['XML::Compile::WSDL11'],
79 init_arg => undef,
80 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 0 XML::Compile::WSDL11->new(
82 $_[0]->user_agent->get( $_[0]->uri )->content );
83 },
84 9 );
85  
86 9 has clients => (
87 is => 'lazy',
88 isa => HashRef [CodeRef],
89 init_arg => undef,
90 );
91  
92 0 ▶sub _build_clients {
Subroutine _build_clients: not called CC=3 SCAR=24.8
93 0 my $self = shift;
94  
95 0 my ( $wss, $auth );
96 0 ▶ if ( $self->use_wss ) { $wss = XML::Compile::SOAP::WSS->new }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_wss) 0 0 0
97 0 my $wsdl = $self->wsdl;
98 0 ▶ if ( $self->use_wss ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_wss) 0 0 0
99 0 $auth = $wss->basicAuth( map { ( $_ => $self->$_ ) }
100 qw(username password) );
101 }
102  
103 0 my %soap_params = map { ( $_ => $self->$_ ) } qw(port service);
104 0 my %client_params = (
105 transporter => $self->_transport->compileClient,
106 %soap_params,
107 );
108 return {
109 0 map { ( $_ => $wsdl->compileClient( $_, %client_params ) ) }
110 0 map { $_->name } $wsdl->operations(%soap_params),
111 };
112 }
113  
114 9 has _current_operation_name => ( is => 'rw', isa => Str, default => q{} );
115  
116 9 has _transport =>
117 ( is => 'lazy', isa => InstanceOf ['XML::Compile::Transport'] );
118  
119 0 ▶sub _build__transport {
Subroutine _build__transport: not called CC=1 SCAR=6.9
120 0 my $self = shift;
121  
122 0 my %soap_params = map { ( $_ => $self->$_ ) } qw(port service);
123 0 my $wsdl = $self->wsdl;
124 0 my $endpoint_uri = URI->new( $wsdl->endPoint(%soap_params) );
125 0 my $user_agent = $self->user_agent;
126  
127 $user_agent->add_handler(
128 0 ▶ request_prepare => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
129 0 $_[0]->header(
130 SOAPAction =>
131 $wsdl->operation( $self->_current_operation_name,
132 %soap_params )->soapAction,
133 );
134 },
135 ( m_method => 'POST',
136 0 map { ( "m_$_" => $endpoint_uri->$_ ) } qw(scheme host_port path),
137 ),
138 );
139  
140 0 return XML::Compile::Transport::SOAPHTTP->new(
141 address => $endpoint_uri,
142 user_agent => $user_agent,
143 );
144 }
145  
146 9 1;
147  
148 __END__
« AvaTax/Service/Address.pm ↑ Summary AvaTax/Service/Tax.pm »