line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Statistics::R::REXP; |
2
|
|
|
|
|
|
|
# ABSTRACT: base class for R objects (Cs) |
3
|
|
|
|
|
|
|
$Statistics::R::REXP::VERSION = '1.0002'; |
4
|
34
|
|
|
34
|
|
58499
|
use 5.010; |
|
34
|
|
|
|
|
110
|
|
5
|
|
|
|
|
|
|
|
6
|
34
|
|
|
34
|
|
170
|
use Scalar::Util qw( blessed ); |
|
34
|
|
|
|
|
61
|
|
|
34
|
|
|
|
|
1405
|
|
7
|
|
|
|
|
|
|
|
8
|
34
|
|
|
34
|
|
464
|
use Class::Tiny::Antlers; |
|
34
|
|
|
|
|
3197
|
|
|
34
|
|
|
|
|
182
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has attributes => ( |
11
|
|
|
|
|
|
|
is => 'ro', |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use overload |
15
|
7232
|
|
|
7232
|
|
699979
|
eq => sub { shift->_eq(@_) }, |
16
|
34
|
|
|
34
|
|
6345
|
ne => sub { ! shift->_eq(@_) }; |
|
34
|
|
|
52
|
|
752
|
|
|
34
|
|
|
|
|
270
|
|
|
52
|
|
|
|
|
21040
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub BUILD { |
20
|
15495
|
|
|
15495
|
0
|
241403
|
my ($self, $args) = @_; |
21
|
|
|
|
|
|
|
|
22
|
15495
|
100
|
|
|
|
35585
|
die "This is an abstract class and must be subclassed" if ref($self) eq __PACKAGE__; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Required methods |
25
|
15494
|
|
|
|
|
26719
|
for my $req ( qw/sexptype to_pl/ ) { |
26
|
30987
|
100
|
|
|
|
104501
|
die "$req method required" unless $self->can($req); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Required attribute type |
30
|
15493
|
100
|
100
|
|
|
297026
|
die "Attribute 'attributes' must be a hash reference" if defined $self->attributes && |
31
|
|
|
|
|
|
|
ref($self->attributes) ne 'HASH' |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _eq { |
35
|
7284
|
|
|
7284
|
|
36530
|
my ($self, $obj) = (shift, shift); |
36
|
7284
|
100
|
|
|
|
11918
|
return undef unless _mutual_isa($self, $obj); |
37
|
|
|
|
|
|
|
|
38
|
7268
|
|
|
|
|
107479
|
my $a = $self->attributes; |
39
|
7268
|
|
|
|
|
114249
|
my $b = $obj->attributes; |
40
|
|
|
|
|
|
|
|
41
|
7268
|
|
|
|
|
27499
|
_compare_deeply($a, $b) |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
## Returns true if either argument is a subclass of the other |
46
|
|
|
|
|
|
|
sub _mutual_isa { |
47
|
27890
|
|
|
27890
|
|
39706
|
my ($a, $b) = (shift, shift); |
48
|
|
|
|
|
|
|
|
49
|
27890
|
100
|
66
|
|
|
91674
|
ref $a eq ref $b || |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
50
|
|
|
|
|
|
|
(blessed($a) && blessed($b) && |
51
|
|
|
|
|
|
|
($a->isa(ref $b) || |
52
|
|
|
|
|
|
|
$b->isa(ref $a))) |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _compare_deeply { |
57
|
27110
|
50
|
|
27110
|
|
84471
|
my ($a, $b) = @_ or die 'Need two arguments'; |
58
|
27110
|
100
|
100
|
|
|
64046
|
if (defined($a) and defined($b)) { |
59
|
20606
|
100
|
|
|
|
29828
|
return 0 unless _mutual_isa($a, $b); |
60
|
20605
|
100
|
|
|
|
51933
|
if (ref $a eq ref []) { |
|
|
100
|
|
|
|
|
|
61
|
4538
|
100
|
|
|
|
8739
|
return undef unless scalar(@$a) == scalar(@$b); |
62
|
4536
|
|
|
|
|
6850
|
for (my $i = 0; $i < scalar(@{$a}); $i++) { |
|
16771
|
|
|
|
|
28691
|
|
63
|
12264
|
100
|
|
|
|
21471
|
return undef unless _compare_deeply($a->[$i], $b->[$i]); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} elsif (ref $a eq ref {}) { |
66
|
1282
|
50
|
|
|
|
4167
|
return undef unless scalar(keys %$a) == scalar(keys %$b); |
67
|
1282
|
|
|
|
|
3565
|
foreach my $name (keys %$a) { |
68
|
|
|
|
|
|
|
return undef unless exists $b->{$name} && |
69
|
2486
|
100
|
66
|
|
|
7073
|
_compare_deeply($a->{$name}, $b->{$name}); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} else { |
72
|
14785
|
100
|
|
|
|
26857
|
return undef unless $a eq $b; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} else { |
75
|
6504
|
100
|
100
|
|
|
19118
|
return undef if defined($a) or defined($b); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
27024
|
|
|
|
|
178246
|
return 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub is_null { |
83
|
263
|
|
|
263
|
1
|
12539
|
return 0; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub is_vector { |
88
|
9
|
|
|
9
|
1
|
37
|
return 0; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub inherits { |
93
|
4
|
|
|
4
|
1
|
903
|
my ($self, $class) = @_; |
94
|
4
|
|
|
|
|
108
|
my $attributes = $self->attributes; |
95
|
4
|
100
|
66
|
|
|
41
|
return unless $attributes && $attributes->{'class'}; |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
6
|
grep {/^$class$/} @{$attributes->{'class'}->to_pl} |
|
6
|
|
|
|
|
59
|
|
|
3
|
|
|
|
|
7
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; # End of Statistics::R::REXP |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |