Calc/Role/Container.pm

filter: Statementstmt 100% 38 / 38 Branchbran 100% 2 / 2 Conditioncond 66.6% 6 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 84.7% 50 / 59 SCAR 16.1
CC
5
Cov
94%
__ANON__
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.0
« Calc/Box.pm ↑ Summary Calc/Row.pm »
1 package Box::Calc::Role::Container;
2 10 $Box::Calc::Role::Container::VERSION = '1.0201';
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 with 'Box::Calc::Role::Dimensional';
7  
8 =head1 NAME
9  
10 Box::Calc::Role::Container - Extends the L<Box::Calc::Role::Dimensional> role to include outer dimensions.
11  
12  
13 =head1 VERSION
14  
15 version 1.0201
16  
17 =head1 METHODS
18  
19 This role installs these methods:
20  
21 =head2 outer_x
22  
23 Returns the outside dimension of largest side of an object.
24  
25 =cut
26  
27 10 has outer_x => (
28 is => 'rw',
29 isa => 'Num',
30 required => 1,
31 );
32  
33 =head2 outer_y
34  
35 Returns the outside dimension of the middle side of an object.
36  
37 =cut
38  
39 10 has outer_y => (
40 is => 'rw',
41 isa => 'Num',
42 required => 1,
43 );
44  
45 =head2 outer_z
46  
47 Returns the outside dimension of the shortest side of an object.
48  
49 =cut
50  
51 10 has outer_z => (
52 is => 'rw',
53 isa => 'Num',
54 required => 1,
55 );
56  
57 =head2 outer_volume
58  
59 Returns the result of multiplying outer_x, outer_y, and outer_z.
60  
61 =cut
62  
63 10 has outer_volume => (
64 is => 'ro',
65 isa => 'Num',
66 required => 1,
67 );
68  
69 =head2 outer_dimensions
70  
71 Returns an array reference containing outer_x, outer_y, and outer_z.
72  
73 =cut
74  
75 10 has outer_dimensions => (
76 is => 'ro',
77 isa => 'ArrayRef',
78 required => 1,
79 );
80  
81 =head2 outer_extent
82  
83 Returns a string of C<outer_x,outer_y,outer_z>. Good for comparing whether two items are dimensionally similar.
84  
85 =cut
86  
87 10 has outer_extent => (
88 is => 'ro',
89 isa => 'Str',
90 required => 1,
91 );
92  
93 =head2 max_weight
94  
95 The max weight of the items including the container. Defaults to 1000.
96  
97 =cut
98  
99 10 has max_weight => (
100 is => 'ro',
101 isa => 'Num',
102 default => 1000,
103 );
104  
105 around BUILDARGS => sub {
106 64 ▶ my $orig = shift;
Subroutine __ANON__: called CC=5 SCAR=16.1
107 64 my $className = shift;
108 64 my $args;
109 64 ▶ if (ref $_[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 25 39 64
110 25 $args = shift;
111 }
112 else {
113 39 $args = { @_ };
114 }
115  
116 64 ▶ $args->{outer_x} ||= $args->{x};
Condition66%2/3
$args->{"outer_x"} ||= $args->{"x"}
l!l&&r!l&&!r
32320
MC/DC0%0/2
$args->{"outer_x"} ||= $args->{"x"}
$args->{"outer_x"} $args->{"x"}
Truth table66%2/3
A ||= B
A= $args->{"outer_x"}B= $args->{"x"}
ABresult
1X1
011
000
117 64 ▶ $args->{outer_y} ||= $args->{y};
Condition66%2/3
$args->{"outer_y"} ||= $args->{"y"}
l!l&&r!l&&!r
32320
MC/DC0%0/2
$args->{"outer_y"} ||= $args->{"y"}
$args->{"outer_y"} $args->{"y"}
Truth table66%2/3
A ||= B
A= $args->{"outer_y"}B= $args->{"y"}
ABresult
1X1
011
000
118 64 ▶ $args->{outer_z} ||= $args->{z};
Condition66%2/3
$args->{"outer_z"} ||= $args->{"z"}
l!l&&r!l&&!r
32320
MC/DC0%0/2
$args->{"outer_z"} ||= $args->{"z"}
$args->{"outer_z"} $args->{"z"}
Truth table66%2/3
A ||= B
A= $args->{"outer_z"}B= $args->{"z"}
ABresult
1X1
011
000
119  
120 # sort large to small
121 64 my ( $x, $y, $z ) = sort { $b <=> $a } ( $args->{outer_x}, $args->{outer_y}, $args->{outer_z} );
122
123 64 $args->{outer_x} = $x;
124 64 $args->{outer_y} = $y;
125 64 $args->{outer_z} = $z;
126 64 $args->{outer_volume} = $x * $y * $z;
127 64 $args->{outer_dimensions} = [$x, $y, $z];
128 64 $args->{outer_extent} = join(',', $x, $y, $z);
129 64 return $className->$orig($args);
130 10 };
131  
132 10 1;
« Calc/Box.pm ↑ Summary Calc/Row.pm »