| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package EWS::DistributionList::Role::Reader; | 
| 2 |  |  |  |  |  |  | BEGIN { | 
| 3 | 1 |  |  | 1 |  | 720 | $EWS::DistributionList::Role::Reader::VERSION = '1.143070'; | 
| 4 |  |  |  |  |  |  | } | 
| 5 | 1 |  |  | 1 |  | 6 | use Moose::Role; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 8 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 5795 | use EWS::DistributionList::ResultSet; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 35 |  | 
| 8 | 1 |  |  | 1 |  | 7 | use Carp; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 540 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub _list_messages { | 
| 11 | 0 |  |  | 0 |  |  | my ( $self, $kind, $response ) = @_; | 
| 12 | 0 |  |  |  |  |  | return @{ $response->{"${kind}Result"}->{ResponseMessages}->{cho_CreateItemResponseMessage} }; | 
|  | 0 |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | } | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub _check_for_errors { | 
| 16 | 0 |  |  | 0 |  |  | my ( $self, $kind, $response ) = @_; | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 0 |  |  |  |  |  | foreach my $msg ( $self->_list_messages( $kind, $response ) ) { | 
| 19 | 0 |  | 0 |  |  |  | my $code = $msg->{"${kind}ResponseMessage"}->{ResponseCode} || ''; | 
| 20 | 0 | 0 |  |  |  |  | croak "Fault returned from Exchange Server: $code\n" | 
| 21 |  |  |  |  |  |  | if $code ne 'NoError'; | 
| 22 |  |  |  |  |  |  | } | 
| 23 | 0 |  |  |  |  |  | return; | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub _list_dlitems { | 
| 27 | 0 |  |  | 0 |  |  | my ( $self, $kind, $response ) = @_; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 0 | 0 |  |  |  |  | return map { @{ $_->{DLExpansion}->{Mailbox} || [] } } | 
|  | 0 |  |  |  |  |  |  | 
| 30 | 0 |  |  |  |  |  | map { $_->{"${kind}ResponseMessage"} } $self->_list_messages( $kind, $response ); | 
|  | 0 |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub _get_dls { | 
| 34 | 0 |  |  | 0 |  |  | my ( $self, $opts ) = @_; | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | return $self->client->ExpandDL->( | 
| 37 |  |  |  |  |  |  | (   exists $opts->{impersonate} | 
| 38 |  |  |  |  |  |  | ? ( Impersonation => { ConnectingSID => { PrimarySmtpAddress => $opts->{impersonate}, } }, ) | 
| 39 |  |  |  |  |  |  | : () | 
| 40 |  |  |  |  |  |  | ), | 
| 41 |  |  |  |  |  |  | RequestVersion => { Version      => $self->client->server_version, }, | 
| 42 |  |  |  |  |  |  | Mailbox        => { EmailAddress => $opts->{distribution_email}, }, | 
| 43 | 0 | 0 |  |  |  |  | ); | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | # find primarysmtp if passed an account id. | 
| 47 |  |  |  |  |  |  | # then find dls in the account. | 
| 48 |  |  |  |  |  |  | sub retrieve { | 
| 49 | 0 |  |  | 0 | 0 |  | my ( $self, $opts ) = @_; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 |  |  |  |  |  | my $get_response = $self->_get_dls($opts); | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 0 | 0 | 0 |  |  |  | if (    exists $get_response->{'ResponseCode'} | 
|  |  |  | 0 |  |  |  |  | 
| 54 |  |  |  |  |  |  | and defined $get_response->{'ResponseCode'} | 
| 55 |  |  |  |  |  |  | and $get_response->{'ResponseCode'} eq 'ErrorNonPrimarySmtpAddress' ) | 
| 56 |  |  |  |  |  |  | { | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 0 |  |  |  |  |  | $self->retrieve( { %{$opts}, distribution_email => $get_response->{DLExpansion}->{Mailbox} } ); | 
|  | 0 |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 0 |  |  |  |  |  | $self->_check_for_errors( 'ExpandDL', $get_response ); | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 0 |  |  |  |  |  | return EWS::DistributionList::ResultSet->new( | 
| 64 |  |  |  |  |  |  | { mailboxes => [ $self->_list_dlitems( 'ExpandDL', $get_response ) ] } ); | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | sub expand { | 
| 68 | 0 |  |  | 0 | 0 |  | return shift->retrieve( { distribution_email => shift } ); | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 1 |  |  | 1 |  | 6 | no Moose::Role; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 9 |  | 
| 72 |  |  |  |  |  |  | 1; |