lib/TUI/Objects/Point.pm

filter: Statementstmt 74.7% 77 / 103 Branchbran 37.5% 6 / 16 Conditioncond 58.3% 7 / 12 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 80.7% 21 / 26 Podpod 90.9% 10 / 11 totaltotal 69.3% 122 / 176 CC 14 SCAR 10.0
CC
14
Cov
69%
subtract
6.0
add_assign
6.0
subtract_assign
6.0
CRAP 2.7
« lib/TUI/Gadgets/ClickTester.pm ↑ Summary lib/TUI/Objects/Rect.pm »
1 package TUI::Objects::Point;
2 # ABSTRACT: defines the class TPoint
3
4 104 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 104 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 104 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 104 our $VERSION = '2.000002';
9 104 $VERSION =~ tr/_//d;
10 104 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 104 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 104 our @EXPORT = qw(
14 TPoint
15 new_TPoint
16 );
17
18 104 ▶use Devel::StrictMode;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 104 ▶use if STRICT => 'Hash::Util';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 104 ▶use TUI::toolkit qw( :utils );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 104 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 :is
23 :types
24 104 );
25
26 sub TPoint() { __PACKAGE__ }
27 1 ▶sub new_TPoint { __PACKAGE__->from(@_) }
Subroutine new_TPoint: called CC=1 SCAR=0.0
Pod documented
28
29 # public attributes
30 104 ▶our %HAS; BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
31 %HAS = (
32 249 ▶ x => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
33 249 ▶ y => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 104 );
35 }
36
37 415 ▶sub new { # \$obj (%args)
Subroutine new: called CC=3 SCAR=11.1
Pod documented
38 415 state $sig = signature(
39 method => 1,
40 named => [
41 x => Int, { optional => 1 },
42 y => Int, { optional => 1 },
43 ],
44 );
45 415 my ( $class, $args ) = $sig->( @_ );
46 my $self = {
47 x => $args->{x} // $HAS{x}->(),
48 415 ▶ y => $args->{y} // $HAS{y}->(),
Condition66%4/6
$args->{"x"} // $TUI::Objects::Point::HAS{"x"}->()
l!l&&r!l&&!r
1662490
$args->{"y"} // $TUI::Objects::Point::HAS{"y"}->()
l!l&&r!l&&!r
1662490
MC/DC0%0/2
$args->{"x"} // $TUI::Objects::Point::HAS{"x"}->()
$args->{"x"} $TUI::Objects::Point::HAS{"x"}->()
MC/DC0%0/2
$args->{"y"} // $TUI::Objects::Point::HAS{"y"}->()
$args->{"y"} $TUI::Objects::Point::HAS{"y"}->()
Truth table66%2/3
A // B
A= $args->{"x"}B= $TUI::Objects::Point::HAS{"x"}->()
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $args->{"y"}B= $TUI::Objects::Point::HAS{"y"}->()
ABresult
1X1
011
000
49 };
50 415 bless $self, $class;
51 415 Hash::Util::lock_keys( %$self ) if STRICT;
52 415 return $self;
53 }
54
55 1 ▶sub from { # $obj ($x, $y)
Subroutine from: called CC=1 SCAR=0.0
Pod undocumented
56 1 state $sig = signature(
57 method => 1,
58 pos => [Int, Int],
59 );
60 1 my ( $class, @args ) = $sig->( @_ );
61 1 return $class->new( x => $args[0], y => $args[1] );
62 }
63
64 15 ▶sub clone { # $p ()
Subroutine clone: called CC=2 SCAR=7.4
Pod documented
65 15 state $sig = signature(
66 method => 1,
67 pos => [],
68 );
69 15 my ( $self ) = $sig->( @_ );
70 15 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
1500
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
71 15 return $class->new( %$self );
72 }
73
74 0 ▶sub dump { # $str ()
Subroutine dump: not called CC=1 SCAR=6.9
Pod documented
75 0 state $sig = signature(
76 method => Object,
77 pos => [],
78 );
79 0 my ( $self ) = $sig->( @_ );
80 0 require Data::Dumper;
81 0 local $Data::Dumper::Sortkeys = 1;
82 0 return Data::Dumper::Dumper $self;
83 }
84
85 0 ▶sub add { # $p ($one, $two, |$swap)
Subroutine add: not called CC=1 SCAR=6.9
Pod documented
86 0 state $sig = signature(
87 pos => [HashLike, HashLike, Bool, { optional => 1 }],
88 );
89 0 my ( $one, $two, $swap ) = $sig->( @_ );
90 0 return TPoint->new( x => $one->{x} + $two->{x}, y => $one->{y} + $two->{y} );
91 }
92
93 0 ▶sub subtract { # $p ($one, $two, |$swap)
Subroutine subtract: not called CC=2 SCAR=17.9
Pod documented
94 0 state $sig = signature(
95 pos => [HashLike, HashLike, Bool, { optional => 1 }],
96 );
97 0 my ( $one, $two, $swap ) = $sig->( @_ );
98 0 ▶ ( $one, $two ) = ( $two, $one ) if $swap;
Branch: 1 branch
BranchTrueFalseTotal
if $swap 0 0 0
99 0 return TPoint->new( x => $one->{x} - $two->{x}, y => $one->{y} - $two->{y} );
100 }
101
102 5 ▶sub equal { # $bool ($one, $two, |$swap)
Subroutine equal: called CC=2 SCAR=7.0
Pod documented
103 5 state $sig = signature(
104 pos => [HashLike, HashLike, Bool, { optional => 1 }],
105 );
106 5 my ( $one, $two, $swap ) = $sig->( @_ );
107 5 ▶ return $one->{x} == $two->{x} && $one->{y} == $two->{y};
Condition66%2/3
$one->{'x'} == $two->{'x'} && $one->{'y'} == $two->{'y'}
!ll&&!rl&&r
104
MC/DC50%1/2
$one->{'x'} == $two->{'x'} && $one->{'y'} == $two->{'y'}
$one->{'x'} == $two->{'x'} $one->{'y'} == $two->{'y'}
Truth table66%2/3
A && B
A= $one->{'x'} == $two->{'x'}B= $one->{'y'} == $two->{'y'}
ABresult
0X0
100
111
108 }
109
110 3 ▶sub not_equal { # $bool ($one, $two, |$swap)
Subroutine not_equal: called CC=1 SCAR=0.0
Pod documented
111 3 state $sig = signature(
112 pos => [HashLike, HashLike, Bool, { optional => 1 }],
113 );
114 3 my ( $one, $two, $swap ) = $sig->( @_ );
115 3 return !equal( $one, $two );
116 }
117
118 0 ▶sub add_assign { # $self ($adder, |$wap)
Subroutine add_assign: not called CC=2 SCAR=17.9
Pod documented
119 0 state $sig = signature(
120 method => Object,
121 pos => [HashLike, Bool, { optional => 1 }],
122 );
123 0 my ( $self, $adder, $swap ) = $sig->( @_ );
124 0 ▶ assert ( not $swap );
Branch: 1 branch
BranchTrueFalseTotal
if $swap 0 0 0
125 0 $self->{x} += $adder->{x};
126 0 $self->{y} += $adder->{y};
127 0 return $self;
128 }
129
130 0 ▶sub subtract_assign { # $self ($subber, |$wap)
Subroutine subtract_assign: not called CC=2 SCAR=17.9
Pod documented
131 0 state $sig = signature(
132 method => Object,
133 pos => [HashLike, Bool, { optional => 1 }],
134 );
135 0 my ( $self, $subber, $swap ) = $sig->( @_ );
136 0 ▶ assert ( not $swap );
Branch: 1 branch
BranchTrueFalseTotal
if $swap 0 0 0
137 0 $self->{x} -= $subber->{x};
138 0 $self->{y} -= $subber->{y};
139 0 return $self;
140 }
141
142 use overload
143 104 ▶ '+' => \&add,
Subroutine BEGIN: called CC=1 SCAR=0.0
144 '-' => \&subtract,
145 '==' => \&equal,
146 '!=' => \&not_equal,
147 '+=' => \&add_assign,
148 '-=' => \&subtract_assign,
149 104 fallback => 1;
150
151 104 ▶my $mk_accessors = sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
152 104 my ( $pkg ) = @_;
153 104 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 104 104
154 104 ▶ assert ( defined $pkg );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg 0 104 104
155 104 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
156 104 my %HAS = %{"${pkg}::HAS"};
157 104 for my $field ( keys %HAS ) {
158 208 my $full_name = "${pkg}::$field";
159 24 ▶ *$full_name = sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
160 24 ▶ assert ( is_Object $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($_[0]) 0 24 24
161 24 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 2 22 24
162 2 ▶ assert ( is_Int $_[1] );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($_[1]) 0 2 2
163 2 $_[0]->{$field} = $_[1];
164 }
165 24 $_[0]->{$field};
166 208 };
167 } #/ for my $field ( keys %HAS)
168 104 }; #/ $mk_accessors = sub
169
170 104 __PACKAGE__->$mk_accessors();
171
172 104 1
173
174 __END__
« lib/TUI/Gadgets/ClickTester.pm ↑ Summary lib/TUI/Objects/Rect.pm »