line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ============================================================================ |
2
|
|
|
|
|
|
|
package Business::UPS::Tracking::Commandline; |
3
|
|
|
|
|
|
|
# ============================================================================ |
4
|
1
|
|
|
1
|
|
1989
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
5
|
1
|
|
|
1
|
|
43
|
use 5.0100; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
466
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends qw(Business::UPS::Tracking::Request); |
9
|
|
|
|
|
|
|
with qw(MooseX::Getopt Business::UPS::Tracking::Role::Base); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=encoding utf8 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Business::UPS::Tracking::Commandline - Commandline interface to UPS tracking |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $commandline = Business::UPS::Tracking::Commandline->new_with_options; |
20
|
|
|
|
|
|
|
# Params are taken from @ARGV |
21
|
|
|
|
|
|
|
$commandline->execute; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This class allows Business::UPS::Tracking being called from a commandline |
26
|
|
|
|
|
|
|
script using L<MooseX::Getopt>. (See L<ups_tracking>) |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 ACCESSORS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 Inherited |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
All accessors from L<Business::UPS::Tracking::Request> |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 verbose |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Be verbose |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 AccessLicenseNumber |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
UPS tracking service access license number |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 UserId |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
UPS account username |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 Password |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
UPS account password |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 config |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Optionally you can retrieve all or some UPS webservice credentials from a |
53
|
|
|
|
|
|
|
configuration file. This accessor holds the path to this file. |
54
|
|
|
|
|
|
|
Defaults to C<~/.ups_tracking> |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Example configuration file: |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
<?xml version="1.0"?> |
59
|
|
|
|
|
|
|
<UPS_tracking_webservice_config> |
60
|
|
|
|
|
|
|
<AccessLicenseNumber>1CFFED5A5E91B17</AccessLicenseNumber> |
61
|
|
|
|
|
|
|
<UserId>myupsuser</UserId> |
62
|
|
|
|
|
|
|
<Password>secret</Password> |
63
|
|
|
|
|
|
|
</UPS_tracking_webservice_config> |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 METHODS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head3 execute |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$commandline->execute; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Performs a UPS webservice query/request. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
has 'tracking' => ( |
76
|
|
|
|
|
|
|
is => 'rw', |
77
|
|
|
|
|
|
|
required => 0, |
78
|
|
|
|
|
|
|
isa => 'Business::UPS::Tracking', |
79
|
|
|
|
|
|
|
traits => [ 'NoGetopt' ], |
80
|
|
|
|
|
|
|
lazy_build => 1, |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
has 'verbose' => ( |
84
|
|
|
|
|
|
|
is => 'rw', |
85
|
|
|
|
|
|
|
isa => 'Bool', |
86
|
|
|
|
|
|
|
documentation => 'Be verbose', |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
MooseX::Getopt::OptionTypeMap->add_option_type_to_map( |
90
|
|
|
|
|
|
|
'Business::UPS::Tracking::Type::TrackingNumber' => '=s', |
91
|
|
|
|
|
|
|
'Business::UPS::Tracking::Type::CountryCode' => '=s', |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub execute { |
97
|
|
|
|
|
|
|
my $self = shift; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $response = $self->run(); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $count = 1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
foreach my $shipment (@{$response->shipment}) { |
104
|
|
|
|
|
|
|
say ".============================================================================."; |
105
|
|
|
|
|
|
|
say "| Shipment $count |"; |
106
|
|
|
|
|
|
|
say $shipment->printall->draw; |
107
|
|
|
|
|
|
|
say ""; |
108
|
|
|
|
|
|
|
if ($self->verbose) { |
109
|
|
|
|
|
|
|
say $shipment->xml->toString(1); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
$count ++; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
return; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _build_tracking { |
118
|
|
|
|
|
|
|
my ($self) = @_; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my %params = (); |
121
|
|
|
|
|
|
|
foreach my $field (qw(AccessLicenseNumber UserId Password)) { |
122
|
|
|
|
|
|
|
my $predicate = '_has_'.$field; |
123
|
|
|
|
|
|
|
if ($self->$predicate) { |
124
|
|
|
|
|
|
|
$params{$field} = $self->$field; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
return Business::UPS::Tracking->new(\%params); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
132
|
|
|
|
|
|
|
no Moose; |
133
|
|
|
|
|
|
|
1; |