Client.pm

filter: Statementstmt 61.4% 35 / 57 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 9 / 15 Podpod 50.0% 1 / 2 totaltotal 48.3% 45 / 93 CC 9 SCAR 29.6
CC
9
Cov
47%
BUILD
56.0
BUILDARGS
12.0
_build_contacts
2.0
CRAP 19.3
« Folder/Role/Reader.pm ↑ Summary Calendar/Role/RetrieveWithinWindow.pm »
1 package EWS::Client;
2 BEGIN {
3 1 ▶ $EWS::Client::VERSION = '1.143070';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 with qw/
8 EWS::Client::Role::SOAP
9 EWS::Client::Role::GetItem
10 EWS::Client::Role::FindItem
11 EWS::Client::Role::FindFolder
12 EWS::Client::Role::GetFolder
13 EWS::Client::Role::ExpandDL
14 /;
15 1 ▶use EWS::Client::Contacts;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use EWS::Client::Calendar;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use EWS::Client::Folder;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use EWS::Client::DistributionList;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use URI::Escape ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Log::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 has username => (
23 is => 'rw',
24 isa => 'Str',
25 required => 1,
26 );
27  
28 1 has password => (
29 is => 'rw',
30 isa => 'Str',
31 required => 1,
32 );
33  
34 1 has server => (
35 is => 'ro',
36 isa => 'Str',
37 required => 1,
38 );
39  
40 1 has contacts => (
41 is => 'ro',
42 isa => 'EWS::Client::Contacts',
43 lazy_build => 1,
44 );
45  
46 sub _build_contacts {
47 0 ▶ my $self = shift;
Subroutine _build_contacts: not called CC=1 SCAR=6.9
48 0 return EWS::Client::Contacts->new({ client => $self });
49 }
50  
51 1 has calendar => (
52 is => 'ro',
53 isa => 'EWS::Client::Calendar',
54 lazy_build => 1,
55 );
56  
57 sub _build_calendar {
58 0 ▶ my $self = shift;
Subroutine _build_calendar: not called CC=1 SCAR=6.9
59 0 return EWS::Client::Calendar->new({ client => $self });
60 }
61  
62 1 has folders => (
63 is => 'ro',
64 isa => 'EWS::Client::Folder',
65 lazy_build => 1,
66 );
67  
68 sub _build_folders {
69 0 ▶ my $self = shift;
Subroutine _build_folders: not called CC=1 SCAR=6.9
70 0 return EWS::Client::Folder->new({ client => $self });
71 }
72  
73 1 has distribution_list => (
74 is => 'ro',
75 isa => 'EWS::Client::DistributionList',
76 lazy_build => 1,
77 );
78  
79 sub _build_distribution_list {
80 0 ▶ my $self = shift;
Subroutine _build_distribution_list: not called CC=1 SCAR=6.9
81 0 return EWS::Client::DistributionList->new({ client => $self });
82 }
83  
84 sub BUILDARGS {
85 0 ▶ my ($class, @rest) = @_;
Subroutine BUILDARGS: not called CC=3 SCAR=24.8
Pod documented
86 0 ▶ my $params = (scalar @rest == 1 ? $rest[0] : {@rest});
Branch: 1 branch
BranchTrueFalseTotal
scalar @rest == 1 ? : 0 0 0
87  
88 # collect EWS password from environment as last resort
89 0 ▶ $params->{password} ||= $ENV{EWS_PASS};
Condition0%0/3
$params->{"password"} ||= $ENV{"EWS_PASS"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{"password"} ||= $ENV{"EWS_PASS"}
$params->{"password"} $ENV{"EWS_PASS"}
Truth table0%0/3
A ||= B
A= $params->{"password"}B= $ENV{"EWS_PASS"}
ABresult
1X1
011
000
90  
91 0 return $params;
92 }
93  
94 sub BUILD {
95 0 ▶ my ($self, $params) = @_;
Subroutine BUILD: not called CC=7 SCAR=40.3
Pod undocumented
96  
97 0 ▶ if ($self->use_negotiated_auth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_negotiated_auth) { } 0 0 0
98 die "please install LWP::Authen::Ntlm"
99 0 ▶ unless eval { require LWP::Authen::Ntlm && $LWP::Authen::Ntlm::VERSION };
Branch: 2 branches
BranchTrueFalseTotal
unless eval { do { require LWP::Authen::Ntlm and $LWP::Authen::Ntlm::VERSION } } 0 0 0
require LWP::Authen::Ntlm and $LWP::Authen::Ntlm::VERSION 0 0 0
100 die "please install Authen::NTLM"
101 0 ▶ unless eval { require Authen::NTLM && $Authen::NTLM::VERSION };
Branch: 2 branches
BranchTrueFalseTotal
unless eval { do { require Authen::NTLM and $Authen::NTLM::VERSION } } 0 0 0
require Authen::NTLM and $Authen::NTLM::VERSION 0 0 0
102  
103 # change email style username to win-domain style
104 0 ▶ if ($self->username =~ m/(.+)@(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->username =~ /(.+)@(.+)/) 0 0 0
105 0 $self->username( $2 .'\\'. $1 );
106 }
107 }
108 else {
109 # URI escape the username and password
110 0 $self->password( URI::Escape::uri_escape($self->password) );
111 0 $self->username( URI::Escape::uri_escape($self->username) );
112 }
113 }
114  
115 1 __PACKAGE__->meta->make_immutable;
116 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 1 1;
118  
119 # ABSTRACT: Microsoft Exchange Web Services Client
120  
121  
122 __END__
123 =pod
124  
125 =head1 NAME
126  
127 EWS::Client - Microsoft Exchange Web Services Client
128  
129 =head1 VERSION
130  
131 version 1.143070
132  
133 =head1 SYNOPSIS
134  
135 Set up your Exchange Web Services client.
136  
137 use EWS::Client;
138 use DateTime;
139
140 my $ews = EWS::Client->new({
141 server => 'exchangeserver.example.com',
142 username => 'oliver',
143 password => 's3krit', # or set in $ENV{EWS_PASS}
144 });
145  
146 Then perform operations on the Exchange server:
147  
148 my $entries = $ews->calendar->retrieve({
149 start => DateTime->now(),
150 end => DateTime->now->add( months => 1 ),
151 });
152
153 print "I retrieved ". $entries->count ." items\n";
154
155 while ($entries->has_next) {
156 print $entries->next->Subject, "\n";
157 }
158
159 my $contacts = $ews->contacts->retrieve;
160  
161 =head1 DESCRIPTION
162  
163 This module acts as a client to the Microsoft Exchange Web Services API. From
164 here you can access calendar and contact entries in a nicely abstracted
165 fashion. Query results are generally available in an iterator and convenience
166 methods exist to access the properties of each entry.
167  
168 =head1 AUTHENTICATION
169  
170 Depending on the configuration of the Microsoft Exchange server, you can use
171 either HTTP Basic Access Auth, or NTLM Negotiated Auth, from this module. The
172 default is HTTP Basic Access Auth, so if using NTLM, the following additional
173 option to C<new()> is required:
174  
175 use_negotiated_auth => 1,
176  
177 =head1 METHODS
178  
179 =head2 EWS::Client->new( \%arguments )
180  
181 Instantiates a new EWS client. There won't be any connection to the server
182 until you call one of the calendar or contacts retrieval methods.
183  
184 =over 4
185  
186 =item C<server> => Fully Qualified Domain Name (required)
187  
188 The host name of the Exchange server to which the module should connect.
189  
190 =item C<username> => String (required)
191  
192 The account username under which the module will connect to Exchange.
193  
194 For Basic Access Auth this value will be URI encoded by the module, meaning
195 you don't have to worry about escaping any special characters. For NTLM
196 Negotiated Auth, pass a C<user@domain> format username and it will
197 automatically be converted into Windows' C<domain\user> format for you.
198  
199 =item C<password> => String OR via C<$ENV{EWS_PASS}> (required)
200  
201 The password of the account under which the module will connect to Exchange.
202  
203 For Basic Access Auth this value will be URI encoded by the module. You can
204 also provide the password via the C<EWS_PASS> environment variable.
205  
206 =item C<use_negotiated_auth> => True or False value
207  
208 The module will assume you wish to use HTTP Basic Access Auth, in which case
209 you should enable that in your Exchange server. However for negotiated methods
210 such as NTLM set this to a True value.
211  
212 =item C<schema_path> => String (optional)
213  
214 A folder on your file system which contains the WSDL and two further Schema
215 files (messages, and types) which describe the Exchange 2007 Web Services SOAP
216 API. They are shipped with this module so your providing this is optional.
217  
218 =item C<server_version> => String (optional)
219  
220 In each request to the server is specified the API version we expect to use.
221 By default this is set to C<Exchange2007_SP1> but you have the opportunity to
222 set it to C<Exchange2007> if you wish using this option.
223  
224 =back
225  
226 =head2 $ews->calendar()
227  
228 Retrieves the L<EWS::Client::Calendar> object which allows search and
229 retrieval of calendar entries and their various properties. See that linked
230 manual page for more details.
231  
232 =head2 $ews->contacts()
233  
234 Retrieves the L<EWS::Client::Contacts> object which allows retrieval of
235 contact entries and their telephone numbers. See that linked manual page for
236 more details.
237  
238 =head2 $ews->folders()
239  
240 Retrieves the L<EWS::Client::Folder> object which allows retrieval of
241 mailbox folder entries and their sizes. See that linked manual page for
242 more details.
243  
244 =head2 $ews->dls()
245  
246 Retrieves the L<EWS::Client::DistributionList> object which allows retrieval of
247 distribution list entries and their email addresses and names. See that linked
248 manual page for more details.
249  
250 =head1 KNOWN ISSUES
251  
252 =over 4
253  
254 =item * No handling of time zone information, sorry.
255  
256 =item * The C<SOAPAction> Header might be wrong for Exchange 2010.
257  
258 =back
259  
260 =head1 THANKS
261  
262 To Greg Shaw for sending patches for NTLM Authentication support and User
263 Impersonation.
264  
265 =head1 AUTHOR
266  
267 Oliver Gorwits <oliver@cpan.org>
268  
269 =head1 COPYRIGHT AND LICENSE
270  
271 This software is copyright (c) 2014 by University of Oxford.
272  
273 This is free software; you can redistribute it and/or modify it under
274 the same terms as the Perl 5 programming language system itself.
275  
276 =cut
277  
« Folder/Role/Reader.pm ↑ Summary Calendar/Role/RetrieveWithinWindow.pm »