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 44     44   803999 use strict;
  44         114  
  44         1397  
4 44     44   236 use warnings;
  44         148  
  44         1337  
5              
6 44     44   2697 use MooseX::Params::Validate;
  44         2758228  
  44         434  
7              
8 44     44   27646 use WWW::LogicBoxes::Types qw( HashRef );
  44         118  
  44         422  
9              
10 44     44   441644 use WWW::LogicBoxes::Contact;
  44         200  
  44         2054  
11 44     44   25564 use WWW::LogicBoxes::Contact::CA;
  44         200  
  44         1947  
12 44     44   24739 use WWW::LogicBoxes::Contact::US;
  44         198  
  44         1926  
13              
14 44     44   406 use Carp;
  44         99  
  44         9633  
15              
16             our $VERSION = '1.10.0'; # VERSION
17             # ABSTRACT: Abstract Factory For Construction of Contacts
18              
19             sub construct_from_response {
20 7     7 1 10792 my $self = shift;
21 7         34 my ( $response ) = pos_validated_list( \@_, { isa => HashRef } );
22              
23 7 50 100     12815 if( $response->{type} eq 'CaContact' ) {
    100 66        
24 0         0 return WWW::LogicBoxes::Contact::CA->construct_from_response( $response );
25             }
26 6         51 elsif( ( grep { $_ eq 'domus' } @{ $response->{contacttype} } )
  7         34  
27             && exists $response->{ApplicationPurpose} && exists $response->{NexusCategory} ) {
28 1         9 return WWW::LogicBoxes::Contact::US->construct_from_response($response);
29             }
30             else {
31 6         43 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.