File Coverage

blib/lib/WWW/LogicBoxes/Contact/Factory.pm
Criterion Covered Total %
statement 31 32 96.8
branch 3 4 75.0
condition 5 6 83.3
subroutine 9 9 100.0
pod 1 1 100.0
total 49 52 94.2


line stmt bran cond sub pod time code
1             package WWW::LogicBoxes::Contact::Factory;
2              
3 45     45   633752 use strict;
  45         168  
  45         1577  
4 45     45   276 use warnings;
  45         97  
  45         1466  
5              
6 45     45   3396 use MooseX::Params::Validate;
  45         3379595  
  45         459  
7              
8 45     45   30090 use WWW::LogicBoxes::Types qw( HashRef );
  45         126  
  45         502  
9              
10 45     45   489260 use WWW::LogicBoxes::Contact;
  45         221  
  45         2296  
11 45     45   29597 use WWW::LogicBoxes::Contact::CA;
  45         217  
  45         2192  
12 45     45   28211 use WWW::LogicBoxes::Contact::US;
  45         221  
  45         2238  
13              
14 45     45   470 use Carp;
  45         159  
  45         10796  
15              
16             our $VERSION = '1.11.0'; # VERSION
17             # ABSTRACT: Abstract Factory For Construction of Contacts
18              
19             sub construct_from_response {
20 7     7 1 13042 my $self = shift;
21 7         48 my ( $response ) = pos_validated_list( \@_, { isa => HashRef } );
22              
23 7 50 100     14565 if( $response->{type} eq 'CaContact' ) {
    100 66        
24 0         0 return WWW::LogicBoxes::Contact::CA->construct_from_response( $response );
25             }
26 6         54 elsif( ( grep { $_ eq 'domus' } @{ $response->{contacttype} } )
  7         35  
27             && exists $response->{ApplicationPurpose} && exists $response->{NexusCategory} ) {
28 1         9 return WWW::LogicBoxes::Contact::US->construct_from_response($response);
29             }
30             else {
31 6         66 return WWW::LogicBoxes::Contact->construct_from_response($response);
32             }
33             }
34              
35             1;
36              
37             __END__
38              
39             =pod
40              
41             =head1 NAME
42              
43             WWW::LogicBoxes::Contact::Factory - Factory for Construction of Contact Objects
44              
45             =head1 SYNOPSIS
46              
47             use WWW::LogicBoxes;
48             use WWW::LogicBoxes::Contact::Factory;
49              
50             my $api = WWW::LogicBoxes->new( ... );
51              
52             my $response = $api->submit({
53             method => 'contacts__details',
54             params => {
55             'contact-id' => 42,
56             },
57             });
58              
59             my $contact = WWW::LogicBoxes::Contact::Factory->construct_from_response( $response );
60              
61             =head1 DESCRIPTION
62              
63             Abstract Factory that accepts the raw response from L<LogicBoxes|http://www.logicboxes.com> and returns a fully formed L<WWW::LogicBoxes::Contact> or one of it's subclasses.
64              
65             =head1 METHODS
66              
67             =head2 construct_from_response
68              
69             my $response = $api->submit({
70             method => 'contacts__details',
71             params => {
72             'contact-id' => 42,
73             },
74             });
75              
76             my $contact = WWW::LogicBoxes::Contact::Factory->construct_from_response( $response );
77              
78             Given a HashRef that is the JSON response from LogicBoxes when retrieving contact details, returns an instance of L<WWW::LogicBoxes::Contact> or one of it's subclasses.