File Coverage

blib/lib/Business/cXML/Contact.pm
Criterion Covered Total %
statement 45 45 100.0
branch 2 2 100.0
condition n/a
subroutine 11 11 100.0
pod 2 2 100.0
total 60 60 100.0


line stmt bran cond sub pod time code
1             =encoding utf-8
2              
3             =head1 NAME
4              
5             Business::cXML::Contact - cXML Contact
6              
7             =head1 SYNOPSIS
8              
9             use Business::cXML::Contact;
10             my $contact = new Business::cXML::Contact {
11             name => 'Some Person',
12             emails => 'some.person@example.com',
13             urls => 'https://www.example.com/',
14             };
15              
16             =head1 DESCRIPTION
17              
18             Object representation of a cXML C<Contact>.
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 9     9   135682 use 5.014;
  9         66  
36 9     9   43 use strict;
  9         16  
  9         256  
37              
38             use base qw(Business::cXML::Object);
39 9     9   40  
  9         14  
  9         925  
40             use Business::cXML::Address::Number;
41 9     9   2839 use Business::cXML::Address::Postal;
  9         26  
  9         306  
42 9     9   3274 use XML::LibXML::Ferry;
  9         23  
  9         307  
43 9     9   49  
  9         18  
  9         190  
44             use constant NODENAME => 'Contact';
45 9     9   39 use constant PROPERTIES => (
  9         18  
  9         602  
46 9         564 role => undef,
47             lang => 'en-US',
48             name => '',
49             emails => [],
50             urls => [],
51             phones => [],
52             faxes => [],
53             postals => [],
54             );
55 9     9   51 use constant OBJ_PROPERTIES => (
  9         17  
56 9         2532 phones => [ 'Business::cXML::Address::Number', 'Phone' ],
57             faxes => [ 'Business::cXML::Address::Number', 'Fax' ],
58             postals => 'Business::cXML::Address::Postal',
59             );
60 9     9   74  
  9         19  
61             my ($self, $el) = @_;
62              
63 11     11 1 38 $self->{_nodeName} = $el->nodeName;
64              
65 11         48 $el->ferry($self, {
66             addressID => '__UNIMPLEMENTED',
67 11         139 addressIDDomain => '__UNIMPLEMENTED',
68             Name => {
69             'xml:lang' => 'lang',
70             __text => 'name',
71             },
72             Phone => [ 'phones', 'Business::cXML::Address::Number' ],
73             Fax => [ 'faxes', 'Business::cXML::Address::Number' ],
74             PostalAddress => [ 'postals', 'Business::cXML::Address::Postal' ],
75             IdReference => '__UNIMPLEMENTED',
76             }
77             );
78             }
79              
80             my ($self, $doc) = @_;
81             my $name = $self->{_nodeName};
82              
83 8     8 1 6171 my $node = $doc->create($name);
84 8         19 $node->{role} = $self->{role} if defined $self->{role};
85             # UNIMPLEMENTED: addressID? addressIDDomain?
86 8         25  
87 8 100       149 $node->add('Name', $self->{name}, 'xml:lang' => $self->{lang});
88             $node->add($_->to_node($node)) foreach (@{ $self->{postals} });
89             $node->add('Email', $_) foreach (@{ $self->{emails} });
90 8         145 $node->add($_->to_node($node)) foreach (@{ $self->{phones} });
91 8         469 $node->add($_->to_node($node)) foreach (@{ $self->{faxes} });
  8         34  
92 8         19 $node->add('URL', $_) foreach (@{ $self->{urls} });
  8         31  
93 8         243 # UNIMPLEMENTED: IdReference*
  8         43  
94 8         215  
  8         28  
95 8         16 return $node;
  8         17  
96             }
97              
98 8         30 =item C<B<role>>
99              
100             Optional
101              
102             =item C<B<lang>>
103              
104             Defaults to C<en-US>
105              
106             =item C<B<name>>
107              
108             Mandatory
109              
110             =item C<B<emails>[]>
111              
112             Optional, strings
113              
114             =item C<B<urls>[]>
115              
116             Optional, strings
117              
118             =item C<B<phones>[]>
119              
120             Optional, L<Business::cXML::Address::Number> objects of type C<Phone>
121              
122             =item C<B<faxes>[]>
123              
124             Optional, L<Business::cXML::Address::Number> objects of type C<Fax>
125              
126             =item C<B<postals>[]>
127              
128             Optional, L<Business::cXML::Address::Postal> objects
129              
130             =back
131              
132             =head1 AUTHOR
133              
134             Stéphane Lavergne L<https://github.com/vphantom>
135              
136             =head1 ACKNOWLEDGEMENTS
137              
138             Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
139              
140             =head1 COPYRIGHT & LICENSE
141              
142             Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
143              
144             Permission is hereby granted, free of charge, to any person obtaining a copy
145             of this software and associated documentation files (the "Software"), to deal
146             in the Software without restriction, including without limitation the rights
147             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
148             copies of the Software, and to permit persons to whom the Software is
149             furnished to do so, subject to the following conditions:
150              
151             The above copyright notice and this permission notice shall be included in all
152             copies or substantial portions of the Software.
153              
154             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
155             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
156             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
157             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
158             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
159             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
160             SOFTWARE.
161              
162             =cut
163              
164             1;