blib/lib/Games/TF2/Demo/Vector.pm

filter: Statementstmt 100% 92 / 92 Branchbran 100% 6 / 6 Conditioncond 66.6% 12 / 18 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 26 / 26 Podpod 100% 11 / 11 totaltotal 92.6% 151 / 163 CC 10 SCAR 7.5
CC
10
Cov
95%
equals
5.1
times
4.0
_vector_operand
3.0
CRAP 2.1
« blib/lib/Games/TF2/Demo/Error.pm ↑ Summary blib/lib/Games/TF2/Server/Event.pm »
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
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa(__PACKAGE__) 1 3 4
Condition66%2/3
builtin::blessed($other) and $other->isa(__PACKAGE__)
!ll&&!rl&&r
103
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__)
ABresult
0X0
100
111
39 3 ▶ return $x == $other->x && $y == $other->y && $z == $other->z;
Condition66%4/6
$x == $other->x && $y == $other->y && $z == $other->z
!ll&&!rl&&r
201
$x == $other->x and $y == $other->y
!ll&&!rl&&r
201
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
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
unless defined $factor and not ref $factor and &looks_like_number($factor) 1 2 3
Condition66%4/6
defined $factor and not ref $factor and &looks_like_number($factor)
!ll&&!rl&&r
102
defined $factor and not ref $factor
!ll&&!rl&&r
012
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)
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if builtin::blessed($operand) and $operand->isa(__PACKAGE__) 3 2 5
Condition66%2/3
builtin::blessed($operand) and $operand->isa(__PACKAGE__)
!ll&&!rl&&r
203
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__)
ABresult
0X0
100
111
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__
« blib/lib/Games/TF2/Demo/Error.pm ↑ Summary blib/lib/Games/TF2/Server/Event.pm »