cXML/Address.pm

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