File Coverage

blib/lib/Business/UPS/Tracking/Element/Weight.pm
Criterion Covered Total %
statement 17 26 65.3
branch n/a
condition n/a
subroutine 6 9 66.6
pod 1 2 50.0
total 24 37 64.8


line stmt bran cond sub pod time code
1             # ============================================================================
2             package Business::UPS::Tracking::Element::Weight;
3             # ============================================================================
4 1     1   4 use utf8;
  1         41  
  1         6  
5 1     1   48 use 5.0100;
  1         3  
6              
7 1     1   4 use Moose;
  1         1  
  1         8  
8              
9 1     1   4709 use Business::UPS::Tracking::Utils;
  1         2  
  1         21  
10 1     1   411 use Business::UPS::Tracking::Element::Code;
  1         2  
  1         180  
11              
12             =encoding utf8
13              
14             =head1 NAME
15              
16             Business::UPS::Tracking::Element::Weight - A shipment or package weight
17            
18             =head1 DESCRIPTION
19              
20             This class represents a declaration of weight. Usually it is created
21             automatically from a L<Business::UPS::Tracking::Shipment> object.
22              
23             This module uses overload for stringification if called in string context.
24              
25             =head1 ACCESSORS
26              
27             =head2 xml
28              
29             Original L<XML::LibXML::Node> node.
30              
31             =head2 UnitOfMeasurement
32              
33             Unit of measurement.
34             Returns a L<Business::UPS::Tracking::Element::Code> object.
35              
36             =head2 Weight
37              
38             Weight value (e.g. '5.50')
39              
40             =cut
41              
42             has 'xml' => (
43             is => 'rw',
44             isa => 'XML::LibXML::Node',
45             required => 1,
46             trigger => \&_build_weight,
47             );
48             has 'UnitOfMeasurement'=> (
49             is => 'rw',
50             isa => 'Business::UPS::Tracking::Element::Code',
51             lazy_build => 1,
52             );
53             has 'Weight'=> (
54             is => 'rw',
55             isa => 'Num',
56             );
57              
58             sub _build_weight {
59 0     0     my ($self,$xml) = @_;
60            
61 0           my $unit = Business::UPS::Tracking::Element::Code->new(
62             xml => $xml->findnodes('UnitOfMeasurement')->get_node(1)
63             );
64              
65 0           $self->UnitOfMeasurement($unit);
66 0           $self->Weight($xml->findvalue('Weight'));
67            
68 0           return;
69             }
70              
71             sub serialize {
72 0     0 0   my ($self) = @_;
73            
74 0           return $self->printall;
75             }
76              
77             =head1 METHODS
78              
79             =head2 printall
80              
81             Returns the weight as a string (eg. '14.5 KGS')
82              
83             =head2 meta
84              
85             Moose meta method
86              
87             =cut
88              
89             sub printall {
90 0     0 1   my ($self) = @_;
91 0           return $self->Weight.' '.$self->UnitOfMeasurement->Code;
92             }
93              
94             __PACKAGE__->meta->make_immutable;
95 1     1   7 no Moose;
  1         1  
  1         5  
96             1;