$VERSION
=
do
{
my
$r
=
q$Rev: 164 $
;
$r
=~ /\d+/; $&; };
use
base (
'Business::Shipping::Package'
);
[
new
=> [ {
-hash
=> 1,
-init
=>
'this_init'
},
'new'
],
scalar
=> [ {
-default
=>
'None'
},
'container'
],
scalar
=> [ {
-default
=>
'Regular'
},
'size'
],
scalar
=> [ {
-default
=>
'False'
},
'machinable'
],
scalar
=> [ {
-default
=>
'Package'
},
'mail_type'
],
scalar
=> [ {
-default
=>
'0.00'
},
'ounces'
],
scalar
=> [ {
-default
=>
'0.00'
},
'pounds'
],
scalar
=> [
{
-static
=> 1,
-default
=>
'container, size, machinable, mail_type, pounds, '
.
'ounces'
},
'Optional'
],
scalar
=> [
{
-static
=> 1,
-default
=>
'container, size, machinable, mail_type'
},
'Unique'
]
];
sub
this_init {
$_
[ 0 ]->shipper(
'USPS'
); }
sub
Required
{
my
(
$self
) =
@_
;
for
(
qw( weight pounds ounces )
) {
if
(
$self
->
$_
) {
return
''
;
}
}
return
'weight'
;
}
sub
weight
{
my
(
$self
,
$in_weight
) =
@_
;
trace(
'('
. uneval( \
@_
) .
')'
);
if
(
$in_weight
) {
if
(
$in_weight
< 1.00 ) {
$in_weight
= 1.00;
}
$self
->set_lbs_oz(
$in_weight
);
}
my
$out_weight
=
$self
->lbs_oz_to_weight;
return
$out_weight
;
}
sub
set_lbs_oz
{
my
(
$self
,
$in_weight
) =
@_
;
my
$pounds
= 0;
my
$ounces
= 0;
$pounds
=
$self
->_round_up(
$in_weight
);
my
$remainder
=
$pounds
-
$in_weight
;
$remainder
= -
$remainder
if
$remainder
< 0;
if
(
$remainder
) {
$ounces
=
$remainder
* 16;
$ounces
=
sprintf
(
"%1.0f"
,
$ounces
);
}
$self
->pounds(
$pounds
);
$self
->ounces(
$ounces
);
return
;
}
sub
lbs_oz_to_weight
{
my
(
$self
) =
@_
;
trace
'()'
;
my
$pounds
=
$self
->pounds || 0;
my
$ounces
=
$self
->ounces || 0;
my
$fractional_pounds
=
$ounces
?
sprintf
(
"%1.0f"
,
$ounces
/ 16 ) : 0;
my
$weight
= (
$pounds
+
$fractional_pounds
);
return
$weight
;
}
sub
_round_up
{
my
(
$self
,
$f
) =
@_
;
return
undef
unless
defined
$f
;
return
sprintf
(
"%1.0f"
,
$f
);
}
1;