Sidef/Object/Object.pm

filter: Statementstmt 17.9% 57 / 317 Branchbran 0.0% 0 / 196 Conditioncond 0.0% 0 / 104 MC/DCmcdc 0.0% 0 / 62 Subroutinesub 17.8% 10 / 56 Podpod 100% 28 / 28 totaltotal 12.4% 95 / 763 CC 140 SCAR 64.6
CC
140
Cov
9%
smartmatch
2256.0
__ANON__
420.0
__ANON__
342.0
CRAP 639.5
« Sidef/Deparse/Perl.pm ↑ Summary Sidef/Types/Number/Complex.pm »
1 package Sidef::Object::Object;
2  
3 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Scalar::Util qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Sidef;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Sidef::Types::Bool::Bool;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use parent qw(Sidef::Object::Convert);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 use overload
14 1 ▶ q{bool} => sub {
Subroutine BEGIN: called CC=1 SCAR=6.6
Subroutine __ANON__: not called CC=2 SCAR=17.9
15 0 ▶ if (defined(my $sub = UNIVERSAL::can($_[0], 'to_b'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $sub = UNIVERSAL::can($_[0], "to_b"))) 0 0 0
16 0 @_ = ($_[0]);
17 0 goto $sub;
18 }
19 0 $_[0];
20 },
21 0 ▶ q{0+} => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
22 0 ▶ if (defined(my $sub = UNIVERSAL::can($_[0], 'to_n'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $sub = UNIVERSAL::can($_[0], "to_n"))) 0 0 0
23 0 @_ = ($_[0]);
24 0 goto $sub;
25 }
26 0 $_[0];
27 },
28 0 ▶ q{""} => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
29 0 ▶ if (defined(my $sub = UNIVERSAL::can($_[0], 'to_s'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $sub = UNIVERSAL::can($_[0], "to_s"))) 0 0 0
30 0 @_ = ($_[0]);
31 0 goto $sub;
32 }
33 0 $_[0];
34 },
35 0 ▶ q{cmp} => sub {
Subroutine __ANON__: not called CC=20 SCAR=60.4
36 0 my ($obj1, $obj2, $swapped) = @_;
37  
38 0 ▶ if ($swapped) {
Branch: 1 branch
BranchTrueFalseTotal
if ($swapped) 0 0 0
39 0 ($obj1, $obj2) = ($obj2, $obj1);
40 }
41  
42 # Optimization for identical objects
43 0 ▶ if (CORE::ref($obj1) eq CORE::ref($obj2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::ref $obj1 eq CORE::ref $obj2) 0 0 0
44 0 ▶ if (CORE::ref($obj1) eq 'Sidef::Types::Number::Number') {
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::ref $obj1 eq 'Sidef::Types::Number::Number') { } 0 0 0
elsif (builtin::refaddr($obj1) == builtin::refaddr($obj2)) { } 0 0 0
45 0 ▶ my $r = join(' ', (CORE::ref($$obj1) || 'Scalar'), (CORE::ref($$obj2) || 'Scalar'));
Condition0%0/4
CORE::ref $$obj1 || 'Scalar'
l!l
00
CORE::ref $$obj2 || 'Scalar'
l!l
00
MC/DC0%0/1
CORE::ref $$obj1 || 'Scalar'
CORE::ref $$obj1
MC/DC0%0/1
CORE::ref $$obj2 || 'Scalar'
CORE::ref $$obj2
Truth table0%0/2
A
A= CORE::ref $$obj1
Aresult
11
00
Truth table0%0/2
A
A= CORE::ref $$obj2
Aresult
11
00
46 0 ▶ if ($r eq 'Math::GMPz Math::GMPz') {
Branch: 4 branches
BranchTrueFalseTotal
if ($r eq 'Math::GMPz Math::GMPz') { } 0 0 0
elsif ($r eq 'Scalar Scalar') { } 0 0 0
elsif ($r eq 'Math::GMPz Scalar') { } 0 0 0
elsif ($r eq 'Scalar Math::GMPz') { } 0 0 0
47 0 return Math::GMPz::Rmpz_cmp($$obj1, $$obj2);
48 }
49 elsif ($r eq 'Scalar Scalar') {
50 0 return ($$obj1 <=> $$obj2);
51 }
52 elsif ($r eq 'Math::GMPz Scalar') {
53 return (
54 0 ▶ ($$obj2 < 0)
Branch: 1 branch
BranchTrueFalseTotal
$$obj2 < 0 ? : 0 0 0
55 ? Math::GMPz::Rmpz_cmp_si($$obj1, $$obj2)
56 : Math::GMPz::Rmpz_cmp_ui($$obj1, $$obj2)
57 );
58 }
59 elsif ($r eq 'Scalar Math::GMPz') {
60 return
61 -(
62 0 ▶ ($$obj1 < 0)
Branch: 1 branch
BranchTrueFalseTotal
$$obj1 < 0 ? : 0 0 0
63 ? Math::GMPz::Rmpz_cmp_si($$obj2, $$obj1)
64 : Math::GMPz::Rmpz_cmp_ui($$obj2, $$obj1)
65 );
66 }
67 }
68 elsif (Scalar::Util::refaddr($obj1) == Scalar::Util::refaddr($obj2)) {
69 0 return 0;
70 }
71 }
72  
73 0 ▶ if ( CORE::ref($obj1) eq CORE::ref($obj2)
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::ref $obj1 eq CORE::ref $obj2 or CORE::ref $obj1 and UNIVERSAL::isa($obj1, CORE::ref $obj2) or CORE::ref $obj2 and UNIVERSAL::isa($obj2, CORE::ref $obj1)) 0 0 0
Condition0%0/12
CORE::ref $obj1 eq CORE::ref $obj2 or CORE::ref $obj1 and UNIVERSAL::isa($obj1, CORE::ref $obj2) or CORE::ref $obj2 and UNIVERSAL::isa($obj2, CORE::ref $obj1)
l!l&&r!l&&!r
000
CORE::ref $obj1 eq CORE::ref $obj2 or CORE::ref $obj1 and UNIVERSAL::isa($obj1, CORE::ref $obj2)
l!l&&r!l&&!r
000
CORE::ref $obj1 and UNIVERSAL::isa($obj1, CORE::ref $obj2)
!ll&&!rl&&r
000
CORE::ref $obj2 and UNIVERSAL::isa($obj2, CORE::ref $obj1)
!ll&&!rl&&r
000
MC/DC0%0/5
CORE::ref $obj1 eq CORE::ref $obj2 or CORE::ref $obj1 and UNIVERSAL::isa($obj1, CORE::ref $obj2) or CORE::ref $obj2 and UNIVERSAL::isa($obj2, CORE::ref $obj1)
CORE::ref $obj1 eq CORE::ref $obj2 CORE::ref $obj1 UNIVERSAL::isa($obj1, CORE::ref $obj2) CORE::ref $obj2 UNIVERSAL::isa($obj2, CORE::ref $obj1)
Truth table0%0/8
A or B and C or D and E
A= CORE::ref $obj1 eq CORE::ref $obj2B= CORE::ref $obj1C= UNIVERSAL::isa($obj1, CORE::ref $obj2)D= CORE::ref $obj2E= UNIVERSAL::isa($obj2, CORE::ref $obj1)
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
74 or CORE::ref($obj1) && UNIVERSAL::isa($obj1, CORE::ref($obj2))
75 or CORE::ref($obj2) && UNIVERSAL::isa($obj2, CORE::ref($obj1))) {
76 0 ▶ if (defined(my $sub = UNIVERSAL::can($obj1, '<=>'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $sub = UNIVERSAL::can($obj1, "<=>"))) 0 0 0
77 0 @_ = ($obj1, $obj2);
78 0 goto $sub;
79 }
80 }
81  
82 0 ▶ (CORE::ref($obj1) eq CORE::ref($obj2))
Branch: 1 branch
BranchTrueFalseTotal
CORE::ref $obj1 eq CORE::ref $obj2 ? : 0 0 0
83 ? (Scalar::Util::refaddr($obj1) <=> Scalar::Util::refaddr($obj2))
84 : (CORE::ref($obj1) cmp CORE::ref($obj2));
85 },
86 0 ▶ q{eq} => sub {
Subroutine __ANON__: not called CC=18 SCAR=58.3
87 0 my ($obj1, $obj2) = @_;
88  
89 # Optimization for identical objects
90 0 ▶ if (CORE::ref($obj1) eq CORE::ref($obj2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::ref $obj1 eq CORE::ref $obj2) 0 0 0
91 0 ▶ if (CORE::ref($obj1) eq 'Sidef::Types::Number::Number') {
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::ref $obj1 eq 'Sidef::Types::Number::Number') { } 0 0 0
elsif (builtin::refaddr($obj1) == builtin::refaddr($obj2)) { } 0 0 0
92 0 ▶ my $r = join(' ', (CORE::ref($$obj1) || 'Scalar'), (CORE::ref($$obj2) || 'Scalar'));
Condition0%0/4
CORE::ref $$obj1 || 'Scalar'
l!l
00
CORE::ref $$obj2 || 'Scalar'
l!l
00
MC/DC0%0/1
CORE::ref $$obj1 || 'Scalar'
CORE::ref $$obj1
MC/DC0%0/1
CORE::ref $$obj2 || 'Scalar'
CORE::ref $$obj2
Truth table0%0/2
A
A= CORE::ref $$obj1
Aresult
11
00
Truth table0%0/2
A
A= CORE::ref $$obj2
Aresult
11
00
93 0 ▶ if ($r eq 'Math::GMPz Math::GMPz') {
Branch: 4 branches
BranchTrueFalseTotal
if ($r eq 'Math::GMPz Math::GMPz') { } 0 0 0
elsif ($r eq 'Scalar Scalar') { } 0 0 0
elsif ($r eq 'Math::GMPz Scalar') { } 0 0 0
elsif ($r eq 'Scalar Math::GMPz') { } 0 0 0
94 0 return !Math::GMPz::Rmpz_cmp($$obj1, $$obj2);
95 }
96 elsif ($r eq 'Scalar Scalar') {
97 0 return ($$obj1 == $$obj2);
98 }
99 elsif ($r eq 'Math::GMPz Scalar') {
100 return
101 !(
102 0 ▶ ($$obj2 < 0)
Branch: 1 branch
BranchTrueFalseTotal
$$obj2 < 0 ? : 0 0 0
103 ? Math::GMPz::Rmpz_cmp_si($$obj1, $$obj2)
104 : Math::GMPz::Rmpz_cmp_ui($$obj1, $$obj2)
105 );
106 }
107 elsif ($r eq 'Scalar Math::GMPz') {
108 return
109 !(
110 0 ▶ ($$obj1 < 0)
Branch: 1 branch
BranchTrueFalseTotal
$$obj1 < 0 ? : 0 0 0
111 ? Math::GMPz::Rmpz_cmp_si($$obj2, $$obj1)
112 : Math::GMPz::Rmpz_cmp_ui($$obj2, $$obj1)
113 );
114 }
115 }
116 elsif (Scalar::Util::refaddr($obj1) == Scalar::Util::refaddr($obj2)) {
117 0 return 1;
118 }
119 }
120  
121 #<<<
122 (
123 0 ▶ CORE::ref($obj1) eq CORE::ref($obj2) ||
Branch: 1 branch
BranchTrueFalseTotal
CORE::ref $obj1 eq CORE::ref $obj2 or UNIVERSAL::isa($obj1, CORE::ref $obj2 || (return 0)) or UNIVERSAL::isa($obj2, CORE::ref $obj1 || (return 0)) or return 0 0 0 0
Condition0%0/10
CORE::ref $obj1 eq CORE::ref $obj2 or UNIVERSAL::isa($obj1, CORE::ref $obj2 || (return 0)) or UNIVERSAL::isa($obj2, CORE::ref $obj1 || (return 0))
l!l&&r!l&&!r
000
CORE::ref $obj1 eq CORE::ref $obj2 or UNIVERSAL::isa($obj1, CORE::ref $obj2 || (return 0))
l!l&&r!l&&!r
000
CORE::ref $obj2 || (return 0)
l!l
00
CORE::ref $obj1 || (return 0)
l!l
00
MC/DC0%0/3
CORE::ref $obj1 eq CORE::ref $obj2 or UNIVERSAL::isa($obj1, CORE::ref $obj2 || (return 0)) or UNIVERSAL::isa($obj2, CORE::ref $obj1 || (return 0))
CORE::ref $obj1 eq CORE::ref $obj2 UNIVERSAL::isa($obj1, CORE::ref $obj2 || (return 0)) UNIVERSAL::isa($obj2, CORE::ref $obj1 || (return 0))
MC/DC0%0/1
CORE::ref $obj2 || (return 0)
CORE::ref $obj2
MC/DC0%0/1
CORE::ref $obj1 || (return 0)
CORE::ref $obj1
Truth table0%0/4
A or B or C
A= CORE::ref $obj1 eq CORE::ref $obj2B= UNIVERSAL::isa($obj1, CORE::ref $obj2 || (return 0))C= UNIVERSAL::isa($obj2, CORE::ref $obj1 || (return 0))
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/2
A
A= CORE::ref $obj2
Aresult
11
00
Truth table0%0/2
A
A= CORE::ref $obj1
Aresult
11
00
124 UNIVERSAL::isa($obj1, CORE::ref($obj2) || return 0) ||
125 UNIVERSAL::isa($obj2, CORE::ref($obj1) || return 0)
126 ) || return 0;
127 #>>>
128  
129 0 ▶ if (defined(my $sub = UNIVERSAL::can($obj1, '=='))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $sub = UNIVERSAL::can($obj1, "=="))) 0 0 0
130 0 @_ = ($obj1, $obj2);
131 0 goto $sub;
132 }
133  
134 0 !CORE::int($obj1 cmp $obj2);
135 1 };
136  
137 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
138 0 bless {}, __PACKAGE__;
139 }
140  
141 0 ▶sub say {
Subroutine say: not called CC=2 SCAR=17.9
Pod documented
142 0 ▶ (CORE::say @_)
Branch: 1 branch
BranchTrueFalseTotal
say(@_) ? : 0 0 0
143 ? (Sidef::Types::Bool::Bool::TRUE)
144 : (Sidef::Types::Bool::Bool::FALSE);
145 }
146  
147 1 *println = \&say;
148  
149 0 ▶sub print {
Subroutine print: not called CC=2 SCAR=17.9
Pod documented
150 0 ▶ (CORE::print @_)
Branch: 1 branch
BranchTrueFalseTotal
print(@_) ? : 0 0 0
151 ? (Sidef::Types::Bool::Bool::TRUE)
152 : (Sidef::Types::Bool::Bool::FALSE);
153 }
154  
155 0 ▶sub lazy {
Subroutine lazy: not called CC=1 SCAR=6.9
Pod documented
156 0 my ($self) = @_;
157 0 Sidef::Object::Lazy->new(obj => $self);
158 }
159  
160 0 ▶sub tap {
Subroutine tap: not called CC=1 SCAR=6.9
Pod documented
161 0 my ($self, $block) = @_;
162 0 $block->run($self);
163 0 $self;
164 }
165  
166 0 ▶sub then {
Subroutine then: not called CC=1 SCAR=6.9
Pod documented
167 0 my ($self, $block) = @_;
168 0 $block->run($self);
169 }
170  
171 0 ▶sub in {
Subroutine in: not called CC=1 SCAR=6.9
Pod documented
172 0 my ($self, $collection) = @_;
173 0 $collection->contains($self);
174 }
175  
176 0 ▶sub method {
Subroutine method: not called CC=1 SCAR=6.9
Pod documented
177 0 my ($self, $method, @args) = @_;
178 0 Sidef::Object::LazyMethod->new({obj => $self, method => "$method", args => \@args});
179 }
180  
181 0 ▶sub object_id {
Subroutine object_id: not called CC=1 SCAR=6.9
Pod documented
182 0 my ($self) = @_;
183 0 Sidef::Types::Number::Number::_set_int(Scalar::Util::refaddr($self));
184 }
185  
186 1 *refaddr = \&object_id;
187  
188 0 ▶sub object_type {
Subroutine object_type: not called CC=1 SCAR=6.9
Pod documented
189 0 my ($self) = @_;
190 0 Sidef::Types::String::String->new(Scalar::Util::reftype($self));
191 }
192  
193 1 *reftype = \&object_type;
194  
195 0 ▶sub class {
Subroutine class: not called CC=3 SCAR=24.8
Pod documented
196 0 my ($obj) = @_;
197 0 ▶ my $ref = CORE::ref($obj) || $obj;
Condition0%0/3
CORE::ref $obj || $obj
l!l&&r!l&&!r
000
MC/DC0%0/2
CORE::ref $obj || $obj
CORE::ref $obj $obj
Truth table0%0/3
A || B
A= CORE::ref $objB= $obj
ABresult
1X1
011
000
198  
199 0 my $rindex = rindex($ref, '::');
200 0 ▶ Sidef::Types::String::String->new($rindex == -1 ? $ref : substr($ref, $rindex + 2));
Branch: 1 branch
BranchTrueFalseTotal
$rindex == -1 ? : 0 0 0
201 }
202  
203 0 ▶sub ref {
Subroutine ref: not called CC=2 SCAR=17.9
Pod documented
204 0 my ($obj) = @_;
205 0 ▶ Sidef::Types::String::String->new(CORE::ref($obj) || $obj);
Condition0%0/3
CORE::ref $obj || $obj
l!l&&r!l&&!r
000
MC/DC0%0/2
CORE::ref $obj || $obj
CORE::ref $obj $obj
Truth table0%0/3
A || B
A= CORE::ref $objB= $obj
ABresult
1X1
011
000
206 }
207  
208 0 ▶sub bless {
Subroutine bless: not called CC=2 SCAR=17.9
Pod documented
209 0 my ($obj, $arg) = @_;
210 0 ▶ CORE::bless($arg, (CORE::ref($obj) || $obj));
Condition0%0/3
CORE::ref $obj || $obj
l!l&&r!l&&!r
000
MC/DC0%0/2
CORE::ref $obj || $obj
CORE::ref $obj $obj
Truth table0%0/3
A || B
A= CORE::ref $objB= $obj
ABresult
1X1
011
000
211 }
212  
213 0 ▶sub clone {
Subroutine clone: not called CC=3 SCAR=24.8
Pod documented
214 0 my ($obj) = @_;
215  
216 0 my $class = CORE::ref($obj);
217 0 my $reftype = Scalar::Util::reftype($obj);
218  
219 0 ▶ if ($reftype eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($reftype eq 'HASH') { } 0 0 0
elsif ($reftype eq 'ARRAY') { } 0 0 0
220 0 CORE::bless {%$obj}, $class;
221 }
222 elsif ($reftype eq 'ARRAY') {
223 0 CORE::bless [@$obj], $class;
224 }
225 else {
226 0 $obj;
227 }
228 }
229  
230 0 ▶sub dclone {
Subroutine dclone: not called CC=1 SCAR=6.9
Pod documented
231 0 my %addr; # keeps track of cloned objects
232  
233 0 ▶ sub {
Subroutine __ANON__: not called CC=14 SCAR=53.5
234 0 my ($obj, $reftype) = @_;
235  
236 0 my $refaddr = Scalar::Util::refaddr($obj);
237  
238 exists($addr{$refaddr})
239 0 ▶ and return $addr{$refaddr};
Branch: 1 branch
BranchTrueFalseTotal
exists $addr{$refaddr} and return $addr{$refaddr} 0 0 0
240  
241 0 my $class = Scalar::Util::blessed($obj);
242  
243 0 ▶ if (defined($class) and not UNIVERSAL::isa($class, 'Sidef::Object::Object')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $class and not UNIVERSAL::isa($class, "Sidef::Object::Object")) 0 0 0
Condition0%0/3
defined $class and not UNIVERSAL::isa($class, "Sidef::Object::Object")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $class and not UNIVERSAL::isa($class, "Sidef::Object::Object")
defined $class not UNIVERSAL::isa($class, "Sidef::Object::Object")
Truth table0%0/3
A and not(B)
A= defined $classB= not UNIVERSAL::isa($class, "Sidef::Object::Object")
ABresult
0X0
100
111
244 0 $addr{$refaddr} = $obj;
245 0 return $obj;
246 }
247  
248 0 ▶ if ($reftype eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($reftype eq 'HASH') { } 0 0 0
elsif ($reftype eq 'ARRAY') { } 0 0 0
249 0 ▶ my $o = defined($class) ? CORE::bless({}, $class) : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $class ? : 0 0 0
250 0 $addr{$refaddr} = $o;
251 %$o = (
252 map {
253 0 my $v = $obj->{$_};
254 0 ▶ my $r = Scalar::Util::reftype($v) // '';
Condition0%0/2
builtin::reftype($v) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($v) // ""
builtin::reftype($v)
Truth table0%0/2
A
A= builtin::reftype($v)
Aresult
11
00
255 0 ▶ ($_ => ($r eq 'HASH' || $r eq 'ARRAY' ? __SUB__->($v, $r) : $v))
Branch: 1 branch
BranchTrueFalseTotal
$r eq 'HASH' || $r eq 'ARRAY' ? : 0 0 0
Condition0%0/3
$r eq "HASH" or $r eq "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
$r eq "HASH" or $r eq "ARRAY"
$r eq "HASH" $r eq "ARRAY"
Truth table0%0/3
A or B
A= $r eq "HASH"B= $r eq "ARRAY"
ABresult
1X1
011
000
256 0 } CORE::keys(%{$obj})
257 );
258 0 $o;
259 }
260 elsif ($reftype eq 'ARRAY') {
261 0 ▶ my $o = defined($class) ? CORE::bless([], $class) : [];
Branch: 1 branch
BranchTrueFalseTotal
defined $class ? : 0 0 0
262 0 $addr{$refaddr} = $o;
263 @$o = (
264 map {
265 0 ▶ my $r = Scalar::Util::reftype($_) // '';
Condition0%0/2
builtin::reftype($_) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($_) // ""
builtin::reftype($_)
Truth table0%0/2
A
A= builtin::reftype($_)
Aresult
11
00
266 0 ▶ $r eq 'ARRAY' || $r eq 'HASH' ? __SUB__->($_, $r) : $_
Branch: 1 branch
BranchTrueFalseTotal
$r eq 'ARRAY' || $r eq 'HASH' ? : 0 0 0
Condition0%0/3
$r eq "ARRAY" or $r eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
$r eq "ARRAY" or $r eq "HASH"
$r eq "ARRAY" $r eq "HASH"
Truth table0%0/3
A or B
A= $r eq "ARRAY"B= $r eq "HASH"
ABresult
1X1
011
000
267 0 } @{$obj}
268 );
269 0 $o;
270 }
271 else {
272 0 $obj;
273 }
274 }
275 0 ->($_[0], Scalar::Util::reftype($_[0]));
276 }
277  
278 1 *deep_clone = \&dclone;
279  
280 0 ▶sub respond_to {
Subroutine respond_to: not called CC=3 SCAR=24.8
Pod documented
281 0 my ($self, @methods) = @_;
282  
283 0 foreach my $method (@methods) {
284 0 ▶ UNIVERSAL::can($self, "$method")
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::can($self, "$method") or return bless( do{\(my $o = 0)}, 'Sidef::Types::Bool::Bool' ) 0 0 0
285 || return (Sidef::Types::Bool::Bool::FALSE);
286 }
287  
288 0 (Sidef::Types::Bool::Bool::TRUE);
289 }
290  
291 0 ▶sub is_a {
Subroutine is_a: not called CC=5 SCAR=34.0
Pod documented
292 0 my ($self, @classes) = @_;
293 0 ▶ my $ref = ref($self) || $self;
Condition0%0/3
CORE::ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
CORE::ref $self || $self
CORE::ref $self $self
Truth table0%0/3
A || B
A= CORE::ref $selfB= $self
ABresult
1X1
011
000
294 0 foreach my $class (@classes) {
295 0 ▶ UNIVERSAL::isa($ref, ref($class) ? ref($class) : "$class")
Branch: 2 branches
BranchTrueFalseTotal
UNIVERSAL::isa($ref, CORE::ref $class ? CORE::ref $class : "$class") and return bless( do{\(my $o = 1)}, 'Sidef::Types::Bool::Bool' ) 0 0 0
CORE::ref $class ? : 0 0 0
296 and return Sidef::Types::Bool::Bool::TRUE;
297 }
298 0 Sidef::Types::Bool::Bool::FALSE;
299 }
300  
301 1 *is_an = \&is_a;
302 1 *kind_of = \&is_a;
303  
304 0 ▶sub is_object {
Subroutine is_object: not called CC=2 SCAR=17.9
Pod documented
305 0 my ($self) = @_;
306 0 ▶ CORE::ref($self)
Branch: 1 branch
BranchTrueFalseTotal
CORE::ref $self ? : 0 0 0
307 ? (Sidef::Types::Bool::Bool::TRUE)
308 : (Sidef::Types::Bool::Bool::FALSE);
309 }
310  
311 0 ▶sub is_typename {
Subroutine is_typename: not called CC=2 SCAR=17.9
Pod documented
312 0 my ($self) = @_;
313 0 ▶ CORE::ref($self)
Branch: 1 branch
BranchTrueFalseTotal
CORE::ref $self ? : 0 0 0
314 ? (Sidef::Types::Bool::Bool::FALSE)
315 : (Sidef::Types::Bool::Bool::TRUE);
316 }
317  
318 0 ▶sub parent_classes {
Subroutine parent_classes: not called CC=2 SCAR=15.3
Pod documented
319 0 my ($obj) = @_;
320  
321 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
322  
323 0 my %seen;
324 my $extract_parents;
325 0 ▶ $extract_parents = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
326 0 my ($ref) = @_;
327  
328 0 my @parents = @{${$ref . '::'}{ISA}};
329  
330 0 ▶ if (@parents) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parents) 0 0 0
331 0 foreach my $parent (@parents) {
332 0 ▶ next if $seen{$parent}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$parent}++ 0 0 0
333 0 push @parents, $extract_parents->($parent);
334 }
335 }
336  
337 0 @parents;
338 0 };
339  
340 0 ▶ Sidef::Types::Array::Array->new([$extract_parents->(CORE::ref($obj) || $obj)]);
Condition0%0/3
CORE::ref $obj || $obj
l!l&&r!l&&!r
000
MC/DC0%0/2
CORE::ref $obj || $obj
CORE::ref $obj $obj
Truth table0%0/3
A || B
A= CORE::ref $objB= $obj
ABresult
1X1
011
000
341 }
342  
343 0 ▶sub interpolate {
Subroutine interpolate: not called CC=1 SCAR=6.9
Pod documented
344 0 my $self = shift(@_);
345 0 $self->new(CORE::join('', @_));
346 }
347  
348 0 ▶sub dump {
Subroutine dump: not called CC=1 SCAR=5.7
Pod documented
349 0 my %addr; # keep track of dumped objects
350  
351 0 ▶ my $sub = sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
352 0 my ($obj) = @_;
353  
354 0 my $refaddr = Scalar::Util::refaddr($obj);
355  
356 exists($addr{$refaddr})
357 0 ▶ and return $addr{$refaddr};
Branch: 1 branch
BranchTrueFalseTotal
exists $addr{$refaddr} and return $addr{$refaddr} 0 0 0
358  
359 0 ▶ my $type = Sidef::normalize_type(CORE::ref($obj) || $obj);
Condition0%0/3
CORE::ref $obj || $obj
l!l&&r!l&&!r
000
MC/DC0%0/2
CORE::ref $obj || $obj
CORE::ref $obj $obj
Truth table0%0/3
A || B
A= CORE::ref $objB= $obj
ABresult
1X1
011
000
360 0 ▶ Scalar::Util::reftype($obj) eq 'HASH' or return $type;
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($obj) eq "HASH" or return $type 0 0 0
361 0 my @keys = CORE::sort(CORE::keys(%{$obj}));
362  
363 0 my $str = Sidef::Types::String::String->new($type . "(#`($refaddr)...)");
364  
365 0 $addr{$refaddr} = $str;
366  
367 0 my $s;
368 $$str = (
369 "$type(" . CORE::join(
370 ', ',
371 map {
372 0 my $str = (
373 defined($obj->{$_})
374 ? (
375 (CORE::ref($obj->{$_}) && ($s = UNIVERSAL::can($obj->{$_}, 'dump')))
376 0 ▶ ? $s->($obj->{$_})
Branch: 2 branches
BranchTrueFalseTotal
defined $obj->{$_} ? : 0 0 0
CORE::ref $obj->{$_} && ($s = UNIVERSAL::can($obj->{$_}, 'dump')) ? : 0 0 0
Condition0%0/3
CORE::ref $obj->{$_} and $s = UNIVERSAL::can($obj->{$_}, "dump")
!ll&&!rl&&r
000
MC/DC0%0/2
CORE::ref $obj->{$_} and $s = UNIVERSAL::can($obj->{$_}, "dump")
CORE::ref $obj->{$_} $s = UNIVERSAL::can($obj->{$_}, "dump")
Truth table0%0/3
A and B
A= CORE::ref $obj->{$_}B= $s = UNIVERSAL::can($obj->{$_}, "dump")
ABresult
0X0
100
111
377 : "$obj->{$_}"
378 )
379 : 'nil'
380 );
381 0 "$_: $str";
382 } @keys
383 )
384 . ')'
385 );
386  
387 0 $str;
388 0 };
389  
390 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
391 0 local *Sidef::Object::Object::dump = $sub;
392 0 $sub->($_[0]);
393 }
394  
395 0 ▶sub to_json {
Subroutine to_json: not called CC=1 SCAR=6.9
Pod documented
396 0 my ($self) = @_;
397 0 state $x = require JSON::PP;
398 0 state $y = require Encode;
399 0 Sidef::Types::String::String->new(Encode::decode_utf8(scalar JSON::PP::encode_json($self->get_value)));
400 }
401  
402 {
403 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
404  
405 0 ▶ sub def_method {
Subroutine def_method: not called CC=2 SCAR=17.9
Pod documented
406 0 my ($self, $name, $block) = @_;
407 0 ▶ *{(CORE::ref($self) || $self) . '::' . $name} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
CORE::ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
CORE::ref $self || $self
CORE::ref $self $self
Truth table0%0/3
A || B
A= CORE::ref $selfB= $self
ABresult
1X1
011
000
408 0 $block->call(@_);
409 0 };
410 0 $self;
411 }
412  
413 0 ▶ sub undef_method {
Subroutine undef_method: not called CC=2 SCAR=17.9
Pod documented
414 0 my ($self, $name) = @_;
415 0 ▶ delete ${(CORE::ref($self) || $self) . '::'}{$name};
Condition0%0/3
CORE::ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
CORE::ref $self || $self
CORE::ref $self $self
Truth table0%0/3
A || B
A= CORE::ref $selfB= $self
ABresult
1X1
011
000
416 0 $self;
417 }
418  
419 0 ▶ sub alias_method {
Subroutine alias_method: not called CC=3 SCAR=24.8
Pod documented
420 0 my ($self, $old, $new) = @_;
421  
422 0 ▶ my $ref = (CORE::ref($self) || $self);
Condition0%0/3
CORE::ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
CORE::ref $self || $self
CORE::ref $self $self
Truth table0%0/3
A || B
A= CORE::ref $selfB= $self
ABresult
1X1
011
000
423 0 my $to = \&{$ref . '::' . $old};
424  
425 0 ▶ if (not defined &$to) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &$to) 0 0 0
426 0 die "[ERROR] Can't alias the nonexistent method `$old` as `$new`!";
427 }
428  
429 0 *{$ref . '::' . $new} = $to;
430 }
431  
432 0 ▶ sub methods {
Subroutine methods: not called CC=5 SCAR=34.0
Pod documented
433 0 my ($self, @args) = @_;
434  
435 0 my %alias;
436 my %methods;
437  
438 0 ▶ my $ref = CORE::ref($self) || $self;
Condition0%0/3
CORE::ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
CORE::ref $self || $self
CORE::ref $self $self
Truth table0%0/3
A || B
A= CORE::ref $selfB= $self
ABresult
1X1
011
000
439  
440 0 ▶ foreach my $method (grep { $_ !~ /^[(_]/ and defined(&{$ref . '::' . $_}) } keys %{$ref . '::'}) {
Condition0%0/3
!($_ =~ /^[(_]/u) && defined &{$ref . '::' . $_;}
!ll&&!rl&&r
000
MC/DC0%0/2
!($_ =~ /^[(_]/u) && defined &{$ref . '::' . $_;}
!($_ =~ /^[(_]/u) defined &{$ref . '::' . $_;}
Truth table0%0/3
not(A) && B
A= !($_ =~ /^[(_]/u)B= defined &{$ref . '::' . $_;}
ABresult
0X0
100
111
441 $methods{$method} = (
442 0 ▶ $alias{\&{$ref . '::' . $method}} //=
Condition0%0/3
$alias{\&{$ref . '::' . $method;}} //= "Sidef::Object::LazyMethod"->new({"obj", $self, "method", $method, "args", \@args})
l!l&&r!l&&!r
000
MC/DC0%0/2
$alias{\&{$ref . '::' . $method;}} //= "Sidef::Object::LazyMethod"->new({"obj", $self, "method", $method, "args", \@args})
$alias{\&{$ref . '::' . $method;}} "Sidef::Object::LazyMethod"->new({"obj", $self, "method", $method, "args", \@args})
Truth table0%0/3
A //= B
A= $alias{\&{$ref . '::' . $method;}}B= "Sidef::Object::LazyMethod"->new({"obj", $self, "method", $method, "args", \@args})
ABresult
1X1
011
000
443 Sidef::Object::LazyMethod->new(
444 {
445 obj => $self,
446 method => $method,
447 args => \@args,
448 }
449 )
450 );
451 }
452  
453 0 Sidef::Types::Hash::Hash->new(\%methods);
454 }
455  
456 # Smart match operator
457 0 ▶ sub smartmatch {
Subroutine smartmatch: not called CC=47 SCAR=77.2
Pod documented
458 0 my ($first, $second) = @_;
459  
460 0 ▶ if (!defined($first) and !defined($second)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $first or defined $second) 0 0 0
Condition0%0/3
defined $first or defined $second
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $first or defined $second
defined $first defined $second
Truth table0%0/3
A or B
A= defined $firstB= defined $second
ABresult
1X1
011
000
461 0 return Sidef::Types::Bool::Bool::TRUE;
462 }
463  
464 # Second is not an object (assuming it is a typename)
465 # Return true if `typeof(first)` is a subclass of `second`
466 0 ▶ if (defined($second) and !CORE::ref($second)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $second and not CORE::ref $second) 0 0 0
Condition0%0/3
defined $second and not CORE::ref $second
!ll&&!rl&&r
000
MC/DC0%0/2
defined $second and not CORE::ref $second
defined $second not CORE::ref $second
Truth table0%0/3
A and not(B)
A= defined $secondB= not CORE::ref $second
ABresult
0X0
100
111
467  
468 0 ▶ if (defined($first) and !CORE::ref($first)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $first and not CORE::ref $first) 0 0 0
Condition0%0/3
defined $first and not CORE::ref $first
!ll&&!rl&&r
000
MC/DC0%0/2
defined $first and not CORE::ref $first
defined $first not CORE::ref $first
Truth table0%0/3
A and not(B)
A= defined $firstB= not CORE::ref $first
ABresult
0X0
100
111
469 return (
470 0 ▶ ($first eq $second)
Branch: 1 branch
BranchTrueFalseTotal
$first eq $second ? : 0 0 0
471 ? Sidef::Types::Bool::Bool::TRUE
472 : Sidef::Types::Bool::Bool::FALSE
473 );
474 }
475  
476 return (
477 0 ▶ UNIVERSAL::isa(CORE::ref($first), $second)
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa(CORE::ref $first, $second) ? : 0 0 0
478 ? Sidef::Types::Bool::Bool::TRUE
479 : Sidef::Types::Bool::Bool::FALSE
480 );
481 }
482  
483 # First is not an object (assuming it is a typename)
484 # Return true if `first` is a subclass of `typeof(second)`
485 0 ▶ if (defined($first) and !CORE::ref($first)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $first and not CORE::ref $first) 0 0 0
Condition0%0/3
defined $first and not CORE::ref $first
!ll&&!rl&&r
000
MC/DC0%0/2
defined $first and not CORE::ref $first
defined $first not CORE::ref $first
Truth table0%0/3
A and not(B)
A= defined $firstB= not CORE::ref $first
ABresult
0X0
100
111
486 return (
487 0 ▶ UNIVERSAL::isa($first, CORE::ref($second))
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($first, CORE::ref $second) ? : 0 0 0
488 ? Sidef::Types::Bool::Bool::TRUE
489 : Sidef::Types::Bool::Bool::FALSE
490 );
491 }
492  
493 # First is String
494 0 ▶ if (UNIVERSAL::isa($first, 'Sidef::Types::String::String')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($first, "Sidef::Types::String::String")) 0 0 0
495  
496 # String ~~ RangeString
497 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Range::RangeString')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Range::RangeString")) 0 0 0
498 0 return $second->contains($first);
499 }
500  
501 # String ~~ String
502 0 ▶ if (CORE::ref($first) eq CORE::ref($second)) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::ref $first eq CORE::ref $second) 0 0 0
503 0 return $second->eq($first);
504 }
505 }
506  
507 # First is Number
508 0 ▶ if (UNIVERSAL::isa($first, 'Sidef::Types::Number::Number')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($first, "Sidef::Types::Number::Number")) 0 0 0
509  
510 # Number ~~ RangeNumber
511 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Range::RangeNumber')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Range::RangeNumber")) 0 0 0
512 0 return $second->contains($first);
513 }
514 }
515  
516 # First is RangeNumber
517 0 ▶ if (UNIVERSAL::isa($first, 'Sidef::Types::Range::RangeNumber')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($first, "Sidef::Types::Range::RangeNumber")) 0 0 0
518  
519 # RangeNumber ~~ Number
520 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Number::Number')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Number::Number")) 0 0 0
521 0 return $first->contains($second);
522 }
523 }
524  
525 # First is RangeString
526 0 ▶ if (UNIVERSAL::isa($first, 'Sidef::Types::Range::RangeString')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($first, "Sidef::Types::Range::RangeString")) 0 0 0
527  
528 # RangeString ~~ String
529 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::String::String')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::String::String")) 0 0 0
530 0 return $first->contains($second);
531 }
532 }
533  
534 # First is Array
535 0 ▶ if (UNIVERSAL::isa($first, 'Sidef::Types::Array::Array')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($first, "Sidef::Types::Array::Array")) 0 0 0
536  
537 # Array ~~ Array
538 0 ▶ if (CORE::ref($first) eq CORE::ref($second)) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::ref $first eq CORE::ref $second) 0 0 0
539 0 return $first->eq($second);
540 }
541  
542 # Array ~~ Regex
543 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Regex::Regex')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Regex::Regex")) 0 0 0
544 0 return $first->match($second);
545 }
546  
547 # Array ~~ Hash
548 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Hash::Hash')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Hash::Hash")) 0 0 0
549 0 return $second->keys->contains_all($first);
550 }
551  
552 # Array ~~ Any
553 0 ▶ if (!UNIVERSAL::isa($second, 'Sidef::Types::Array::Array')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($second, "Sidef::Types::Array::Array")) 0 0 0
554 0 return $first->contains($second);
555 }
556 }
557  
558 # First is Hash
559 0 ▶ if (UNIVERSAL::isa($first, 'Sidef::Types::Hash::Hash')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($first, "Sidef::Types::Hash::Hash")) 0 0 0
560  
561 # Hash ~~ Array
562 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Array::Array')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Array::Array")) 0 0 0
563 0 return $second->contains_all($first->keys);
564 }
565  
566 # Hash ~~ Hash
567 0 ▶ if (CORE::ref($first) eq CORE::ref($second)) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::ref $first eq CORE::ref $second) 0 0 0
568 0 return $second->eq($first);
569 }
570  
571 # Hash ~~ Regex
572 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Regex::Regex')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Regex::Regex")) 0 0 0
573 0 return $first->keys->match($second);
574 }
575  
576 # Hash ~~ Any
577 0 ▶ if (!UNIVERSAL::isa($second, 'Sidef::Types::Hash::Hash')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($second, "Sidef::Types::Hash::Hash")) 0 0 0
578 0 return $first->exists($second);
579 }
580 }
581  
582 # First is Regex
583 0 ▶ if (UNIVERSAL::isa($first, 'Sidef::Types::Regex::Regex')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($first, "Sidef::Types::Regex::Regex")) 0 0 0
584  
585 # Regex ~~ Regex
586 0 ▶ if (CORE::ref($first) eq CORE::ref($second)) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::ref $first eq CORE::ref $second) 0 0 0
587 0 return $first->eq($second);
588 }
589  
590 # Regex ~~ Array
591 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Array::Array')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Array::Array")) 0 0 0
592 0 return $second->match($first);
593 }
594  
595 # Regex ~~ Hash
596 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Hash::Hash')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Hash::Hash")) 0 0 0
597 0 return $second->keys->match($first);
598 }
599  
600 # Regex ~~ Any
601 0 ▶ if (!UNIVERSAL::isa($second, 'Sidef::Types::Regex::Regex')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($second, "Sidef::Types::Regex::Regex")) 0 0 0
602 0 return $first->match($second)->is_successful;
603 }
604 }
605  
606 # Second is Array
607 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Array::Array')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Array::Array")) 0 0 0
608  
609 # Any ~~ Array
610 0 return $second->contains($first);
611 }
612  
613 # Second is Hash
614 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Hash::Hash')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Hash::Hash")) 0 0 0
615  
616 # Any ~~ Hash
617 0 return $second->exists($first);
618 }
619  
620 # Second is Regex
621 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Regex::Regex')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Regex::Regex")) 0 0 0
622 0 return $second->match($first)->is_successful;
623 }
624  
625 # Second is Block
626 0 ▶ if (UNIVERSAL::isa($second, 'Sidef::Types::Block::Block')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($second, "Sidef::Types::Block::Block")) 0 0 0
627 0 ▶ if (!UNIVERSAL::isa($first, 'Sidef::Types::Block::Block')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($first, "Sidef::Types::Block::Block")) 0 0 0
628 0 return $second->run($first);
629 }
630 }
631  
632 0 ▶ if (defined($first) and !defined($second)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $first and not defined $second) 0 0 0
Condition0%0/3
defined $first and not defined $second
!ll&&!rl&&r
000
MC/DC0%0/2
defined $first and not defined $second
defined $first not defined $second
Truth table0%0/3
A and not(B)
A= defined $firstB= not defined $second
ABresult
0X0
100
111
633 0 return Sidef::Types::Bool::Bool::FALSE;
634 }
635  
636 0 ▶ if (defined($second) and !defined($first)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $second and not defined $first) 0 0 0
Condition0%0/3
defined $second and not defined $first
!ll&&!rl&&r
000
MC/DC0%0/2
defined $second and not defined $first
defined $second not defined $first
Truth table0%0/3
A and not(B)
A= defined $secondB= not defined $first
ABresult
0X0
100
111
637 0 return Sidef::Types::Bool::Bool::FALSE;
638 }
639  
640 0 my $bool = $first eq $second;
641 #<<<
642 0 ▶ CORE::ref($bool) ? $bool : (
Branch: 2 branches
BranchTrueFalseTotal
CORE::ref $bool ? : 0 0 0
$bool ? : 0 0 0
643 $bool ? Sidef::Types::Bool::Bool::TRUE
644 : Sidef::Types::Bool::Bool::FALSE
645 );
646 #>>>
647 }
648  
649 # Pipeline operator
650 1 ▶ *{__PACKAGE__ . '::' . '|>'} = sub {
Subroutine __ANON__: not called CC=3 SCAR=23.0
651 0 my ($arg, $func, @args) = @_;
652  
653 0 ▶ if (Scalar::Util::reftype($func) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($func) eq "ARRAY") 0 0 0
654 0 @args = @$func;
655 0 $func = shift(@args);
656 }
657  
658 0 ▶ if (CORE::ref($func) eq 'Sidef::Types::String::String') {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::ref $func eq "Sidef::Types::String::String") 0 0 0
659 0 return $arg->$$func(@args);
660 }
661  
662 0 $func->call($arg, @args);
663 1 };
664  
665 # Deprecated pair method: ASCII colon; U+3A
666 1 ▶ *{__PACKAGE__ . '::' . ':'} = sub {
Subroutine __ANON__: not called CC=1 SCAR=1.2
667 0 Sidef::Types::Array::Pair->new($_[0], $_[1]);
668 1 };
669  
670 # Pair method: Fullwidth Colon; U+FF1A
671 1 ▶ *{__PACKAGE__ . '::' . ':'} = sub {
Subroutine __ANON__: not called CC=1 SCAR=1.2
672 0 Sidef::Types::Array::Pair->new($_[0], $_[1]);
673 1 };
674  
675 # NamedParam method: Triple Colon Operator; U+2AF6
676 1 ▶ *{__PACKAGE__ . '::' . '⫶'} = sub {
Subroutine __ANON__: not called CC=1 SCAR=1.2
677 0 Sidef::Variable::NamedParam->new($_[0], $_[1]);
678 1 };
679  
680 # Logical AND
681 1 ▶ *{__PACKAGE__ . '::' . '&&'} = sub {
Subroutine __ANON__: not called CC=2 SCAR=13.0
682 0 ▶ $_[0] ? $_[1] : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 0 0
683 1 };
684  
685 # Logical OR
686 1 ▶ *{__PACKAGE__ . '::' . '||'} = sub {
Subroutine __ANON__: not called CC=2 SCAR=13.0
687 0 ▶ $_[0] ? $_[0] : $_[1];
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 0 0
688 1 };
689  
690 # Logical XOR
691 1 ▶ *{__PACKAGE__ . '::' . '^'} = sub {
Subroutine __ANON__: not called CC=3 SCAR=22.0
692 0 ▶ ($_[0] xor $_[1])
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ^^ $_[1] ? : 0 0 0
Condition0%0/4
$_[0] xor $_[1]
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
$_[0] xor $_[1]
$_[0] $_[1]
Truth table0%0/4
A xor B
A= $_[0]B= $_[1]
ABresult
110
101
011
000
693 ? (Sidef::Types::Bool::Bool::TRUE)
694 : (Sidef::Types::Bool::Bool::FALSE);
695 1 };
696  
697 # Defined-OR
698 1 ▶ *{__PACKAGE__ . '::' . '\\\\'} = sub {
Subroutine __ANON__: not called CC=2 SCAR=13.0
699 0 ▶ defined($_[0]) ? $_[1] : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
700 1 };
701  
702 # Smartmatch operator
703 1 *{__PACKAGE__ . '::' . '~~'} = \&smartmatch;
704  
705 # Negation of smartmatch
706 1 ▶ *{__PACKAGE__ . '::' . '!~'} = sub {
Subroutine __ANON__: not called CC=1 SCAR=1.2
707 0 Sidef::Object::Object::smartmatch($_[0], $_[1])->neg;
708 1 };
709 }
710  
711 1 1;
« Sidef/Deparse/Perl.pm ↑ Summary Sidef/Types/Number/Complex.pm »