File Coverage

blib/lib/Business/cXML/Address.pm
Criterion Covered Total %
statement 39 39 100.0
branch 10 10 100.0
condition n/a
subroutine 11 11 100.0
pod 2 2 100.0
total 62 62 100.0


line stmt bran cond sub pod time code
1             =encoding utf-8
2              
3             =head1 NAME
4              
5             Business::cXML::Address - cXML Address
6              
7             =head1 SYNOPSIS
8              
9             use Business::cXML::Address;
10             my $addr = new Business::cXML::Address {
11             name => 'Some Company',
12             email => 'shipping@example.com',
13             url => 'https://shipping.example.com/',
14             };
15              
16             =head1 DESCRIPTION
17              
18             Object representation of a cXML C<Address>.
19              
20             Note that there are only minor differences between an address and a contact,
21             however they are significant enough to warrant two separate classes.
22              
23             =head1 METHODS
24              
25             See L<Business::cXML::Object/COMMON METHODS>.
26              
27             =head1 PROPERTY METHODS
28              
29             See L<Business::cXML::Object/PROPERTY METHODS> for how the following operate.
30              
31             =over
32              
33             =cut
34              
35 8     8   151048 use 5.014;
  8         35  
36 8     8   41 use strict;
  8         46  
  8         238  
37              
38             use base qw(Business::cXML::Object);
39 8     8   40  
  8         26  
  8         859  
40             use Business::cXML::Address::Number;
41 8     8   799 use Business::cXML::Address::Postal;
  8         18  
  8         196  
42 8     8   809 use XML::LibXML::Ferry;
  8         23  
  8         252  
43 8     8   39  
  8         16  
  8         204  
44             use constant NODENAME => 'Address';
45 8     8   38 use constant PROPERTIES => (
  8         15  
  8         520  
46 8         529 lang => 'en-US',
47             name => '',
48             email => undef,
49             url => undef,
50             phone => undef,
51             fax => undef,
52             postal => undef,
53             );
54 8     8   46 use constant OBJ_PROPERTIES => (
  8         60  
55 8         2061 phone => [ 'Business::cXML::Address::Number', 'Phone' ],
56             fax => [ 'Business::cXML::Address::Number', 'Fax' ],
57             postal => 'Business::cXML::Address::Postal',
58             );
59 8     8   45  
  8         15  
60             my ($self, $el) = @_;
61              
62 15     15 1 49 $self->{_nodeName} = $el->nodeName;
63              
64 15         55 $el->ferry($self, {
65             addressID => '__UNIMPLEMENTED',
66 15         196 addressIDDomain => '__UNIMPLEMENTED',
67             isoCountryCode => '__UNIMPLEMENTED',
68             Name => {
69             'xml:lang' => 'lang',
70             __text => 'name',
71             },
72             Phone => [ 'phone', 'Business::cXML::Address::Number' ],
73             Fax => [ 'fax', 'Business::cXML::Address::Number' ],
74             PostalAddress => [ 'postal', 'Business::cXML::Address::Postal' ],
75             IdReference => '__UNIMPLEMENTED',
76             }
77             );
78             }
79              
80             my ($self, $doc) = @_;
81             my $name = $self->{_nodeName};
82              
83 9     9 1 5650 my $node = $doc->create($name);
84 9         26 # UNIMPLEMENTED: addressID? addressIDDomain? isoCountryCode?
85              
86 9         35 $node->add('Name', $self->{name}, 'xml:lang' => $self->{lang});
87             $node->add($self->{postal}->to_node($node)) if ref $self->{postal};
88             $node->add('Email', $self->{email}) if $self->{email};
89 9         198 $node->add($self->{phone}->to_node($node)) if ref $self->{phone};
90 9 100       662 $node->add($self->{fax}->to_node($node)) if ref $self->{fax};
91 9 100       193 $node->add('URL', $self->{url}) if $self->{url};
92 9 100       355 # UNIMPLEMENTED: IdReference?
93 9 100       146  
94 9 100       146 return $node;
95             }
96              
97 9         323 =item C<B<lang>>
98              
99             Defaults to C<en-US>
100              
101             =item C<B<name>>
102              
103             Mandatory
104              
105             =item C<B<email>>
106              
107             Optional
108              
109             =item C<B<url>>
110              
111             Optional
112              
113             =item C<B<phone>>
114              
115             Optional, L<Business::cXML::Address::Number> object of type C<Phone>
116              
117             =item C<B<fax>>
118              
119             Optional, L<Business::cXML::Address::Number> object of type C<Fax>
120              
121             =item C<B<postal>>
122              
123             Optional, L<Business::cXML::Address::Postal> object
124              
125             =back
126              
127             =head1 AUTHOR
128              
129             Stéphane Lavergne L<https://github.com/vphantom>
130              
131             =head1 ACKNOWLEDGEMENTS
132              
133             Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
134              
135             =head1 COPYRIGHT & LICENSE
136              
137             Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
138              
139             Permission is hereby granted, free of charge, to any person obtaining a copy
140             of this software and associated documentation files (the "Software"), to deal
141             in the Software without restriction, including without limitation the rights
142             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
143             copies of the Software, and to permit persons to whom the Software is
144             furnished to do so, subject to the following conditions:
145              
146             The above copyright notice and this permission notice shall be included in all
147             copies or substantial portions of the Software.
148              
149             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
150             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
151             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
152             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
153             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
154             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
155             SOFTWARE.
156              
157             =cut
158              
159             1;