File Coverage

lib/Business/Fixflo/PropertyAddress.pm
Criterion Covered Total %
statement 45 47 95.7
branch 8 8 100.0
condition n/a
subroutine 14 15 93.3
pod 4 4 100.0
total 71 74 95.9


line stmt bran cond sub pod time code
1             package Business::Fixflo::PropertyAddress;
2              
3             =head1 NAME
4              
5             Business::Fixflo::Property::Address
6              
7             =head1 DESCRIPTION
8              
9             A class for a fixflo property address, extends L
10              
11             =cut
12              
13 16     16   102 use strict;
  16         30  
  16         424  
14 16     16   70 use warnings;
  16         31  
  16         440  
15              
16 16     16   72 use Moo;
  16         27  
  16         73  
17             extends 'Business::Fixflo::Property';
18              
19 16     16   5426 use Try::Tiny;
  16         47  
  16         1080  
20 16     16   94 use Carp qw/ carp /;
  16         42  
  16         769  
21 16     16   93 use Business::Fixflo::Property;
  16         31  
  16         463  
22 16     16   85 use Business::Fixflo::Address;
  16         30  
  16         312  
23 16     16   70 use Business::Fixflo::Exception;
  16         42  
  16         448  
24              
25 16     16   97 use Carp qw/ confess /;
  16         50  
  16         10719  
26              
27             =head1 Operations on a property address
28              
29             =head2 get
30              
31             Gets a property address based on the Id
32              
33             =head2 merge
34              
35             merges a property address into a property:
36              
37             $PropertyAddress = $PropertyAddress->merge( $Property );
38              
39             $Property must be a Business::Fixflo::Property object and have its Id set
40              
41             =head2 split
42              
43             splits a property address from a property
44              
45             =head2 property
46              
47             gets the L object associated with the property
48             address:
49              
50             my $Property = $PropertyAddress->property;
51              
52             =cut
53              
54             sub get {
55 1     1 1 1527 my ( $self ) = @_;
56              
57 1         11 my $data = $self->client->api_get(
58             'PropertyAddress/' . $self->Id
59             );
60              
61 1         3 foreach my $attr ( keys( %{ $data } ) ) {
  1         4  
62 3     3   235 try { $self->$attr( $data->{$attr} ); }
63             catch {
64 0     0   0 carp( "Couldn't set $attr on @{[ ref( $self ) ]}: $_" );
  0         0  
65 3         55 };
66             }
67              
68 1         23 return $self;
69             }
70              
71             sub merge {
72 4     4 1 1300 my ( $self,$Property ) = @_;
73              
74 4 100       30 Business::Fixflo::Exception->throw({
75             message => 'PropertyAddress->merge requires a Business::Fixflo::Property',
76             }) if ref( $Property ) ne 'Business::Fixflo::Property';
77              
78 3 100       23 Business::Fixflo::Exception->throw({
79             message => 'PropertyAddress->Id must be set to merge',
80             }) if ! $self->Id;
81              
82 2 100       14 Business::Fixflo::Exception->throw({
83             message => 'Property->Id must be set to merge',
84             }) if ! $Property->Id;
85              
86 1         10 return $self->_parse_envelope_data(
87             $self->client->api_post(
88             'PropertyAddress/Merge',
89             {
90             Id => $self->Id,
91             PropertyId => $Property->Id,
92             }
93             ),
94             );
95             }
96              
97             sub split {
98 2     2 1 46 my ( $self ) = @_;
99              
100 2 100       16 Business::Fixflo::Exception->throw({
101             message => 'PropertyAddress->Id must be set to split',
102             }) if ! $self->Id;
103              
104 1         9 return $self->_parse_envelope_data(
105             $self->client->api_post(
106             'PropertyAddress/Split',
107             {
108             Id => $self->Id,
109             }
110             ),
111             );
112             }
113              
114             sub property {
115 1     1 1 3 my ( $self ) = @_;
116              
117 1         27 my $Property = Business::Fixflo::Property->new(
118             client => $self->client,
119             Id => $self->PropertyId,
120             );
121              
122 1         13 return $Property->get;
123             }
124              
125             =head1 AUTHOR
126              
127             Lee Johnson - C
128              
129             This library is free software; you can redistribute it and/or modify it under
130             the same terms as Perl itself. If you would like to contribute documentation,
131             features, bug fixes, or anything else then please raise an issue / pull request:
132              
133             https://github.com/Humanstate/business-fixflo
134              
135             =cut
136              
137             1;
138              
139             # vim: ts=4:sw=4:et