line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Box::Calc::Row; |
2
|
|
|
|
|
|
|
$Box::Calc::Row::VERSION = '1.0200'; |
3
|
12
|
|
|
12
|
|
1000
|
use strict; |
|
12
|
|
|
|
|
24
|
|
|
12
|
|
|
|
|
309
|
|
4
|
12
|
|
|
12
|
|
83
|
use Moose; |
|
12
|
|
|
|
|
24
|
|
|
12
|
|
|
|
|
79
|
|
5
|
12
|
|
|
12
|
|
74574
|
use Box::Calc::Item; |
|
12
|
|
|
|
|
40725
|
|
|
12
|
|
|
|
|
407
|
|
6
|
12
|
|
|
12
|
|
80
|
use List::Util qw/sum/; |
|
12
|
|
|
|
|
22
|
|
|
12
|
|
|
|
|
875
|
|
7
|
12
|
|
|
12
|
|
8926
|
use Log::Any qw($log); |
|
12
|
|
|
|
|
147935
|
|
|
12
|
|
|
|
|
51
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Box::Calc::Row - The smallest organizational unit in a box. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
version 1.0200 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $row = Box::Calc::Row->new(max_x => 6); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 METHODS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 new(params) |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Constructor. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=item max_x |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
The maximimum width of the row. This is equivalent to the C<x> or longest dimension of the containing box. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=back |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 fill_weight() |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Returns the weight of the items in this row. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has fill_weight => ( |
42
|
|
|
|
|
|
|
is => 'rw', |
43
|
|
|
|
|
|
|
default => 0, |
44
|
|
|
|
|
|
|
isa => 'Num', |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 fill_x() |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Returns how full the row is in the C<x> dimension. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has fill_x => ( |
54
|
|
|
|
|
|
|
is => 'rw', |
55
|
|
|
|
|
|
|
default => 0, |
56
|
|
|
|
|
|
|
isa => 'Num', |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 fill_y() |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Returns how full the row is in the C<y> dimension. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
has fill_y => ( |
66
|
|
|
|
|
|
|
is => 'rw', |
67
|
|
|
|
|
|
|
default => 0, |
68
|
|
|
|
|
|
|
isa => 'Num', |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 fill_z() |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Returns how full the row is in the C<z> dimension. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
has fill_z => ( |
78
|
|
|
|
|
|
|
is => 'rw', |
79
|
|
|
|
|
|
|
default => 0, |
80
|
|
|
|
|
|
|
isa => 'Num', |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 max_x() |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Returns the maximum C<x> dimension of this row. See C<new> for details. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
has max_x => ( |
90
|
|
|
|
|
|
|
is => 'ro', |
91
|
|
|
|
|
|
|
required => 1, |
92
|
|
|
|
|
|
|
isa => 'Num', |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 items() |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Returns an array reference of items contained in this row. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 count_items() |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Returns the number of items contained in this row. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
has items => ( |
106
|
|
|
|
|
|
|
is => 'rw', |
107
|
|
|
|
|
|
|
isa => 'ArrayRef[Box::Calc::Item]', |
108
|
|
|
|
|
|
|
default => sub { [] }, |
109
|
|
|
|
|
|
|
traits => ['Array'], |
110
|
|
|
|
|
|
|
handles => { |
111
|
|
|
|
|
|
|
count_items => 'count', |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 calculate_weight() |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Calculates the weight of all the items in this row, and returns that value. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub calculate_weight { |
122
|
3937
|
|
|
3937
|
1
|
4791
|
my $self = shift; |
123
|
3937
|
|
|
|
|
114859
|
return $self->fill_weight; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 pack_item(item) |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Places an item into the row, and updates all the relevant statistics about the row. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Returns 1 on success or 0 on failure. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=over |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item item |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
A L<Box::Calc::Item> instance. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=back |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub pack_item { |
143
|
20859
|
|
|
20859
|
1
|
34981
|
my ($self, $item) = @_; |
144
|
20859
|
100
|
|
|
|
618478
|
if ($item->x > $self->max_x - $self->fill_x) { |
145
|
3560
|
|
|
|
|
18960
|
$log->info('No room in row for '.$item->{name}.', requesting new row.'); |
146
|
3560
|
|
|
|
|
63399
|
return 0; |
147
|
|
|
|
|
|
|
} |
148
|
17299
|
|
|
|
|
35750
|
push @{$self->items}, $item; |
|
17299
|
|
|
|
|
477720
|
|
149
|
17299
|
|
|
|
|
502365
|
$self->fill_weight($self->fill_weight + $item->weight); |
150
|
17299
|
|
|
|
|
499598
|
$self->fill_x($self->fill_x + $item->x); |
151
|
17299
|
100
|
|
|
|
521290
|
$self->fill_y($item->y) if $item->y > $self->fill_y; |
152
|
17299
|
100
|
|
|
|
517883
|
$self->fill_z($item->z) if $item->z > $self->fill_z; |
153
|
17299
|
|
|
|
|
60249
|
return 1; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 packing_list(weight, list) |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Updates a scalar reference with the weight of the row and a hash reference of all the items in this row. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub packing_list { |
164
|
1949
|
|
|
1949
|
1
|
3763
|
my ($self, $weight, $list) = @_; |
165
|
1949
|
|
|
|
|
1907
|
foreach my $item (@{$self->items}) { |
|
1949
|
|
|
|
|
52064
|
|
166
|
10418
|
|
|
|
|
11467
|
${$weight} += $item->weight; |
|
10418
|
|
|
|
|
311015
|
|
167
|
10418
|
|
|
|
|
271659
|
$list->{$item->name}++; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 packing_instructions() |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns a hash reference of items contained in this row via the C<describe> method, and other important info about the row. Example: |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
{ |
176
|
|
|
|
|
|
|
items => [ ... ], |
177
|
|
|
|
|
|
|
x => 3, |
178
|
|
|
|
|
|
|
y => 2, |
179
|
|
|
|
|
|
|
z => 2 |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub packing_instructions { |
185
|
1964
|
|
|
1964
|
1
|
2201
|
my $self = shift; |
186
|
|
|
|
|
|
|
return { |
187
|
1964
|
|
|
|
|
2187
|
items => [map { $_->describe } @{ $self->items }], |
|
10448
|
|
|
|
|
24493
|
|
|
1964
|
|
|
|
|
51386
|
|
188
|
|
|
|
|
|
|
fill_x => $self->fill_x, |
189
|
|
|
|
|
|
|
fill_y => $self->fill_y, |
190
|
|
|
|
|
|
|
fill_z => $self->fill_z, |
191
|
|
|
|
|
|
|
calculated_weight => $self->calculate_weight, |
192
|
|
|
|
|
|
|
}; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub used_volume { |
196
|
1960
|
|
|
1960
|
0
|
2428
|
my $self = shift; |
197
|
1960
|
|
|
|
|
2043
|
return sum map { $_->volume } @{ $self->items }; |
|
10442
|
|
|
|
|
323595
|
|
|
1960
|
|
|
|
|
53338
|
|
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub volume { |
201
|
0
|
|
|
0
|
0
|
|
return $_[0]->fill_x * $_[0]->fill_y * $_[0]->fill_z; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
12
|
|
|
12
|
|
60994
|
no Moose; |
|
12
|
|
|
|
|
74
|
|
|
12
|
|
|
|
|
127
|
|
205
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |