| 1 | =encoding utf-8 | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Business::cXML::Address::Number - cXML contact phone/fax number | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | use Business::cXML::Address::Number; | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | Object representation of a cXML phone or fax number. You can specify which | ||||||||||
| 14 | when calling C<new()> by passing I<C<$node>> set to C<Phone> (default) or | ||||||||||
| 15 | C<Fax>. Alternatively, you can also specify it with a C<_nodeName> in | ||||||||||
| 16 | C<new()>'s I<C<$properties>>. | ||||||||||
| 17 | |||||||||||
| 18 | Specifically B<not> implemented are Faxes containing a URL or e-mail address | ||||||||||
| 19 | instead of a telephone number. | ||||||||||
| 20 | |||||||||||
| 21 | =head1 METHODS | ||||||||||
| 22 | |||||||||||
| 23 | See L<Business::cXML::Object/COMMON METHODS>, plus the following: | ||||||||||
| 24 | |||||||||||
| 25 | =over | ||||||||||
| 26 | |||||||||||
| 27 | =cut | ||||||||||
| 28 | |||||||||||
| 29 | 10 | ▶ | use 5.014; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 10 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | |||||||||||
| 32 | package Business::cXML::Address::Number; | ||||||||||
| 33 | 10 | ▶ | use base qw(Business::cXML::Object); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | |||||||||||
| 35 | 10 | ▶ | use constant NODENAME => 'Phone'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 10 | ▶ | use constant PROPERTIES => ( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | name => undef, | ||||||||||
| 38 | country_iso => 'US', | ||||||||||
| 39 | country_code => '1', | ||||||||||
| 40 | area_code => '', | ||||||||||
| 41 | number => '', | ||||||||||
| 42 | extension => undef, | ||||||||||
| 43 | 10 | ); | |||||||||
| 44 | |||||||||||
| 45 | 10 | ▶ | use Business::cXML::Utils qw(to_numeric); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 10 | ▶ | use XML::LibXML::Ferry; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 47 | |||||||||||
| 48 | 17 | ▶ | sub _numeric { | ||||||||
|
Subroutine
_numeric: called CC=1 SCAR=0.0
| |||||||||||
| 49 | 17 | my ($self, $val) = @_; | |||||||||
| 50 | 17 | $val = $val->textContent; | |||||||||
| 51 | 17 | return to_numeric($val); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 7 | ▶ | sub from_node { | ||||||||
|
Subroutine
from_node: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 55 | 7 | my ($self, $el) = @_; | |||||||||
| 56 | |||||||||||
| 57 | 7 | $el->ferry($self, { | |||||||||
| 58 | TelephoneNumber => { | ||||||||||
| 59 | CountryCode => { | ||||||||||
| 60 | isoCountryCode => 'country_iso', | ||||||||||
| 61 | __text => [ 'country_code', \&_numeric ], | ||||||||||
| 62 | }, | ||||||||||
| 63 | AreaOrCityCode => [ 'area_code', \&_numeric ], | ||||||||||
| 64 | Number => [ 'number', \&_numeric ], | ||||||||||
| 65 | Extension => [ 'extension', \&_numeric ], | ||||||||||
| 66 | }, | ||||||||||
| 67 | URL => '__UNIMPLEMENTED', # Fax only | ||||||||||
| 68 | Email => '__UNIMPLEMENTED', # Fax only | ||||||||||
| 69 | }); | ||||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 6 | ▶ | sub to_node { | ||||||||
|
Subroutine
to_node: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 73 | 6 | my ($self, $doc) = @_; | |||||||||
| 74 | 6 | my $node = $doc->create($self->{_nodeName}, undef, name => $self->{name}); | |||||||||
| 75 | |||||||||||
| 76 | 6 | my $el = $node->add('TelephoneNumber'); | |||||||||
| 77 | 6 | $el->add('CountryCode', $self->{country_code}, isoCountryCode => $self->{country_iso}); | |||||||||
| 78 | 6 | $el->add('AreaOrCityCode', $self->{area_code}); | |||||||||
| 79 | 6 | $el->add('Number', $self->{number}); | |||||||||
| 80 | 6 | ▶ | $el->add('Extension', $self->{extension}) if $self->{extension}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | |||||||||||
| 82 | 6 | return $node; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | =item C<B<toString>()> | ||||||||||
| 86 | |||||||||||
| 87 | Returns the string representation of the phone number in C<C-AAA-NNN-NNNN> | ||||||||||
| 88 | format, without the extension. Only North-American formatting is currently | ||||||||||
| 89 | implemented. | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | 2 | ▶ | sub toString { | ||||||||
|
Subroutine
toString: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 94 | 2 | my ($self) = @_; | |||||||||
| 95 | 2 | my $n = $self->{number}; | |||||||||
| 96 | 2 | ▶ | $n = join('-', unpack('A3A4', $n)) if (length($self->{number}) == 7); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 2 | return $self->{country_code} . '-' . $self->{area_code} . '-' . $n; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | =item C<B<fromString>( I<$string> )> | ||||||||||
| 101 | |||||||||||
| 102 | Extracts country code, area code and number from I<C<$string>>. (Not the | ||||||||||
| 103 | extension.) Non-numeric characters are safely discarded. Only North-American | ||||||||||
| 104 | formatting is currently implemented, with the benefit that the initial C<1> is | ||||||||||
| 105 | optional. | ||||||||||
| 106 | |||||||||||
| 107 | Note: processing starts from the left, so any custom extension suffixes are | ||||||||||
| 108 | safely ignored. | ||||||||||
| 109 | |||||||||||
| 110 | =cut | ||||||||||
| 111 | |||||||||||
| 112 | 1 | ▶ | sub fromString { | ||||||||
|
Subroutine
fromString: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 113 | 1 | my ($self, $str) = @_; | |||||||||
| 114 | 1 | $str = to_numeric($str); | |||||||||
| 115 | 1 | my ($area, $number) = $str =~ m/^1?(\d{3})(\d{7})/x; | |||||||||
| 116 | 1 | $self->{country_code} = '1'; | |||||||||
| 117 | 1 | $self->{area_code} = $area; | |||||||||
| 118 | 1 | $self->{number} = $number; | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | =back | ||||||||||
| 122 | |||||||||||
| 123 | =head1 PROPERTY METHODS | ||||||||||
| 124 | |||||||||||
| 125 | See L<Business::cXML::Object/PROPERTY METHODS> for how the following operate. | ||||||||||
| 126 | |||||||||||
| 127 | =over | ||||||||||
| 128 | |||||||||||
| 129 | =item C<B<name>> | ||||||||||
| 130 | |||||||||||
| 131 | Optional, name of this phone or fax number (i.e. C<work>). Without a name, | ||||||||||
| 132 | this represents a C<TelephoneNumber> without a wrapper C<Phone>/C<Fax>. | ||||||||||
| 133 | |||||||||||
| 134 | =item C<B<country_iso>> | ||||||||||
| 135 | |||||||||||
| 136 | 2-letter ISO country code | ||||||||||
| 137 | |||||||||||
| 138 | =item C<B<country_code>> | ||||||||||
| 139 | |||||||||||
| 140 | Country code (default: C<1>) | ||||||||||
| 141 | |||||||||||
| 142 | =item C<B<area_code>> | ||||||||||
| 143 | |||||||||||
| 144 | Area code | ||||||||||
| 145 | |||||||||||
| 146 | =item C<B<number>> | ||||||||||
| 147 | |||||||||||
| 148 | Number | ||||||||||
| 149 | |||||||||||
| 150 | =item C<B<extension>> | ||||||||||
| 151 | |||||||||||
| 152 | Optional, extension | ||||||||||
| 153 | |||||||||||
| 154 | =back | ||||||||||
| 155 | |||||||||||
| 156 | =head1 AUTHOR | ||||||||||
| 157 | |||||||||||
| 158 | Stéphane Lavergne L<https://github.com/vphantom> | ||||||||||
| 159 | |||||||||||
| 160 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 161 | |||||||||||
| 162 | Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project. | ||||||||||
| 163 | |||||||||||
| 164 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 165 | |||||||||||
| 166 | Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom> | ||||||||||
| 167 | |||||||||||
| 168 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||||||
| 169 | of this software and associated documentation files (the "Software"), to deal | ||||||||||
| 170 | in the Software without restriction, including without limitation the rights | ||||||||||
| 171 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||||||
| 172 | copies of the Software, and to permit persons to whom the Software is | ||||||||||
| 173 | furnished to do so, subject to the following conditions: | ||||||||||
| 174 | |||||||||||
| 175 | The above copyright notice and this permission notice shall be included in all | ||||||||||
| 176 | copies or substantial portions of the Software. | ||||||||||
| 177 | |||||||||||
| 178 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||||||
| 179 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||||||
| 180 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||||||
| 181 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||||||
| 182 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||||||
| 183 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||||||
| 184 | SOFTWARE. | ||||||||||
| 185 | |||||||||||
| 186 | =cut | ||||||||||
| 187 | |||||||||||
| 188 | 10 | 1; | |||||||||