line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Shipment::Generic; |
2
|
|
|
|
|
|
|
$Shipment::Generic::VERSION = '0.18'; |
3
|
1
|
|
|
1
|
|
15041
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
875
|
use Moose 2.0000; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'Shipment::Base'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _build_services { |
13
|
|
|
|
|
|
|
{ generic => Shipment::Service->new( |
14
|
|
|
|
|
|
|
id => 'generic', |
15
|
|
|
|
|
|
|
name => 'Generic Service', |
16
|
|
|
|
|
|
|
), |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub rate { |
22
|
|
|
|
|
|
|
my ($self, $service_id, $rate) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$service_id ||= 'generic'; |
25
|
|
|
|
|
|
|
$rate ||= 0; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Data::Currency; |
28
|
|
|
|
|
|
|
use Shipment::Service; |
29
|
|
|
|
|
|
|
$self->service( |
30
|
|
|
|
|
|
|
new Shipment::Service( |
31
|
|
|
|
|
|
|
id => $service_id, |
32
|
|
|
|
|
|
|
name => $service_id, |
33
|
|
|
|
|
|
|
cost => Data::Currency->new($rate, $self->currency), |
34
|
|
|
|
|
|
|
) |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub ship { |
41
|
|
|
|
|
|
|
my ($self, $service_id, $tracking_id, $rate) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->rate($service_id, $rate); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
if (!$tracking_id) { |
46
|
|
|
|
|
|
|
foreach (@{$self->packages}) { |
47
|
|
|
|
|
|
|
$tracking_id = $_->tracking_id if $_->tracking_id; |
48
|
|
|
|
|
|
|
last if $_->tracking_id; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$tracking_id ||= 'n/a'; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$self->tracking_id($tracking_id); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
use Shipment::Label; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
foreach (@{$self->packages}) { |
59
|
|
|
|
|
|
|
$_->tracking_id($tracking_id) if !$_->tracking_id; |
60
|
|
|
|
|
|
|
$_->label( |
61
|
|
|
|
|
|
|
Shipment::Label->new( |
62
|
|
|
|
|
|
|
{ tracking_id => $_->tracking_id, |
63
|
|
|
|
|
|
|
content_type => 'text/plain', |
64
|
|
|
|
|
|
|
data => qq| |
65
|
|
|
|
|
|
|
FROM: |
66
|
|
|
|
|
|
|
| . $self->from_address->name . qq| |
67
|
|
|
|
|
|
|
| . $self->from_address->company . qq| |
68
|
|
|
|
|
|
|
| . $self->from_address->address1 . qq| |
69
|
|
|
|
|
|
|
| . $self->from_address->address2 . qq| |
70
|
|
|
|
|
|
|
| |
71
|
|
|
|
|
|
|
. $self->from_address->city . qq|, | |
72
|
|
|
|
|
|
|
. $self->from_address->province_code . qq| | |
73
|
|
|
|
|
|
|
. $self->from_address->postal_code . qq| |
74
|
|
|
|
|
|
|
| . $self->from_address->country_code . qq| |
75
|
|
|
|
|
|
|
| . $self->from_address->phone . qq| |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
TO: |
78
|
|
|
|
|
|
|
| . $self->to_address->name . qq| |
79
|
|
|
|
|
|
|
| . $self->to_address->company . qq| |
80
|
|
|
|
|
|
|
| . $self->to_address->address1 . qq| |
81
|
|
|
|
|
|
|
| . $self->to_address->address2 . qq| |
82
|
|
|
|
|
|
|
| |
83
|
|
|
|
|
|
|
. $self->to_address->city . qq|, | |
84
|
|
|
|
|
|
|
. $self->to_address->province_code . qq| | |
85
|
|
|
|
|
|
|
. $self->to_address->postal_code . qq| |
86
|
|
|
|
|
|
|
| . $self->to_address->country_code . qq| |
87
|
|
|
|
|
|
|
| . $self->to_address->phone . qq| |
88
|
|
|
|
|
|
|
|, |
89
|
|
|
|
|
|
|
file_name => $_->tracking_id . '.txt', |
90
|
|
|
|
|
|
|
}, |
91
|
|
|
|
|
|
|
) |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub cancel { |
99
|
|
|
|
|
|
|
my $self = shift; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return 'success'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
no Moose; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=pod |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=encoding UTF-8 |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 NAME |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Shipment::Generic |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 VERSION |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
version 0.18 |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SYNOPSIS |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This module does not DO a whole lot, |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
use Shipment::Generic; |
128
|
|
|
|
|
|
|
use Shipment::Address; |
129
|
|
|
|
|
|
|
use Shipment::Package; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my $shipment = Shipment::Generic->new( |
132
|
|
|
|
|
|
|
from_address => Shipment::Address->new( ... ), |
133
|
|
|
|
|
|
|
to_address => Shipment::Address->new( ... ), |
134
|
|
|
|
|
|
|
packages => [ Shipment::Package->new( ... ), ], |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$shipment->rate( 'ground' ); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$shipment->ship( 'ground' ); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 NAME |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Shipment::Generic - a very Generic shipping interface |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 ABOUT |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This class provides a Generic interface for a shipping service. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 Class Attributes |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This class does not override or provide any additional attributes. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 Class Methods |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 _build_services |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This routine simply adds a single "generic" service |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 rate |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This routine populates $self->service |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
It optionally accepts the cost passed as the second argument |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$shipment->rate( 'ground', '12.34 ); |
166
|
|
|
|
|
|
|
print $shipment->service->cost . "\n"; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 ship |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This routine sets $self->tracking_id and calls $self->rate |
171
|
|
|
|
|
|
|
Also sets a label for each package |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
$shipment->ship( 'ground', '123456789', '12.32' ); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
TODO: create generic thermal, pdf, and png labels so that we can do: |
176
|
|
|
|
|
|
|
$shipment->get_package(0)->label->save; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 cancel |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This routine really does nothing but return 'success' |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
$shipment->tracking_id( '12345' ); |
183
|
|
|
|
|
|
|
$shipment->cancel; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AUTHOR |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Andrew Baerg @ <andrew at pullingshots dot ca> |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
http://pullingshots.ca/ |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 BUGS |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Please contact me directly. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 COPYRIGHT |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Copyright (C) 2010 Andrew J Baerg, All Rights Reserved |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 NO WARRANTY |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Absolutely, positively NO WARRANTY, neither express or implied, is |
202
|
|
|
|
|
|
|
offered with this software. You use this software at your own risk. In |
203
|
|
|
|
|
|
|
case of loss, no person or entity owes you anything whatsoever. You |
204
|
|
|
|
|
|
|
have been warned. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 LICENSE |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
209
|
|
|
|
|
|
|
under the same terms as Perl itself. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 AUTHOR |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Andrew Baerg <baergaj@cpan.org> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Andrew Baerg. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
220
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=cut |