Business::UPS::Tracking::Element::Weight - A shipment or package weight


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

Index


Code Index:

NAME

Top

Business::UPS::Tracking::Element::Weight - A shipment or package weight

DESCRIPTION

Top

This class represents a declaration of weight. Usually it is created automatically from a Business::UPS::Tracking::Shipment object.

This module uses overload for stringification if called in string context.

ACCESSORS

Top

xml

Original XML::LibXML::Node node.

UnitOfMeasurement

Unit of measurement. Returns a Business::UPS::Tracking::Element::Code object.

Weight

Weight value (e.g. '5.50')

METHODS

Top

serialize

Returns the weight as a string (eg. '14.5 KGS')

meta

Moose meta method


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

use Moose;
__PACKAGE__->meta->error_class("Business::UPS::Tracking::Exception");

use Business::UPS::Tracking::Utils;
use Business::UPS::Tracking::Element::Code;

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

has 'xml' => (
    is       => 'rw',
    isa      => 'XML::LibXML::Node',
    required => 1,
    trigger  => \&_build_weight,
);
has 'UnitOfMeasurement'=> (
    is      => 'rw',
    isa     => 'Business::UPS::Tracking::Element::Code',
    lazy_build  => 1,
);
has 'Weight'=> (
    is      => 'rw',
    isa     => 'Num',
);

sub _build_weight {
    my ($self,$xml) = @_;
    
    my $unit = Business::UPS::Tracking::Element::Code->new(
        xml => $xml->findnodes('UnitOfMeasurement')->get_node(1)
    );

    $self->UnitOfMeasurement($unit);
    $self->Weight($xml->findvalue('Weight'));
    
    return;
}

sub serialize {
    my ($self) = @_;
    return $self->Weight.' '.$self->UnitOfMeasurement->Code;
}

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