$Box::Calc::Row::VERSION
=
'1.0206'
;
has
fill_weight
=> (
is
=>
'rw'
,
default
=> 0,
isa
=>
'Num'
,
);
has
fill_x
=> (
is
=>
'rw'
,
default
=> 0,
isa
=>
'Num'
,
);
has
fill_y
=> (
is
=>
'rw'
,
default
=> 0,
isa
=>
'Num'
,
);
has
fill_z
=> (
is
=>
'rw'
,
default
=> 0,
isa
=>
'Num'
,
);
has
max_x
=> (
is
=>
'ro'
,
required
=> 1,
isa
=>
'Num'
,
);
has
items
=> (
is
=>
'rw'
,
isa
=>
'ArrayRef[Box::Calc::Item]'
,
default
=>
sub
{ [] },
traits
=> [
'Array'
],
handles
=> {
count_items
=>
'count'
,
}
);
sub
calculate_weight {
my
$self
=
shift
;
return
$self
->fill_weight;
}
sub
pack_item {
my
(
$self
,
$item
) =
@_
;
if
(
$item
->x >
$self
->max_x -
$self
->fill_x) {
$log
->info(
'No room in row for '
.
$item
->{name}.
', requesting new row.'
);
return
0;
}
push
@{
$self
->items},
$item
;
$self
->fill_weight(
$self
->fill_weight +
$item
->weight);
$self
->fill_x(
$self
->fill_x +
$item
->x);
$self
->fill_y(
$item
->y)
if
$item
->y >
$self
->fill_y;
$self
->fill_z(
$item
->z)
if
$item
->z >
$self
->fill_z;
return
1;
}
sub
packing_list {
my
(
$self
,
$weight
,
$list
) =
@_
;
foreach
my
$item
(@{
$self
->items}) {
${
$weight
} +=
$item
->weight;
$list
->{
$item
->name}++;
}
}
sub
packing_instructions {
my
$self
=
shift
;
return
{
items
=> [
map
{
$_
->describe } @{
$self
->items }],
fill_x
=>
$self
->fill_x,
fill_y
=>
$self
->fill_y,
fill_z
=>
$self
->fill_z,
calculated_weight
=>
$self
->calculate_weight,
};
}
sub
used_volume {
my
$self
=
shift
;
return
sum
map
{
$_
->volume } @{
$self
->items };
}
sub
volume {
return
$_
[0]->fill_x *
$_
[0]->fill_y *
$_
[0]->fill_z;
}
no
Moose;
__PACKAGE__->meta->make_immutable;