Business::Shipping::USPS_Online::Shipment - Business::Shipping::USPS_Online::Shipment documentation


Business-Shipping documentation Contained in the Business-Shipping distribution.

Index


Code Index:

NAME

Top

Business::Shipping::USPS_Online::Shipment

DESCRIPTION

Top

See Business::Shipping POD for usage information.

METHODS

Top

pounds

ounces

weight

container

size

machinable

mail_type

width

height

length

girth

from_country

Always returns 'US'.

to_country( $to_country )

Uses the name translaters of Shipping::Shipment::to_country(), then applies its own translations. The former may not be necessary, but the latter is.

packages_push

Syntatic sugar to avoid push @{$self->packages()}, $new_package;

AUTHOR

Top

Daniel Browning, db@kavod.com, http://www.kavod.com/

COPYRIGHT AND LICENCE

Top


Business-Shipping documentation Contained in the Business-Shipping distribution.
package Business::Shipping::USPS_Online::Shipment;

use Any::Moose;
use Business::Shipping::Logging;
use Business::Shipping::Config;
use Business::Shipping::Util;
use Business::Shipping::USPS_Online::Package;
use version; our $VERSION = qv('400');
extends 'Business::Shipping::Shipment';

has 'packages' => (
    is         => 'rw',
    isa        => 'ArrayRef[Business::Shipping::USPS_Online::Package]',
    default    => sub { [Business::Shipping::USPS_Online::Package->new()] },
    auto_deref => 1,
);

has 'max_weight' => (is => 'rw', default => 70);
has 'service' => (is => 'rw');
has '_to_country' => (is => 'rw');

sub BUILD {
    $_[0]->from_country('US');
    return;
}

__PACKAGE__->meta()->make_immutable();

# Can't use 'handles', because the ArrayRef itself doesn't actually handle
# anything, it's the objects inside it that do.

foreach my $attribute (
    qw/
    pounds
    ounces
    weight
    container
    size
    machinable
    mail_type
    width
    height
    length
    girth
    /
    )
{
    eval "sub $attribute { return shift->package0->$attribute( \@_ ); }";
}

sub from_country { return 'US'; }

sub to_country {

    #trace '( ' . uneval( \@_ ) . ' )';
    my ($self, $to_country) = @_;

    if (defined $to_country) {

        #
        # Apply any Shipping::Shipment conversions, then apply our own.
        #
        $to_country = $self->SUPER::to_country($to_country);
        my $countries = config_to_hash(
            cfg()->{usps_information}->{usps_country_name_translations});
        $to_country = $countries->{$to_country} || $to_country;

        trace("setting to_country to \'$to_country\'");
        $self->_to_country($to_country);
    }
    trace("SUPER::to_country now is " . ($self->SUPER::to_country() || ''));

    return $self->_to_country();
}

sub packages_push {
    my ($self, $new_package) = @_;
    push @{ $self->packages() }, $new_package;
    return;
}

1;

__END__