Statistics/R/REXP/Closure.pm

filter: Statementstmt 95.1% 59 / 62 Branchbran 88.4% 23 / 26 Conditioncond 60.6% 20 / 33 MC/DCmcdc 33.3% 6 / 18 Subroutinesub 100% 13 / 13 Podpod 33.3% 1 / 3 totaltotal 78.7% 122 / 155 CC 25 SCAR 22.4
CC
25
Cov
84%
BUILD
17.4
__ANON__
6.5
BUILDARGS
6.1
CRAP 9.4
« Statistics/R/IO/Rserve.pm ↑ Summary Statistics/R/REXP.pm »
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
BranchTrueFalseTotal
if (scalar @_ == 1) { } 2 76 78
elsif (@_ % 2) { } 1 75 76
45 2 ▶ if ( ref $_[0] eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 2 2
elsif (builtin::blessed($_[0]) and $_[0]->isa('Statistics::R::REXP::Closure')) { } 1 2 3
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")
!ll&&!rl&&r
101
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $args->{"body"} 1 74 75
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
BranchTrueFalseTotal
if ref $self->args ne "ARRAY" or grep {ref $_;} @{$self->args;} 0 74 74
Condition33%1/3
ref $self->args ne "ARRAY" or grep {ref $_;} @{$self->args;}
l!l&&r!l&&!r
0074
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;}
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ref $self->defaults ne "ARRAY" or grep {defined $_ and not builtin::blessed($_) && $_->isa("Statistics::R::REXP");} @{$self->defaults;} 0 74 74
Condition44%4/9
ref $self->defaults ne "ARRAY" or grep {defined $_ and not builtin::blessed($_) && $_->isa("Statistics::R::REXP");} @{$self->defaults;}
l!l&&r!l&&!r
0074
defined $_ && !(builtin::blessed($_) && $_->isa('Statistics::R::REXP'))
!ll&&!rl&&r
28180
builtin::blessed($_) && $_->isa('Statistics::R::REXP')
!ll&&!rl&&r
0018
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;}
ABresult
1X1
011
000
Truth table50%2/4
A && not(B && C)
A= defined $_B= builtin::blessed($_)C= $_->isa('Statistics::R::REXP')
ABCresult
0XX0
1110
10X1
1101
79
80 74 ▶ die "Attribute 'body' must be a reference to an instance of Statistics::R::REXP" unless
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self->body) and $self->body->isa("Statistics::R::REXP") 1 73 74
Condition66%2/3
builtin::blessed($self->body) and $self->body->isa("Statistics::R::REXP")
!ll&&!rl&&r
1073
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if defined $self->environment and not builtin::blessed($self->environment) && $self->environment->isa("Statistics::R::REXP::Environment") 1 72 73
Condition83%5/6
defined $self->environment and not builtin::blessed($self->environment) && $self->environment->isa("Statistics::R::REXP::Environment")
!ll&&!rl&&r
9631
builtin::blessed($self->environment) && $self->environment->isa('Statistics::R::REXP::Environment')
!ll&&!rl&&r
1063
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')
ABCresult
0XX0
1110
10X1
1101
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
BranchTrueFalseTotal
if ($defaults_length) 19 53 72
88 die 'argument names don\'t match their defaults'
89 19 ▶ unless $defaults_length == @{$self->args}
Branch: 1 branch
BranchTrueFalseTotal
unless $defaults_length == @{$self->args;} 1 18 19
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
BranchTrueFalseTotal
unless &$orig(@_) 2 5 7
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
BranchTrueFalseTotal
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) and Statistics::R::REXP::_compare_deeply($self->environment, $obj->environment) 3 2 5
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)
!ll&&!rl&&r
113
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)
!ll&&!rl&&r
104
scalar grep({$_;} @{$self->defaults;}) == scalar grep({$_;} @{$obj->defaults;}) or Statistics::R::REXP::_compare_deeply($self->defaults, $obj->defaults)
l!l&&r!l&&!r
400
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)
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
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__
« Statistics/R/IO/Rserve.pm ↑ Summary Statistics/R/REXP.pm »