| Business-UPS-Tracking documentation | Contained in the Business-UPS-Tracking distribution. |
Business::UPS::Tracking::Element::Address - An address
This class represents an address. Usually it is created automatically from a Business::UPS::Tracking::Shipment object.
Original XML::LibXML::Node node.
Only US and Canada
ISO 3166-1 alpha-2 country code.
Serialize address into a string.
Moose meta method
| Business-UPS-Tracking documentation | Contained in the Business-UPS-Tracking distribution. |
# ============================================================================ package Business::UPS::Tracking::Element::Address; # ============================================================================ use utf8; use 5.0100; use Moose; __PACKAGE__->meta->error_class("Business::UPS::Tracking::Exception"); use Business::UPS::Tracking::Utils; our $VERSION = $Business::UPS::Tracking::VERISON;
has 'xml' => ( is => 'rw', isa => 'XML::LibXML::Node', required => 1, trigger => \&_build_address, ); has 'AddressLine1' => ( is => 'rw', isa => 'Maybe[Str]', ); has 'AddressLine2' => ( is => 'rw', isa => 'Maybe[Str]', ); has 'AddressLine3' => ( is => 'rw', isa => 'Maybe[Str]', ); has 'City' => ( is => 'rw', isa => 'Maybe[Str]', ); has 'StateProvinceCode' => ( is => 'rw', isa => 'Maybe[Str]', ); has 'PostalCode' => ( is => 'rw', isa => 'Maybe[Str]', ); has 'CountryCode' => ( is => 'rw', isa => 'Maybe[Str]', ); sub _build_address { my ( $self, $xml ) = @_; foreach my $node ( @{ $xml->childNodes } ) { my $name = $node->nodeName; my $value = $node->textContent; next unless $self->can($name); next unless defined $value; $self->$name($value); } return; }
sub serialize { my ($self) = @_; my @address; push (@address,$self->AddressLine1) if $self->AddressLine1; push (@address,$self->AddressLine2) if $self->AddressLine2; push (@address,$self->AddressLine3) if $self->AddressLine3; my $line = $self->CountryCode; $line .= '-'.$self->PostalCode if $self->PostalCode; $line .= ' '.$self->City if $self->City; push (@address,$line); return join("\n",@address); } __PACKAGE__->meta->make_immutable; no Moose; 1;