Business::UPS::Tracking::Shipment - Base class for shipments


Business-UPS-Tracking documentation Contained in the Business-UPS-Tracking distribution.

Index


Code Index:

NAME

Top

Business::UPS::Tracking::Shipment - Base class for shipments

DESCRIPTION

Top

This class is a base class for Business::UPS::Tracking::Shipment::SmallPackage and Business::UPS::Tracking::Shipment::Freight. Usually it is created automatically from a Business::UPS::Tracking::Response object. It provides accessors common to all shipment types.

ACCESSORS

Top

xml

XML::LibXML::Node node of the shipment.

ScheduledDelivery

Scheduled delivery date and time. Returns a DateTime object.

PickupDate

Pickup date. Returns a DateTime object.

ShipperNumber

Shipper UPS customer number.

ShipperAddress

Shipper address. Returns a Business::UPS::Tracking::Element::Address object.

ShipmentWeight

Shipment weight. Returns a Business::UPS::Tracking::Element::Weight object.

ShipToAddress

Shipment destination address. Returns a Business::UPS::Tracking::Element::Address object.

Service

Service code and description. Returns a Business::UPS::Tracking::Element::Code object.

ShipmentReferenceNumber

Reference number for the whole shipment as provided by the shipper. Returns a Business::UPS::Tracking::Element::ReferenceNumber object.

METHODS

Top

ShipmentType

Returns the shipment type. Either 'Freight' or 'Small Package'

meta

Moose meta method


Business-UPS-Tracking documentation Contained in the Business-UPS-Tracking distribution.
# ============================================================================
package Business::UPS::Tracking::Shipment;
# ============================================================================
use utf8;
use 5.0100;

use Moose;
__PACKAGE__->meta->error_class("Business::UPS::Tracking::Exception");
with qw(Business::UPS::Tracking::Role::Serialize
    Business::UPS::Tracking::Role::Builder);

use Business::UPS::Tracking::Utils;

our $VERSION = $Business::UPS::Tracking::VERISON;

has 'xml' => (
    is      => 'ro',
    required=> 1,
    isa     => 'XML::LibXML::Node',
);
has 'ScheduledDelivery' => (
    is      => 'ro',
    isa     => 'Maybe[Business::UPS::Tracking::Type::Date]',
    traits  => ['Serializable'],
    lazy_build      => 1,
    documentation   => 'Scheduled delivery date',
);
has 'PickupDate' => (
    is      => 'ro',
    isa     => 'Maybe[Business::UPS::Tracking::Type::Date]',
    traits  => ['Serializable'],
    documentation   => 'Pickup date',
    lazy_build      => 1,
);
has 'ShipperNumber' => (
    is      => 'ro',
    isa     => 'Str',
    traits  => ['Serializable'],
    documentation   => 'Shipper UPS customer number',
    lazy_build      => 1,
);
has 'ShipperAddress' => (
    is      => 'ro',
    isa     => 'Maybe[Business::UPS::Tracking::Element::Address]',
    traits  => ['Serializable'],
    documentation   => 'Shipper address',
    lazy_build      => 1,
);
has 'ShipmentWeight' => (
    is      => 'ro',
    isa     => 'Maybe[Business::UPS::Tracking::Element::Weight]',
    traits  => ['Serializable'],
    documentation => 'Shipment weight',
    lazy_build    => 1,
);
has 'ShipToAddress' => (
    is      => 'ro',
    isa     => 'Maybe[Business::UPS::Tracking::Element::Address]',
    traits  => ['Serializable'],
    documentation   => 'Destination address',
    lazy_build      => 1,
);
has 'Service' => (
    is      => 'ro',
    isa     => 'Maybe[Business::UPS::Tracking::Element::Code]',
    traits  => ['Serializable'],
    documentation   => 'Service',
    lazy_build      => 1,
);
has 'ReferenceNumber' => (
    is      => 'ro',
    isa     => 'Maybe[Business::UPS::Tracking::Element::ReferenceNumber]',
    traits  => ['Serializable'],
    documentation   => 'Reference number',
    lazy_build      => 1,
);
has 'ShipmentIdentificationNumber' => (
    is      => 'ro',
    isa     => 'Str',
    traits  => ['Serializable'],
    documentation   => 'Identification number',
    lazy_build      => 1,
);

sub _build_ScheduledDelivery {
    my ($self) = @_;

    my $datestr = $self->xml->findvalue('ScheduledDeliveryDate');
    my $date    = Business::UPS::Tracking::Utils::parse_date($datestr);

    my $timestr = $self->xml->findvalue('ScheduledDeliveryTime');
    $date = Business::UPS::Tracking::Utils::parse_time( $timestr, $date );

    return $date;
}

sub _build_PickupDate {
    my ($self) = @_;

    my $datestr = $self->xml->findvalue('PickupDate');
    return Business::UPS::Tracking::Utils::parse_date($datestr);
}

sub _build_ShipperNumber {
    my ($self) = @_;
    
    return $self->xml->findvalue('Shipper/ShipperNumber');
}

sub _build_ShipperAddress {
    my ($self) = @_;
    
    return $self->build_address('Shipper/Address');
}

sub _build_ShipmentWeight {
    my ($self) = @_;
    
    return $self->build_weight('ShipmentWeight');
}

sub _build_ShipToAddress {
    my ($self) = @_;
    
    return $self->build_address('ShipTo/Address');
}

sub _build_Service {
    my ($self) = @_;
    
    return $self->build_code('Service');
}

sub _build_ReferenceNumber {
    my ($self) = @_;
    
    return $self->build_referencenumber('ReferenceNumber');
}

sub _build_ShipmentIdentificationNumber {
    my ($self) = @_;

    return $self->xml->findvalue('ShipmentIdentificationNumber')
        || undef;
}

sub ShipmentType {
    Business::UPS::Tracking::X->throw("__PACKAGE__ is an abstract class")
}


__PACKAGE__->meta->make_immutable;
no Moose;
1;