cXML/Contact.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 100% 61 / 61 CC 7 SCAR 12.4
CC
7
Cov
100%
to_node
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
« cXML/Object.pm ↑ Summary cXML/Address.pm »
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 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 package Business::cXML::Contact;
39 9 ▶use base qw(Business::cXML::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 9 ▶use Business::cXML::Address::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 9 ▶use Business::cXML::Address::Postal;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 9 ▶use XML::LibXML::Ferry;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 9 ▶use constant NODENAME => 'Contact';
Subroutine BEGIN: called CC=1 SCAR=0.0
46 9 ▶use constant PROPERTIES => (
Subroutine BEGIN: called CC=1 SCAR=0.0
47 role => undef,
48 lang => 'en-US',
49 name => '',
50 emails => [],
51 urls => [],
52 phones => [],
53 faxes => [],
54 postals => [],
55 9 );
56 9 ▶use constant OBJ_PROPERTIES => (
Subroutine BEGIN: called CC=1 SCAR=0.0
57 phones => [ 'Business::cXML::Address::Number', 'Phone' ],
58 faxes => [ 'Business::cXML::Address::Number', 'Fax' ],
59 postals => 'Business::cXML::Address::Postal',
60 9 );
61  
62 2 ▶sub from_node {
Subroutine from_node: called CC=1 SCAR=0.0
Pod documented
63 2 my ($self, $el) = @_;
64  
65 2 $self->{_nodeName} = $el->nodeName;
66  
67 2 $el->ferry($self, {
68 addressID => '__UNIMPLEMENTED',
69 addressIDDomain => '__UNIMPLEMENTED',
70 Name => {
71 'xml:lang' => 'lang',
72 __text => 'name',
73 },
74 Phone => [ 'phones', 'Business::cXML::Address::Number' ],
75 Fax => [ 'faxes', 'Business::cXML::Address::Number' ],
76 PostalAddress => [ 'postals', 'Business::cXML::Address::Postal' ],
77 IdReference => '__UNIMPLEMENTED',
78 }
79 );
80 }
81  
82 3 ▶sub to_node {
Subroutine to_node: called CC=7 SCAR=19.5
Pod documented
83 3 my ($self, $doc) = @_;
84 3 my $name = $self->{_nodeName};
85  
86 3 my $node = $doc->create($name);
87 3 ▶ $node->{role} = $self->{role} if defined $self->{role};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"role"} 2 1 3
88 # UNIMPLEMENTED: addressID? addressIDDomain?
89  
90 3 $node->add('Name', $self->{name}, 'xml:lang' => $self->{lang});
91 3 $node->add($_->to_node($node)) foreach (@{ $self->{postals} });
92 3 $node->add('Email', $_) foreach (@{ $self->{emails} });
93 3 $node->add($_->to_node($node)) foreach (@{ $self->{phones} });
94 3 $node->add($_->to_node($node)) foreach (@{ $self->{faxes} });
95 3 $node->add('URL', $_) foreach (@{ $self->{urls} });
96 # UNIMPLEMENTED: IdReference*
97  
98 3 return $node;
99 }
100  
101 =item C<B<role>>
102  
103 Optional
104  
105 =item C<B<lang>>
106  
107 Defaults to C<en-US>
108  
109 =item C<B<name>>
110  
111 Mandatory
112  
113 =item C<B<emails>[]>
114  
115 Optional, strings
116  
117 =item C<B<urls>[]>
118  
119 Optional, strings
120  
121 =item C<B<phones>[]>
122  
123 Optional, L<Business::cXML::Address::Number> objects of type C<Phone>
124  
125 =item C<B<faxes>[]>
126  
127 Optional, L<Business::cXML::Address::Number> objects of type C<Fax>
128  
129 =item C<B<postals>[]>
130  
131 Optional, L<Business::cXML::Address::Postal> objects
132  
133 =back
134  
135 =head1 AUTHOR
136  
137 Stéphane Lavergne L<https://github.com/vphantom>
138  
139 =head1 ACKNOWLEDGEMENTS
140  
141 Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
142  
143 =head1 COPYRIGHT & LICENSE
144  
145 Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
146  
147 Permission is hereby granted, free of charge, to any person obtaining a copy
148 of this software and associated documentation files (the "Software"), to deal
149 in the Software without restriction, including without limitation the rights
150 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
151 copies of the Software, and to permit persons to whom the Software is
152 furnished to do so, subject to the following conditions:
153  
154 The above copyright notice and this permission notice shall be included in all
155 copies or substantial portions of the Software.
156  
157 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
159 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
160 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
161 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
162 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
163 SOFTWARE.
164  
165 =cut
166  
167 9 1;
« cXML/Object.pm ↑ Summary cXML/Address.pm »