Folder/Role/Reader.pm

filter: Statementstmt 28.8% 17 / 59 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 54.5% 6 / 11 Podpod 0.0% 0 / 1 totaltotal 21.7% 23 / 106 SCAR 54.7
CC
20
Cov
18%
_list_folderitems
56.0
retrieve
56.0
_check_for_errors
20.0
CRAP 238.3
↑ Summary Contacts/Item.pm »
1 package EWS::Folder::Role::Reader;
2 BEGIN {
3 1 ▶ $EWS::Folder::Role::Reader::VERSION = '1.143070';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5  
6 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use EWS::Folder::ResultSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub _list_messages {
12 0 ▶ my ($self, $kind, $response) = @_;
Subroutine _list_messages: not called CC=2 SCAR=17.9
13 0 ▶ if ( $response->{Fault} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{'Fault'}) { } 0 0 0
14 0 my $msg;
15 0 $msg->{"${kind}ResponseMessage"}->{ResponseCode} = $response->{Fault}->{faultstring};
16 0 return $msg;
17 }
18 else {
19 0 return @{ $response->{"${kind}Result"}
20 ->{ResponseMessages}
21 0 ->{"cho_CreateItemResponseMessage"} };
22 }
23 }
24  
25 sub _check_for_errors {
26 0 ▶ my ($self, $kind, $response) = @_;
Subroutine _check_for_errors: not called CC=4 SCAR=30.0
27  
28 0 foreach my $msg ( $self->_list_messages($kind, $response) ) {
29 0 ▶ my $code = $msg->{"${kind}ResponseMessage"}->{ResponseCode} || '';
Condition0%0/2
$$msg{"${kind}ResponseMessage"}{'ResponseCode'} || ''
l!l
00
MC/DC0%0/1
$$msg{"${kind}ResponseMessage"}{'ResponseCode'} || ''
$$msg{"${kind}ResponseMessage"}{'ResponseCode'}
Truth table0%0/2
A
A= $$msg{"${kind}ResponseMessage"}{'ResponseCode'}
Aresult
11
00
30 0 ▶ croak "Fault returned from Exchange Server: $code\n"
Branch: 1 branch
BranchTrueFalseTotal
if $code ne "NoError" 0 0 0
31 if $code ne 'NoError';
32 }
33 }
34  
35 sub _PagingOffset {
36 0 ▶ my ($self, $kind, $response) = @_;
Subroutine _PagingOffset: not called CC=4 SCAR=30.0
37  
38 0 foreach my $msg ( $self->_list_messages($kind, $response) ) {
39 0 ▶ if ( exists $msg->{"${kind}ResponseMessage"}->{RootFolder} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$msg{"${kind}ResponseMessage"}{"RootFolder"}) 0 0 0
40 0 ▶ if ( ! $msg->{"${kind}ResponseMessage"}->{RootFolder}->{IncludesLastItemInRange} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$msg{"${kind}ResponseMessage"}{"RootFolder"}{"IncludesLastItemInRange"}) 0 0 0
41 0 return $msg->{"${kind}ResponseMessage"}->{RootFolder}->{IndexedPagingOffset};
42 }
43 }
44 }
45 0 return 0;
46 }
47  
48 sub _list_folderitems {
49 0 ▶ my ($self, $kind, $response) = @_;
Subroutine _list_folderitems: not called CC=7 SCAR=40.3
50  
51 0 ▶ return map { exists $_->{Folder} ? $_->{Folder} : $_ }
Branch: 1 branch
BranchTrueFalseTotal
exists $_->{'Folder'} ? : 0 0 0
52 0 ▶ map { exists $_->{TasksFolder} ? $_->{TasksFolder} : $_ }
Branch: 1 branch
BranchTrueFalseTotal
exists $_->{'TasksFolder'} ? : 0 0 0
53 0 ▶ map { exists $_->{ContactsFolder} ? $_->{ContactsFolder} : $_ }
Branch: 1 branch
BranchTrueFalseTotal
exists $_->{'ContactsFolder'} ? : 0 0 0
54 0 ▶ map { exists $_->{CalendarFolder} ? $_->{CalendarFolder} : $_ }
Branch: 1 branch
BranchTrueFalseTotal
exists $_->{'CalendarFolder'} ? : 0 0 0
55 0 ▶ map { @{ $_->{Folders}->{cho_Folder} || [] } }
Branch: 1 branch
BranchTrueFalseTotal
$_->{"Folders"}{"cho_Folder"} or [] 0 0 0
56 0 ▶ map { exists $_->{RootFolder} ? $_->{RootFolder} : $_ }
Branch: 1 branch
BranchTrueFalseTotal
exists $_->{'RootFolder'} ? : 0 0 0
57 0 map { $_->{"${kind}ResponseMessage"} }
58 $self->_list_messages($kind, $response);
59 }
60  
61 # Find list of items within the view, then Get details for each one
62 # (item:Body is only available this way, it's not returned by FindItem)
63 sub retrieve{
64 0 ▶ my ($self, $opts) = @_;
Subroutine retrieve: not called CC=7 SCAR=40.3
Pod undocumented
65  
66 0 my @items;
67 0 my $IndexedPagingOffset = 0;
68 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$IndexedPagingOffset > 0 and do { do { my $find_response = scalar $self->client->FindFolder->(exists $opts->{"impersonate"} ? ("Impersonation", {"ConnectingSID", {"PrimarySmtpAddress", $opts->{"impersonate"}}}) : (), "RequestVersion", {"Version", $self->client->server_version}, "Traversal", "Deep", "FolderShape", {"BaseShape", "IdOnly", "AdditionalProperties", {"cho_Path", [{"ExtendedFieldURI", {"PropertyTag", 3592, "PropertyType", "Integer"}}, map({+{"FieldURI", {"FieldURI", $_}};} "folder:DisplayName", "folder:FolderClass", "folder:ChildFolderCount", "folder:TotalCount", "folder:ManagedFolderInformation", "folder:ParentFolderId")]}}, "IndexedPageFolderView", {"MaxEntriesReturned", 100, "Offset", $IndexedPagingOffset, "BasePoint", "Beginning"}, "ParentFolderIds", {"cho_FolderId", [{"DistinguishedFolderId", {exists $opts->{"folderId"} ? ("Id", $self->FolderId) : "Id", "msgfolderroot"}}]}); $self->_check_for_errors("FindFolder", $find_response); push @items, $self->_list_folderitems("FindFolder", $find_response); $IndexedPagingOffset = $self->_PagingOffset("FindFolder", $find_response) } } 0 0 0
69 # Find all folders underneath the 'Top of Information Store'
70 my $find_response = scalar $self->client->FindFolder->(
71 (exists $opts->{impersonate} ? (
72 Impersonation => {
73 ConnectingSID => {
74 PrimarySmtpAddress => $opts->{impersonate},
75 }
76 },
77 ) : ()),
78 RequestVersion => {
79 Version => $self->client->server_version,
80 },
81 Traversal => 'Deep',
82 FolderShape => {
83 BaseShape => 'IdOnly',
84 AdditionalProperties => {
85 cho_Path => [
86 {ExtendedFieldURI => {
87 PropertyTag => '3592',
88 PropertyType => 'Integer',
89 }},
90 map {{
91 0 ▶ FieldURI => {
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'folderId'} ? : 0 0 0
92 FieldURI => $_,
93 },
94 }} qw/
95 folder:DisplayName
96 folder:FolderClass
97 folder:ChildFolderCount
98 folder:TotalCount
99 folder:ManagedFolderInformation
100 folder:ParentFolderId
101 /,
102 ],
103 },
104 },
105 IndexedPageFolderView => {
106 MaxEntriesReturned => '100',
107 Offset => $IndexedPagingOffset,
108 BasePoint => 'Beginning',
109 },
110 ParentFolderIds => {
111 cho_FolderId => [
112 {
113 DistinguishedFolderId => {
114 (exists $opts->{folderId} ? (
115 0 ▶ Id => $self->FolderId,
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'impersonate'} ? : 0 0 0
116 ) : Id => "msgfolderroot",)
117 },
118 },
119 ],
120 },
121 );
122  
123 0 $self->_check_for_errors('FindFolder', $find_response);
124  
125 0 push( @items, $self->_list_folderitems('FindFolder', $find_response));
126  
127 0 $IndexedPagingOffset = $self->_PagingOffset('FindFolder', $find_response);
128 } while ( $IndexedPagingOffset > 0 );
129  
130 0 ▶ return return EWS::Folder::ResultSet->new({items => []})
Branch: 1 branch
BranchTrueFalseTotal
if scalar @items == 0 0 0 0
131 if scalar @items == 0;
132  
133 # Now add to that the details for the actual 'Top of Information Store' folder.
134 my $get_response = scalar $self->client->GetFolder->(
135 (exists $opts->{impersonate} ? (
136 Impersonation => {
137 ConnectingSID => {
138 PrimarySmtpAddress => $opts->{impersonate},
139 }
140 },
141 ) : ()),
142 RequestVersion => {
143 Version => $self->client->server_version,
144 },
145 FolderShape => {
146 BaseShape => 'IdOnly',
147 AdditionalProperties => {
148 cho_Path => [
149 {ExtendedFieldURI => {
150 PropertyTag => '3592',
151 PropertyType => 'Integer',
152 }},
153 map {{
154 0 ▶ FieldURI => {
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'folderId'} ? : 0 0 0
155 FieldURI => $_,
156 },
157 }} qw/
158 folder:DisplayName
159 folder:FolderClass
160 folder:ChildFolderCount
161 folder:ManagedFolderInformation
162 folder:ParentFolderId
163 /,
164 ],
165 },
166 },
167 FolderIds => {
168 cho_FolderId => [
169 {DistinguishedFolderId => {
170 (exists $opts->{folderId} ? (
171 0 ▶ Id => $self->FolderId,
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'impersonate'} ? : 0 0 0
172 ) : Id => "msgfolderroot",)
173 }},
174 ],
175 },
176 );
177  
178 0 $self->_check_for_errors('GetFolder', $get_response);
179  
180 0 push( @items, $self->_list_folderitems('GetFolder', $get_response));
181  
182 0 return EWS::Folder::ResultSet->new({
183 items => [ @items ]
184 });
185 }
186  
187 1 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
188 1 1;
189  
↑ Summary Contacts/Item.pm »