| 1 | package Statistics::R::REXP::Closure; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: an R closure | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 14 | $Statistics::R::REXP::Closure::VERSION = '1.0002'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use 5.010; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use Scalar::Util qw(refaddr blessed); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use Class::Tiny::Antlers qw(-default around); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 14 | ▶ | use namespace::clean; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 14 | extends 'Statistics::R::REXP'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 14 | ▶ | use constant sexptype => 'CLOSXP'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | has args => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 44 | ▶ | default => sub { [] }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 14 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | has defaults => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 54 | ▶ | default => sub { [] }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 14 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 14 | has body => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 14 | has environment => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | use overload | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | ▶ | '""' => sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | 'function('. join(', ', @{$self->args}) . ') ' . $self->body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 14 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 78 | ▶ | sub BUILDARGS { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=6 SCAR=18.2
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 78 | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 78 | ▶ | if ( scalar @_ == 1 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | if ( ref $_[0] eq 'HASH' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | return $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ▶ | } elsif ( blessed $_[0] && $_[0]->isa('Statistics::R::REXP::Closure') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($_[0]) and $_[0]->isa("Statistics::R::REXP::Closure")
MC/DC50%1/2
builtin::blessed($_[0]) and $_[0]->isa("Statistics::R::REXP::Closure")
builtin::blessed($_[0])
$_[0]->isa("Statistics::R::REXP::Closure")
Truth table66%2/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("Statistics::R::REXP::Closure")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # copy constructor from another closure | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | return { args => $_[0]->args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | defaults => $_[0]->defaults, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | body => $_[0]->body, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | environment => $_[0]->environment }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | 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 | 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 | return {@_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 75 | ▶ | sub BUILD { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=15 SCAR=28.6
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 75 | my ($self, $args) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # Required attribute | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 75 | ▶ | die 'Attribute (body) is required' unless defined $args->{body}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | grep { ref $_ } @{$self->args}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $self->args ne "ARRAY" or grep {ref $_;} @{$self->args;}
MC/DC0%0/2
ref $self->args ne "ARRAY" or grep {ref $_;} @{$self->args;}
ref $self->args ne "ARRAY"
grep {ref $_;} @{$self->args;}
Truth table33%1/3
A or B
A= ref $self->args ne "ARRAY"B= grep {ref $_;} @{$self->args;}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | die "Attribute 'defaults' must be a reference to an array of REXPs" if ref($self->defaults) ne 'ARRAY' || | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 74 | ▶ | grep { defined($_) && ! (blessed($_) && $_->isa('Statistics::R::REXP')) } @{$self->defaults}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
ref $self->defaults ne "ARRAY" or grep {defined $_ and not builtin::blessed($_) && $_->isa("Statistics::R::REXP");} @{$self->defaults;}
defined $_ && !(builtin::blessed($_) && $_->isa('Statistics::R::REXP'))
builtin::blessed($_) && $_->isa('Statistics::R::REXP')
MC/DC0%0/2
ref $self->defaults ne "ARRAY" or grep {defined $_ and not builtin::blessed($_) && $_->isa("Statistics::R::REXP");} @{$self->defaults;}
ref $self->defaults ne "ARRAY"
grep {defined $_ and not builtin::blessed($_) && $_->isa("Statistics::R::REXP");} @{$self->defaults;}
MC/DC0%0/3
defined $_ && !(builtin::blessed($_) && $_->isa('Statistics::R::REXP'))
defined $_
builtin::blessed($_)
$_->isa('Statistics::R::REXP')
Truth table33%1/3
A or B
A= ref $self->defaults ne "ARRAY"B= grep {defined $_ and not builtin::blessed($_) && $_->isa("Statistics::R::REXP");} @{$self->defaults;}
Truth table50%2/4
A && not(B && C)
A= defined $_B= builtin::blessed($_)C= $_->isa('Statistics::R::REXP')
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 74 | ▶ | die "Attribute 'body' must be a reference to an instance of Statistics::R::REXP" unless | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($self->body) and $self->body->isa("Statistics::R::REXP")
MC/DC50%1/2
builtin::blessed($self->body) and $self->body->isa("Statistics::R::REXP")
builtin::blessed($self->body)
$self->body->isa("Statistics::R::REXP")
Truth table66%2/3
A and B
A= builtin::blessed($self->body)B= $self->body->isa("Statistics::R::REXP")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | blessed($self->body) && $self->body->isa('Statistics::R::REXP'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 73 | ▶ | die "Attribute 'environment' must be an instance of Environment" if defined $self->environment && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $self->environment and not builtin::blessed($self->environment) && $self->environment->isa("Statistics::R::REXP::Environment")
builtin::blessed($self->environment) && $self->environment->isa('Statistics::R::REXP::Environment')
MC/DC66%2/3
defined $self->environment and not builtin::blessed($self->environment) && $self->environment->isa("Statistics::R::REXP::Environment")
defined $self->environment
builtin::blessed($self->environment)
$self->environment->isa('Statistics::R::REXP::Environment')
Truth table75%3/4
A and not(B && C)
A= defined $self->environmentB= builtin::blessed($self->environment)C= $self->environment->isa('Statistics::R::REXP::Environment')
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | !(blessed($self->environment) && $self->environment->isa('Statistics::R::REXP::Environment')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 72 | my $defaults_length = @{$self->defaults}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 72 | ▶ | if ($defaults_length) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | die 'argument names don\'t match their defaults' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 19 | ▶ | unless $defaults_length == @{$self->args} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 7 | ▶ | around _eq => sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.7
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 7 | my $orig = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 7 | ▶ | return unless $orig->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 5 | my ($self, $obj) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | Statistics::R::REXP::_compare_deeply($self->args, $obj->args) && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | ((scalar(grep {$_} @{$self->defaults}) == scalar(grep {$_} @{$obj->defaults})) || | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
Statistics::R::REXP::_compare_deeply($self->args, $obj->args) and scalar grep({$_;} @{$self->defaults;}) == scalar grep({$_;} @{$obj->defaults;}) || Statistics::R::REXP::_compare_deeply($self->defaults, $obj->defaults) and Statistics::R::REXP::_compare_deeply($self->body, $obj->body)
Statistics::R::REXP::_compare_deeply($self->args, $obj->args) and scalar grep({$_;} @{$self->defaults;}) == scalar grep({$_;} @{$obj->defaults;}) || Statistics::R::REXP::_compare_deeply($self->defaults, $obj->defaults)
scalar grep({$_;} @{$self->defaults;}) == scalar grep({$_;} @{$obj->defaults;}) or Statistics::R::REXP::_compare_deeply($self->defaults, $obj->defaults)
MC/DC50%2/4
Statistics::R::REXP::_compare_deeply($self->args, $obj->args) and scalar grep({$_;} @{$self->defaults;}) == scalar grep({$_;} @{$obj->defaults;}) || Statistics::R::REXP::_compare_deeply($self->defaults, $obj->defaults) and Statistics::R::REXP::_compare_deeply($self->body, $obj->body)
Statistics::R::REXP::_compare_deeply($self->args, $obj->args)
scalar grep({$_;} @{$self->defaults;}) == scalar grep({$_;} @{$obj->defaults;})
Statistics::R::REXP::_compare_deeply($self->defaults, $obj->defaults)
Statistics::R::REXP::_compare_deeply($self->body, $obj->body)
Truth table50%3/6
A and B or C and D
A= Statistics::R::REXP::_compare_deeply($self->args, $obj->args)B= scalar grep({$_;} @{$self->defaults;}) == scalar grep({$_;} @{$obj->defaults;})C= Statistics::R::REXP::_compare_deeply($self->defaults, $obj->defaults)D= Statistics::R::REXP::_compare_deeply($self->body, $obj->body)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 14 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | sub to_pl { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_pl: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | die "Closures do not have a native Perl representation" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 14 | 1; # End of Statistics::R::REXP::Closure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||