|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
  
 
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Statistics::R::REXP::Closure;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # ABSTRACT: an R closure  | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 $Statistics::R::REXP::Closure::VERSION = '1.0002';  | 
| 
4
 | 
14
 | 
 
 | 
 
 | 
  
14
  
 | 
 
 | 
53236
 | 
 use 5.010;  | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
43
 | 
    | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
6
 | 
14
 | 
 
 | 
 
 | 
  
14
  
 | 
 
 | 
66
 | 
 use Scalar::Util qw(refaddr blessed);  | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
26
 | 
    | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
664
 | 
    | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
8
 | 
14
 | 
 
 | 
 
 | 
  
14
  
 | 
 
 | 
405
 | 
 use Class::Tiny::Antlers qw(-default around);  | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3224
 | 
    | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
69
 | 
    | 
| 
9
 | 
14
 | 
 
 | 
 
 | 
  
14
  
 | 
 
 | 
2085
 | 
 use namespace::clean;  | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9338
 | 
    | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
93
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 extends 'Statistics::R::REXP';  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
14
 | 
14
 | 
 
 | 
 
 | 
  
14
  
 | 
 
 | 
3194
 | 
 use constant sexptype => 'CLOSXP';  | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
27
 | 
    | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1949
 | 
    | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 has args => (  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     is => 'ro',  | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     default => sub { [] },  | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 );  | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 has defaults => (  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     is => 'ro',  | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     default => sub { [] },  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 );  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 has body => (  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     is => 'ro',  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 );  | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 has environment => (  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     is => 'ro',  | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 );  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 use overload  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     '""' => sub {  | 
| 
37
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
263
 | 
         my $self = shift;  | 
| 
38
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
         'function('. join(', ', @{$self->args}) . ') ' . $self->body  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
40
 | 
    | 
| 
39
 | 
14
 | 
 
 | 
 
 | 
  
14
  
 | 
 
 | 
878
 | 
     };  | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
773
 | 
    | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
94
 | 
    | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub BUILDARGS {  | 
| 
43
 | 
78
 | 
 
 | 
 
 | 
  
78
  
 | 
  
0
  
 | 
4567
 | 
     my $class = shift;  | 
| 
44
 | 
78
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
249
 | 
     if ( scalar @_ == 1 ) {  | 
| 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
45
 | 
2
 | 
  
 50
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
21
 | 
         if ( ref $_[0] eq 'HASH' ) {  | 
| 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
46
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             return $_[0];  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         } elsif ( blessed $_[0] && $_[0]->isa('Statistics::R::REXP::Closure') ) {  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             # copy constructor from another closure  | 
| 
49
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
34
 | 
             return { args => $_[0]->args,  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                      defaults => $_[0]->defaults,  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                      body => $_[0]->body,  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                      environment => $_[0]->environment };  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
54
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
         die "Single parameters to new() must be a HASH data"  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             ." or a Statistics::R::REXP::Closure object => ". $_[0] ."\n";  | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     elsif ( @_ % 2 ) {  | 
| 
58
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
         die "The new() method for $class expects a hash reference or a key/value list."  | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 . " You passed an odd number of arguments\n";  | 
| 
60
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
61
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     else {  | 
| 
62
 | 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
281
 | 
         return {@_};  | 
| 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
64
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
65
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub BUILD {  | 
| 
68
 | 
75
 | 
 
 | 
 
 | 
  
75
  
 | 
  
0
  
 | 
2045
 | 
     my ($self, $args) = (shift, shift);  | 
| 
69
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
70
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # Required attribute  | 
| 
71
 | 
75
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
199
 | 
     die 'Attribute (body) is required' unless defined $args->{body};  | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       | 
| 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # Required attribute type  | 
| 
74
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     die "Attribute 'args' must be a reference to an array of scalars" if ref($self->args) ne 'ARRAY' ||  | 
| 
75
 | 
74
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
1216
 | 
         grep { ref $_ } @{$self->args};  | 
| 
 
 | 
64
 | 
 
 | 
 
 | 
 
 | 
 
 | 
285
 | 
    | 
| 
 
 | 
74
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1516
 | 
    | 
| 
76
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       | 
| 
77
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     die "Attribute 'defaults' must be a reference to an array of REXPs" if ref($self->defaults) ne 'ARRAY' ||  | 
| 
78
 | 
74
 | 
  
100
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
1377
 | 
         grep { defined($_) && ! (blessed($_) && $_->isa('Statistics::R::REXP')) } @{$self->defaults};  | 
| 
 
 | 
46
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
398
 | 
    | 
| 
 
 | 
74
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1307
 | 
    | 
| 
79
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       | 
| 
80
 | 
74
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
1406
 | 
     die "Attribute 'body' must be a reference to an instance of Statistics::R::REXP" unless  | 
| 
81
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         blessed($self->body) && $self->body->isa('Statistics::R::REXP');  | 
| 
82
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       | 
| 
83
 | 
73
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
2802
 | 
     die "Attribute 'environment' must be an instance of Environment" if defined $self->environment &&  | 
| 
 
 | 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
84
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         !(blessed($self->environment) && $self->environment->isa('Statistics::R::REXP::Environment'));  | 
| 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       | 
| 
86
 | 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2521
 | 
     my $defaults_length = @{$self->defaults};  | 
| 
 
 | 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1020
 | 
    | 
| 
87
 | 
72
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
443
 | 
     if ($defaults_length) {  | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         die 'argument names don\'t match their defaults'   | 
| 
89
 | 
19
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
35
 | 
             unless $defaults_length == @{$self->args}  | 
| 
 
 | 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
273
 | 
    | 
| 
90
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
91
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
93
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 around _eq => sub {  | 
| 
94
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $orig = shift;  | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     return unless $orig->(@_);  | 
| 
96
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my ($self, $obj) = (shift, shift);  | 
| 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     Statistics::R::REXP::_compare_deeply($self->args, $obj->args) &&  | 
| 
98
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         ((scalar(grep {$_} @{$self->defaults}) == scalar(grep {$_} @{$obj->defaults})) ||  | 
| 
99
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
          Statistics::R::REXP::_compare_deeply($self->defaults, $obj->defaults)) &&  | 
| 
100
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         Statistics::R::REXP::_compare_deeply($self->body, $obj->body) &&  | 
| 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         Statistics::R::REXP::_compare_deeply($self->environment, $obj->environment)  | 
| 
102
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 };  | 
| 
103
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
104
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
105
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub to_pl {  | 
| 
106
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
  
1
  
 | 
611
 | 
     die "Closures do not have a native Perl representation"  | 
| 
107
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
108
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
109
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
110
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1; # End of Statistics::R::REXP::Closure  | 
| 
111
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
112
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |