| Business-UPS-Tracking documentation | Contained in the Business-UPS-Tracking distribution. |
Business::UPS::Tracking::Commandline - Commandline interface to UPS tracking
my $commandline = Business::UPS::Tracking::Commandline->new_with_options; # Params are taken from @ARGV $commandline->execute;
This class allows Business::UPS::Tracking being called from a commandline script using MooseX::Getopt. (See ups_tracking)
All accessors from Business::UPS::Tracking::Request
Be verbose
UPS tracking service access license number
UPS account username
UPS account password
Optionally you can retrieve all or some UPS webservice credentials from a
configuration file. This accessor holds the path to this file.
Defaults to ~/.ups_tracking
Example configuration file:
<?xml version="1.0"?>
<UPS_tracing_webservice_config>
<AccessLicenseNumber>1CFFED5A5E91B17</AccessLicenseNumber>
<UserId>myupsuser</UserId>
<Password>secret</Password>
</UPS_tracing_webservice_config>
$commandline->execute;
Performs a UPS webservice query/request.
| Business-UPS-Tracking documentation | Contained in the Business-UPS-Tracking distribution. |
# ============================================================================ package Business::UPS::Tracking::Commandline; # ============================================================================ use utf8; use 5.0100; use Moose; extends qw(Business::UPS::Tracking::Request); with qw(MooseX::Getopt Business::UPS::Tracking::Role::Base); __PACKAGE__->meta->error_class("Business::UPS::Tracking::Exception"); our $VERSION = $Business::UPS::Tracking::VERISON;
has 'tracking' => ( is => 'rw', required => 0, isa => 'Business::UPS::Tracking', traits => [ 'NoGetopt' ], lazy_build => 1, ); has 'verbose' => ( is => 'rw', isa => 'Bool', documentation => 'Be verbose', ); MooseX::Getopt::OptionTypeMap->add_option_type_to_map( 'Business::UPS::Tracking::Type::TrackingNumber' => '=s', 'Business::UPS::Tracking::Type::CountryCode' => '=s', ); __PACKAGE__->meta->make_immutable; sub execute { my $self = shift; my $response = $self->run(); my $count = 1; foreach my $shipment (@{$response->shipment}) { say ".============================================================================."; say "| Shipment $count |"; say $shipment->serialize->draw; say ""; if ($self->verbose) { say $shipment->xml->toString(1); } $count ++; } } sub _build_tracking { my ($self) = @_; my %params = (); foreach my $field (qw(AccessLicenseNumber UserId Password)) { my $predicate = '_has_'.$field; if ($self->$predicate) { $params{$field} = $self->$field; } } return Business::UPS::Tracking->new(\%params); } __PACKAGE__->meta->make_immutable; no Moose; 1;