| 1 | package Box::Calc::Role::Container; | ||||||||||||||||||||
| 2 | 11 | $Box::Calc::Role::Container::VERSION = '1.0205'; | |||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 11 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 11 | 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.0205 | ||||||||||||||||||||
| 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 | 11 | 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 | 11 | 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 | 11 | 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 | |||||||||||||||||||||
| 64 | sub outer_volume { | ||||||||||||||||||||
| 65 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
outer_volume: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 66 | 0 | return $self->outer_x * $self->outer_y * $self->outer_z; | |||||||||||||||||||
| 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 | sub outer_dimensions { | ||||||||||||||||||||
| 76 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
outer_dimensions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 77 | 2 | return [ $self->outer_x, $self->outer_y, $self->outer_z, ]; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =head2 outer_extent | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | Returns a string of C<outer_x,outer_y,outer_z>. Good for comparing whether two items are dimensionally similar. | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | sub outer_extent { | ||||||||||||||||||||
| 88 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
outer_extent: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 89 | 0 | return join ',', $self->outer_x, $self->outer_y, $self->outer_z; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =head2 max_weight | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | The max weight of the items including the container. Defaults to 1000. | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 11 | has max_weight => ( | |||||||||||||||||||
| 99 | is => 'ro', | ||||||||||||||||||||
| 100 | isa => 'Num', | ||||||||||||||||||||
| 101 | default => 1000, | ||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | around BUILDARGS => sub { | ||||||||||||||||||||
| 105 | 78 | ▶ | my $orig = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||
| 106 | 78 | my $className = shift; | |||||||||||||||||||
| 107 | 78 | my $args; | |||||||||||||||||||
| 108 | 78 | ▶ | if (ref $_[0] eq 'HASH') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 109 | 26 | $args = shift; | |||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||
| 112 | 52 | $args = { @_ }; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 78 | ▶ | $args->{outer_x} ||= $args->{x}; | ||||||||||||||||||
|
Condition66%2/3
$args->{"outer_x"} ||= $args->{"x"}
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"}
| |||||||||||||||||||||
| 116 | 78 | ▶ | $args->{outer_y} ||= $args->{y}; | ||||||||||||||||||
|
Condition66%2/3
$args->{"outer_y"} ||= $args->{"y"}
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"}
| |||||||||||||||||||||
| 117 | 78 | ▶ | $args->{outer_z} ||= $args->{z}; | ||||||||||||||||||
|
Condition66%2/3
$args->{"outer_z"} ||= $args->{"z"}
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"}
| |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | # sort large to small | ||||||||||||||||||||
| 120 | 78 | my ( $x, $y, $z ) = sort { $b <=> $a } ( $args->{outer_x}, $args->{outer_y}, $args->{outer_z} ); | |||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 78 | $args->{outer_x} = $x; | |||||||||||||||||||
| 123 | 78 | $args->{outer_y} = $y; | |||||||||||||||||||
| 124 | 78 | $args->{outer_z} = $z; | |||||||||||||||||||
| 125 | 78 | return $className->$orig($args); | |||||||||||||||||||
| 126 | 11 | }; | |||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 11 | 1; | |||||||||||||||||||