line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::TrackUPS; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
50020
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1432
|
use HTTP::Request; |
|
1
|
|
|
|
|
46414
|
|
|
1
|
|
|
|
|
40
|
|
9
|
1
|
|
|
1
|
|
1194
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
41858
|
|
|
1
|
|
|
|
|
51
|
|
10
|
1
|
|
|
1
|
|
616
|
use XML::Simple qw(XMLin); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
|
|
|
|
|
|
my $class = shift; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
bless { |
16
|
|
|
|
|
|
|
# Production Tracking URL, this can be overridden. |
17
|
|
|
|
|
|
|
URI => 'https://www.ups.com/ups.app/xml/Track', |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# This URL should be used for testing and integration |
20
|
|
|
|
|
|
|
# URI => 'https://wwwcie.ups.com/ups.app/xml/Track', |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
@_, |
23
|
|
|
|
|
|
|
}, ref($class) || $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub track { |
27
|
|
|
|
|
|
|
my ($self, $number) = @_; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $req = HTTP::Request->new( |
30
|
|
|
|
|
|
|
'POST', $self->URI, undef, $self->_req_xml($number), |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
my $resp = $self->_ua->request($req); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
unless ($resp->is_success) { |
35
|
|
|
|
|
|
|
die "Connection error: " . $resp->status_line; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
XMLin($resp->content); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _ua { |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
my %opts; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
if ('HASH' eq ref($self->{lwp_options})) { |
46
|
|
|
|
|
|
|
%opts = %{$self->{lwp_options}}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
LWP::UserAgent->new( |
50
|
|
|
|
|
|
|
agent => ref($self) . '/' . $self->VERSION, |
51
|
|
|
|
|
|
|
%opts, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _req_xml { |
56
|
|
|
|
|
|
|
my ($self, $tracking_number) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Simple but effective way of constructing XML requests. |
59
|
|
|
|
|
|
|
my $xml=<<'XML'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
%s |
63
|
|
|
|
|
|
|
%s |
64
|
|
|
|
|
|
|
%s |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Track |
70
|
|
|
|
|
|
|
%s |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
%s |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
XML |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sprintf($xml, $self->access_key, $self->ID, $self->password, $self->request_option, $tracking_number); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Auto-generate accessors/mutators: |
80
|
|
|
|
|
|
|
for my $method (qw(URI ID password access_key request_option)) { |
81
|
|
|
|
|
|
|
no strict 'refs'; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
*{$method} = sub { |
84
|
|
|
|
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
if (@_) { |
86
|
|
|
|
|
|
|
$self->{$method} = shift; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
return $self->{$method}; |
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |