File Coverage

blib/lib/Business/UPS/Tracking/Element/Activity.pm
Criterion Covered Total %
statement 20 49 40.8
branch n/a
condition n/a
subroutine 7 14 50.0
pod 1 1 100.0
total 28 64 43.7


line stmt bran cond sub pod time code
1             # ============================================================================
2             package Business::UPS::Tracking::Element::Activity;
3             # ============================================================================
4 1     1   7 use utf8;
  1         3  
  1         8  
5 1     1   38 use 5.0100;
  1         4  
6              
7 1     1   20 use Moose;
  1         3  
  1         6  
8             with qw(Business::UPS::Tracking::Role::Print
9             Business::UPS::Tracking::Role::Builder);
10              
11 1     1   6731 no if $] >= 5.017004, warnings => qw(experimental::smartmatch);
  1         3  
  1         14  
12              
13 1     1   80 use Business::UPS::Tracking::Utils;
  1         2  
  1         19  
14 1     1   6 use Business::UPS::Tracking::Element::Activity;
  1         2  
  1         400  
15              
16             =encoding utf8
17              
18             =head1 NAME
19              
20             Business::UPS::Tracking::Element::Activity - A small freight package activity
21              
22             =head1 DESCRIPTION
23              
24             This class represents an small freight package activity. Usually it is created
25             automatically from a L<Business::UPS::Tracking::Element::Package> object.
26              
27             =head1 ACCESSORS
28              
29             =head2 xml
30              
31             Original L<XML::LibXML::Node> node.
32              
33             =head2 ActivityLocationAddress
34              
35             A L<Business::UPS::Tracking::Element::Address> object representing the
36             location of the activity.
37              
38             =head2 ActivityLocation
39              
40             Type of location.
41             Returns a L<Business::UPS::Tracking::Element::Code> object.
42              
43             =head2 SignedForByName
44              
45             =head2 StatusCode
46              
47             =head2 StatusType
48              
49             Status code.
50             Returns a L<Business::UPS::Tracking::Element::Code> object.
51              
52             =head2 DateTime
53              
54             L<DateTime> object.
55              
56             =cut
57              
58             has 'xml' => (
59             is => 'ro',
60             isa => 'XML::LibXML::Node',
61             required => 1,
62             );
63              
64             has 'ActivityLocationAddress' => (
65             is => 'ro',
66             isa => 'Maybe[Business::UPS::Tracking::Element::Address]',
67             traits => ['Printable'],
68             documentation => 'Address',
69             lazy_build => 1,
70             );
71             has 'ActivityLocation' => (
72             is => 'ro',
73             isa => 'Maybe[Business::UPS::Tracking::Element::Code]',
74             traits => ['Printable'],
75             lazy_build => 1,
76             );
77             has 'SignedForByName' => (
78             is => 'ro',
79             isa => 'Maybe[Str]',
80             traits => ['Printable'],
81             lazy_build => 1,
82             documentation => 'Signed by',
83             );
84             has 'StatusCode' => (
85             is => 'ro',
86             isa => 'Maybe[Str]',
87             lazy_build => 1,
88             traits => ['Printable'],
89             documentation => 'Satus code',
90             );
91             # MP ... Billing information
92             # OR ... Original scan
93             # DP ... Departure scan
94             # AR ... Arival scan
95             # LC ... Location scan
96             # KS/KR ... Annahmeverweigerung
97             # KM/KB ... Anlieferung (Bounce?)
98             # 48 ... Failed 1st atempt
99             # KX ... Failed 2nd atempt
100             # 49 ... Failed 3rd atempt
101             # UL ... Unload scan
102              
103             has 'StatusType' => (
104             is => 'ro',
105             isa => 'Maybe[Business::UPS::Tracking::Element::Code]',
106             traits => ['Printable'],
107             lazy_build => 1,
108             documentation => 'Status',
109             );
110             has 'DateTime' => (
111             is => 'ro',
112             isa => 'Maybe[Business::UPS::Tracking::Type::Date]',
113             traits => ['Printable'],
114             lazy_build => 1,
115             documentation => 'Date/time',
116             );
117              
118             sub _build_DateTime {
119 0     0     my ($self) = @_;
120              
121 0           my $datestr = $self->xml->findvalue('Date');
122 0           my $date = Business::UPS::Tracking::Utils::parse_date($datestr);
123              
124 0           my $timestr = $self->xml->findvalue('Time');
125 0           return Business::UPS::Tracking::Utils::parse_time( $timestr, $date );
126             }
127              
128             sub _build_StatusType {
129 0     0     my ($self) = @_;
130              
131 0           return $self->build_code('Status/StatusType');
132             }
133              
134             sub _build_StatusCode {
135 0     0     my ($self) = @_;
136              
137 0           return $self->xml->findvalue('Status/StatusCode/Code');
138             }
139              
140             sub _build_ActivityLocationAddress {
141 0     0     my ($self) = @_;
142              
143 0           return $self->build_address('ActivityLocation/Address' );
144             }
145              
146             sub _build_ActivityLocation {
147 0     0     my ($self) = @_;
148              
149 0           return $self->build_code('ActivityLocation' );
150             }
151              
152             sub _build_SignedForByName {
153 0     0     my ($self) = @_;
154              
155 0           return $self->xml->findvalue('ActivityLocation/SignedForByName');
156             }
157              
158             =head1 METHODS
159              
160             =head2 Status
161              
162             Translates the L<StatusTypeCode> to a short description. Can return
163              
164             =over
165              
166             =item * In Transit
167              
168             =item * Delivered
169              
170             =item * Exeption
171              
172             =item * Pickup
173              
174             =item * Manifest Pickup
175              
176             =item * Unknown
177              
178             =back
179              
180             =cut
181              
182             sub Status {
183 0     0 1   my ($self) = @_;
184              
185 0           given ($self->StatusType->Code) {
186 0           when ('I') {
187 0           return 'In Transit';
188             }
189 0           when ('D') {
190 0           return 'Delivered';
191             }
192 0           when ('X') {
193 0           return 'Exeption';
194             }
195 0           when ('P') {
196 0           return 'Pickup';
197             }
198 0           when ('M') {
199 0           return 'Manifest Pickup';
200             }
201 0           default {
202 0           return 'Unknown';
203             }
204             }
205             }
206              
207             =head2 meta
208              
209             Moose meta method
210              
211             =cut
212              
213             __PACKAGE__->meta->make_immutable;
214 1     1   6 no Moose;
  1         2  
  1         6  
215             1;