line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Box::Calc::Row; |
2
|
|
|
|
|
|
|
$Box::Calc::Row::VERSION = '1.0206'; |
3
|
14
|
|
|
14
|
|
854
|
use strict; |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
394
|
|
4
|
14
|
|
|
14
|
|
61
|
use Moose; |
|
14
|
|
|
|
|
60
|
|
|
14
|
|
|
|
|
79
|
|
5
|
14
|
|
|
14
|
|
83801
|
use Box::Calc::Item; |
|
14
|
|
|
|
|
57786
|
|
|
14
|
|
|
|
|
680
|
|
6
|
14
|
|
|
14
|
|
171
|
use List::Util qw/sum/; |
|
14
|
|
|
|
|
35
|
|
|
14
|
|
|
|
|
1052
|
|
7
|
14
|
|
|
14
|
|
7112
|
use Log::Any qw($log); |
|
14
|
|
|
|
|
100064
|
|
|
14
|
|
|
|
|
88
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Box::Calc::Row - The smallest organizational unit in a box. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
version 1.0206 |
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
|
11639
|
|
|
11639
|
1
|
14641
|
my $self = shift; |
123
|
11639
|
|
|
|
|
216786
|
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
|
53702
|
|
|
53702
|
1
|
119628
|
my ($self, $item) = @_; |
144
|
53702
|
100
|
|
|
|
1129859
|
if ($item->x > $self->max_x - $self->fill_x) { |
145
|
8804
|
|
|
|
|
66919
|
$log->info('No room in row for '.$item->{name}.', requesting new row.'); |
146
|
8804
|
|
|
|
|
57018
|
return 0; |
147
|
|
|
|
|
|
|
} |
148
|
44898
|
|
|
|
|
81075
|
push @{$self->items}, $item; |
|
44898
|
|
|
|
|
933406
|
|
149
|
44898
|
|
|
|
|
956742
|
$self->fill_weight($self->fill_weight + $item->weight); |
150
|
44898
|
|
|
|
|
885060
|
$self->fill_x($self->fill_x + $item->x); |
151
|
44898
|
100
|
|
|
|
932642
|
$self->fill_y($item->y) if $item->y > $self->fill_y; |
152
|
44898
|
100
|
|
|
|
922206
|
$self->fill_z($item->z) if $item->z > $self->fill_z; |
153
|
44898
|
|
|
|
|
153150
|
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
|
5800
|
|
|
5800
|
1
|
9199
|
my ($self, $weight, $list) = @_; |
165
|
5800
|
|
|
|
|
5875
|
foreach my $item (@{$self->items}) { |
|
5800
|
|
|
|
|
106189
|
|
166
|
31158
|
|
|
|
|
31830
|
${$weight} += $item->weight; |
|
31158
|
|
|
|
|
610613
|
|
167
|
31158
|
|
|
|
|
549480
|
$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
|
5815
|
|
|
5815
|
1
|
6700
|
my $self = shift; |
186
|
|
|
|
|
|
|
return { |
187
|
5815
|
|
|
|
|
6429
|
items => [map { $_->describe } @{ $self->items }], |
|
31188
|
|
|
|
|
57535
|
|
|
5815
|
|
|
|
|
109663
|
|
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
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 used_volume |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Returns the real used volume for this row. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 volume |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Returns the exact volume needed for this row. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub used_volume { |
207
|
5811
|
|
|
5811
|
1
|
6693
|
my $self = shift; |
208
|
5811
|
|
|
|
|
5927
|
return sum map { $_->volume } @{ $self->items }; |
|
31182
|
|
|
|
|
52734
|
|
|
5811
|
|
|
|
|
107151
|
|
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub volume { |
212
|
0
|
|
|
0
|
1
|
|
return $_[0]->fill_x * $_[0]->fill_y * $_[0]->fill_z; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
14
|
|
|
14
|
|
35385
|
no Moose; |
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
119
|
|
216
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |