File Coverage

blib/lib/EWS/Client/Role/SOAP.pm
Criterion Covered Total %
statement 5 7 71.4
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 8 10 80.0


line stmt bran cond sub pod time code
1             package EWS::Client::Role::SOAP;
2             BEGIN {
3 1     1   849 $EWS::Client::Role::SOAP::VERSION = '1.143070';
4             }
5 1     1   6 use Moose::Role;
  1         2  
  1         10  
6              
7 1     1   6546 use XML::Compile::WSDL11;
  0            
  0            
8             use XML::Compile::SOAP11;
9             use XML::Compile::Transport::SOAPHTTP;
10             use File::ShareDir ();
11              
12             has server_version => (
13             is => 'ro',
14             isa => 'Str',
15             default => 'Exchange2007_SP1',
16             required => 0,
17             );
18              
19             has use_negotiated_auth => (
20             is => 'ro',
21             isa => 'Any',
22             default => 0,
23             required => 0,
24             );
25              
26             has transporter => (
27             is => 'ro',
28             isa => 'XML::Compile::Transport::SOAPHTTP',
29             lazy_build => 1,
30             );
31              
32             sub _build_transporter {
33             my $self = shift;
34             my $addr = $self->server . '/EWS/Exchange.asmx';
35              
36             if (not $self->use_negotiated_auth) {
37             $addr = sprintf '%s:%s@%s',
38             $self->username, $self->password, $addr;
39             }
40              
41             my $t = XML::Compile::Transport::SOAPHTTP->new(
42             address => 'https://'. $addr);
43            
44             if ($self->use_negotiated_auth) {
45             $t->userAgent->credentials($self->server.':443', '',
46             $self->username, $self->password);
47             }
48              
49             # XXX disable all security checks
50             $t->userAgent->ssl_opts( verify_hostname => 0, SSL_verify_mode => 0x00 );
51              
52             return $t;
53             }
54              
55             has wsdl => (
56             is => 'ro',
57             isa => 'XML::Compile::WSDL11',
58             lazy_build => 1,
59             );
60              
61             sub _build_wsdl {
62             my $self = shift;
63              
64             XML::Compile->addSchemaDirs( $self->schema_path );
65             my $wsdl = XML::Compile::WSDL11->new('ews-services.wsdl');
66             $wsdl->importDefinitions('ews-types.xsd');
67             $wsdl->importDefinitions('ews-messages.xsd');
68              
69             # skip the t:Culture element in the ResolveNames response
70             # it breaks the XML Parser for some reason
71             $wsdl->addHook(path => "{http://schemas.microsoft.com/exchange/services/2006/messages}ResolveNamesResponse/ResponseMessages/ResolveNamesResponseMessage/ResolutionSet/Resolution/Contact",
72             before => sub {
73             my ($xml, $path) = @_;
74             my @nodes = $xml->childNodes();
75             foreach my $node (@nodes) {
76             if($node->nodeName eq 't:Culture'){
77             $xml->removeChild($node);
78             }
79             }
80             return $xml;
81             });
82              
83             return $wsdl;
84             }
85              
86             has schema_path => (
87             is => 'ro',
88             isa => 'Str',
89             lazy_build => 1,
90             );
91              
92             sub _build_schema_path {
93             my $self = shift;
94             return File::ShareDir::dist_dir('EWS-Client');
95             }
96              
97             no Moose::Role;
98             1;
99