File Coverage

blib/lib/Business/cXML/Address/Postal.pm
Criterion Covered Total %
statement 34 34 100.0
branch 10 10 100.0
condition n/a
subroutine 8 8 100.0
pod 2 2 100.0
total 54 54 100.0


line stmt bran cond sub pod time code
1             =encoding utf-8
2              
3             =head1 NAME
4              
5             Business::cXML::Address::Postal - cXML postal address
6              
7             =head1 SYNOPSIS
8              
9             use Business::cXML::Address::Postal;
10              
11             =head1 DESCRIPTION
12              
13             Object representation of a cXML C<PostalAddress>.
14              
15             =head1 METHODS
16              
17             See L<Business::cXML::Object/COMMON METHODS>.
18              
19             =head1 PROPERTY METHODS
20              
21             See L<Business::cXML::Object/PROPERTY METHODS> for how the following operate.
22              
23             =over
24              
25             =cut
26              
27 10     10   223 use 5.014;
  10         28  
28 10     10   52 use strict;
  10         20  
  10         346  
29              
30             use base qw(Business::cXML::Object);
31 10     10   53  
  10         20  
  10         869  
32             use constant NODENAME => 'PostalAddress';
33 10     10   61 use constant PROPERTIES => (
  10         19  
  10         922  
34 10         630 name => undef,
35             delivertos => [],
36             streets => [],
37             city => '',
38             muni => undef,
39             state => undef,
40             code => undef,
41             country_iso => '',
42             country => '',
43             );
44 10     10   73  
  10         29  
45             use XML::LibXML::Ferry;
46 10     10   65  
  10         25  
  10         2474  
47             my ($self, $el) = @_;
48              
49 15     15 1 47 $el->ferry($self, {
50             Municipality => 'muni',
51 15         116 PostalCode => 'code',
52             Country => {
53             isoCountryCode => 'country_iso',
54             __text => 'country',
55             },
56             }
57             );
58             }
59              
60             my ($self, $doc) = @_;
61             my $node = $doc->create($self->{_nodeName});
62             $node->{name} = $self->{name} if $self->{name};
63 8     8 1 26  
64 8         30 $node->add('DeliverTo', $_) foreach (@{ $self->{delivertos} });
65 8 100       118 $node->add('Street', $_) foreach (@{ $self->{streets} });
66             $node->add('Street', ' ') unless scalar(@{ $self->{streets} }); # At least one required
67 8         334 $node->add('City', $self->{city});
  8         55  
68 8         305 $node->add('Municipality', $self->{muni}) if $self->{muni};
  8         37  
69 8 100       239 $node->add('State', $self->{state}) if $self->{state};
  8         35  
70 8         59 $node->add('PostalCode', $self->{code}) if $self->{code};
71 8 100       292 $node->add('Country', $self->{country}, isoCountryCode => $self->{country_iso});
72 8 100       260 return $node;
73 8 100       257 }
74 8         251  
75 8         425 =item C<B<name>>
76              
77             Optional, name of this address (i.e. C<billing department>)
78              
79             =item C<B<delivertos>[]>
80              
81             Optional
82              
83             =item C<B<streets>[]>
84              
85             Mandatory (at least one)
86              
87             =item C<B<city>>
88              
89             Mandatory
90              
91             =item C<B<muni>>
92              
93             Optional
94              
95             =item C<B<state>>
96              
97             Optional
98              
99             =item C<B<code>>
100              
101             Optional postal code
102              
103             =item C<B<country_iso>>
104              
105             Mandatory 2-letter ISO country code
106              
107             =item C<B<country>>
108              
109             Mandatory
110              
111             =back
112              
113             =head1 AUTHOR
114              
115             Stéphane Lavergne L<https://github.com/vphantom>
116              
117             =head1 ACKNOWLEDGEMENTS
118              
119             Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
120              
121             =head1 COPYRIGHT & LICENSE
122              
123             Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
124              
125             Permission is hereby granted, free of charge, to any person obtaining a copy
126             of this software and associated documentation files (the "Software"), to deal
127             in the Software without restriction, including without limitation the rights
128             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
129             copies of the Software, and to permit persons to whom the Software is
130             furnished to do so, subject to the following conditions:
131              
132             The above copyright notice and this permission notice shall be included in all
133             copies or substantial portions of the Software.
134              
135             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
136             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
137             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
138             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
139             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
140             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
141             SOFTWARE.
142              
143             =cut
144              
145             1;