| 1 | package Games::TF2::Demo::Vector; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Object::Pad 0.800; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | class Games::TF2::Demo::Vector :strict(params) { | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 12 | ▶ | use Games::TF2::Demo::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | use Scalar::Util qw(blessed looks_like_number); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | '""' => sub ( $self, @ ) { $self->to_string }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | '==' => sub ( $self, $other, @ ) { $self->equals($other) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | '!=' => sub ( $self, $other, @ ) { !$self->equals($other) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | '+' => sub ( $self, $other, @ ) { $self->plus($other) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | '-' => sub ( $self, $other, @ ) { $self->minus($other) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | '*' => sub ( $self, $factor, @ ) { $self->times($factor) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 12 | fallback => undef; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | field $x :param :reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | field $y :param :reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
y: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | field $z :param :reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
z: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | method to_string () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | return "($x, $y, $z)"; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | method to_array () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_array: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | return ( $x, $y, $z ); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | method equals ($other) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equals: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | return !!0 unless blessed($other) && $other->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($other) and $other->isa(__PACKAGE__)
MC/DC50%1/2
builtin::blessed($other) and $other->isa(__PACKAGE__)
builtin::blessed($other)
$other->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= builtin::blessed($other)B= $other->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | ▶ | return $x == $other->x && $y == $other->y && $z == $other->z; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$x == $other->x && $y == $other->y && $z == $other->z
$x == $other->x and $y == $other->y
MC/DC33%1/3
$x == $other->x && $y == $other->y && $z == $other->z
$x == $other->x
$y == $other->y
$z == $other->z
Truth table50%2/4
A and B && C
A= $x == $other->xB= $y == $other->yC= $z == $other->z
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | method plus ($other) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plus: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | my ( $other_x, $other_y, $other_z ) = _vector_operand( $other, '+' )->to_array; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | return __CLASS__->new( x => $x + $other_x, y => $y + $other_y, z => $z + $other_z ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | method minus ($other) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
minus: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | my ( $other_x, $other_y, $other_z ) = _vector_operand( $other, '-' )->to_array; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | return __CLASS__->new( x => $x - $other_x, y => $y - $other_y, z => $z - $other_z ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | method times ($factor) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
times: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | ▶ | Games::TF2::Demo::Error::Argument->throw( message => 'Games::TF2::Demo::Vector: * needs a number' ) unless defined $factor && !ref $factor && looks_like_number($factor); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $factor and not ref $factor and &looks_like_number($factor)
defined $factor and not ref $factor
MC/DC33%1/3
defined $factor and not ref $factor and &looks_like_number($factor)
defined $factor
not ref $factor
&looks_like_number($factor)
Truth table50%2/4
A and not(B) and C
A= defined $factorB= not ref $factorC= &looks_like_number($factor)
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | return __CLASS__->new( x => $x * $factor, y => $y * $factor, z => $z * $factor ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | method length () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
length: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | return sqrt( $x * $x + $y * $y + $z * $z ); | |||||||||||||||||||||||||||||||||||||||||
| 59 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | method distance ($other) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
distance: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | return $self->minus($other)->length; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | ▶ | sub _vector_operand ( $operand, $operator ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_vector_operand: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | ▶ | return $operand if blessed($operand) && $operand->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($operand) and $operand->isa(__PACKAGE__)
MC/DC50%1/2
builtin::blessed($operand) and $operand->isa(__PACKAGE__)
builtin::blessed($operand)
$operand->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= builtin::blessed($operand)B= $operand->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | Games::TF2::Demo::Error::Argument->throw( message => "Games::TF2::Demo::Vector: $operator needs another vector" ); | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||||||||||||||||