line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Box::Calc::Role::Dimensional; |
2
|
|
|
|
|
|
|
$Box::Calc::Role::Dimensional::VERSION = '1.0200'; |
3
|
14
|
|
|
14
|
|
10078
|
use strict; |
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
358
|
|
4
|
14
|
|
|
14
|
|
67
|
use warnings; |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
398
|
|
5
|
14
|
|
|
14
|
|
4615
|
use Moose::Role; |
|
14
|
|
|
|
|
44957
|
|
|
14
|
|
|
|
|
70
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Box::Calc::Role::Dimensional - Role to add standard dimensions to objects. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
version 1.0200 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head2 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
The x, y, and z attributes are first sorted from largest to smallest before creating the object. So you can insert them in any order. x=3, y=9, z=1 would become x=r9, y=3, z=1. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#----------# |
21
|
|
|
|
|
|
|
| | |
22
|
|
|
|
|
|
|
| | |
23
|
|
|
|
|
|
|
| Y | |
24
|
|
|
|
|
|
|
| | |
25
|
|
|
|
|
|
|
| | |
26
|
|
|
|
|
|
|
| X | |
27
|
|
|
|
|
|
|
#----------# |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Z is from bottom up |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This role installs these methods: |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 x |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Returns the largest side of an object. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has x => ( |
43
|
|
|
|
|
|
|
is => 'rw', |
44
|
|
|
|
|
|
|
required => 1, |
45
|
|
|
|
|
|
|
isa => 'Num', |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 y |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Returns the middle side of an object. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has y => ( |
55
|
|
|
|
|
|
|
is => 'rw', |
56
|
|
|
|
|
|
|
required => 1, |
57
|
|
|
|
|
|
|
isa => 'Num', |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 z |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Returns the shortest side of an object. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has z => ( |
67
|
|
|
|
|
|
|
is => 'rw', |
68
|
|
|
|
|
|
|
required => 1, |
69
|
|
|
|
|
|
|
isa => 'Num', |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 weight |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Returns the weight of an object. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has weight => ( |
79
|
|
|
|
|
|
|
is => 'ro', |
80
|
|
|
|
|
|
|
isa => 'Num', |
81
|
|
|
|
|
|
|
required => 1, |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 volume |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Returns the result of multiplying x, y, and z. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
has volume => ( |
91
|
|
|
|
|
|
|
is => 'ro', |
92
|
|
|
|
|
|
|
isa => 'Num', |
93
|
|
|
|
|
|
|
required => 1, |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 dimensions |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Returns an array reference containing x, y, and z. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
has dimensions => ( |
103
|
|
|
|
|
|
|
is => 'ro', |
104
|
|
|
|
|
|
|
isa => 'ArrayRef', |
105
|
|
|
|
|
|
|
required => 1, |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 extent |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Returns a string of C<x,y,z>. Good for comparing whether two items are dimensionally similar. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
has extent => ( |
115
|
|
|
|
|
|
|
is => 'ro', |
116
|
|
|
|
|
|
|
isa => 'Str', |
117
|
|
|
|
|
|
|
required => 1, |
118
|
|
|
|
|
|
|
); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
around BUILDARGS => sub { |
121
|
|
|
|
|
|
|
my $orig = shift; |
122
|
|
|
|
|
|
|
my $className = shift; |
123
|
|
|
|
|
|
|
my $args; |
124
|
|
|
|
|
|
|
if (ref $_[0] eq 'HASH') { |
125
|
|
|
|
|
|
|
$args = shift; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
else { |
128
|
|
|
|
|
|
|
$args = { @_ }; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# sort large to small |
132
|
|
|
|
|
|
|
my ( $x, $y, $z ); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
if ( $args->{no_sort} ) { |
135
|
|
|
|
|
|
|
( $x, $y, $z ) = ( $args->{x}, $args->{y}, $args->{z} ); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
elsif ( $args->{swap_xy} ) { |
138
|
|
|
|
|
|
|
( $x, $y, $z ) = sort { $b <=> $a } ( $args->{x}, $args->{y}, $args->{z} ); |
139
|
|
|
|
|
|
|
( $x, $y ) = ( $y, $x ); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
else { |
142
|
|
|
|
|
|
|
( $x, $y, $z ) = sort { $b <=> $a } ( $args->{x}, $args->{y}, $args->{z} ); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$args->{x} = $x; |
146
|
|
|
|
|
|
|
$args->{y} = $y; |
147
|
|
|
|
|
|
|
$args->{z} = $z; |
148
|
|
|
|
|
|
|
$args->{volume} = $x * $y * $z; |
149
|
|
|
|
|
|
|
$args->{dimensions} = [$x, $y, $z]; |
150
|
|
|
|
|
|
|
$args->{extent} = join(',', $x, $y, $z); |
151
|
|
|
|
|
|
|
return $className->$orig($args); |
152
|
|
|
|
|
|
|
}; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |