Statistics/R/REXP/Vector.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 86.3% 19 / 22 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 15 / 15 Podpod 50.0% 2 / 4 totaltotal 90.6% 97 / 107 CC 16 SCAR 12.5
CC
16
Cov
93%
BUILD
6.4
BUILDARGS
6.1
to_pl
3.0
CRAP 3.5
« Statistics/R/IO/ParserState.pm ↑ Summary Statistics/R/REXP/Logical.pm »
1 package Statistics::R::REXP::Vector;
2 # ABSTRACT: an R vector
3 25 $Statistics::R::REXP::Vector::VERSION = '1.0002';
4 25 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 25 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 25 ▶use Class::Tiny::Antlers qw(-default around);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 25 extends 'Statistics::R::REXP';
11  
12 25 ▶use overload '""' => sub { shift->_to_s; };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
13  
14 has type => (
15 is => 'ro',
16 169 ▶ default => sub { shift->_type; },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 25 );
18  
19 has elements => (
20 is => 'ro',
21 97 ▶ default => sub { []; },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 25 );
23  
24  
25 9557 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=6 SCAR=18.2
Pod undocumented
26 9557 my $class = shift;
27 9557 ▶ if ( scalar @_ == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1) { } 2852 6705 9557
elsif (@_ % 2) { } 9 6696 6705
28 2852 ▶ if ( ref $_[0] eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 2852 2852
elsif (builtin::blessed($_[0]) and $_[0]->isa('Statistics::R::REXP::Vector')) { } 18 2834 2852
29 0 return $_[0];
30 }
31 ▶ elsif (blessed($_[0]) && $_[0]->isa('Statistics::R::REXP::Vector')) {
Condition66%2/3
builtin::blessed($_[0]) and $_[0]->isa("Statistics::R::REXP::Vector")
!ll&&!rl&&r
2834018
MC/DC50%1/2
builtin::blessed($_[0]) and $_[0]->isa("Statistics::R::REXP::Vector")
builtin::blessed($_[0]) $_[0]->isa("Statistics::R::REXP::Vector")
Truth table66%2/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("Statistics::R::REXP::Vector")
ABresult
0X0
100
111
32 18 return { elements => $_[0]->elements }
33 } else {
34 2834 return { elements => $_[0] }
35 }
36 }
37 elsif ( @_ % 2 ) {
38 9 die "The new() method for $class expects a hash reference or a key/value list."
39 . " You passed an odd number of arguments\n";
40 }
41 else {
42 6696 return { @_ };
43 }
44 }
45  
46  
47 9539 ▶sub BUILD {
Subroutine BUILD: called CC=6 SCAR=18.5
Pod undocumented
48 9539 my ($self, $args) = @_;
49  
50 9539 ▶ die "This is an abstract class and must be subclassed" if ref($self) eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self eq __PACKAGE__ 0 9539 9539
51  
52 # Required methods
53 9539 for my $req ( qw/_type/ ) {
54 9539 ▶ die "$req method required" unless $self->can($req);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($req) 0 9539 9539
55 }
56
57 # Required attribute type
58 9539 ▶ die "Attribute 'elements' must be an array reference" if defined $self->elements &&
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->elements and ref $self->elements ne "ARRAY" 18 9521 9539
Condition66%2/3
defined $self->elements and ref $self->elements ne "ARRAY"
!ll&&!rl&&r
0952118
MC/DC50%1/2
defined $self->elements and ref $self->elements ne "ARRAY"
defined $self->elements ref $self->elements ne "ARRAY"
Truth table66%2/3
A and B
A= defined $self->elementsB= ref $self->elements ne "ARRAY"
ABresult
0X0
100
111
59 ref($self->elements) ne 'ARRAY'
60 }
61  
62  
63 4515 ▶around _eq => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
64 4515 my $orig = shift;
65  
66 4515 ▶ return undef unless $orig->(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless &$orig(@_) 14 4501 4515
67  
68 4501 my ($self, $obj) = (shift, shift);
69  
70 4501 Statistics::R::REXP::_compare_deeply($self->elements, $obj->elements)
71 25 };
72  
73  
74 440 ▶sub _to_s {
Subroutine _to_s: called CC=1 SCAR=0.0
75 440 my $self = shift;
76 440 ▶ my $stringify = sub { map { defined $_ ? $_ : 'undef'} @_ };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1120 128 1248
77 440 $self->_type . '(' . join(', ', &$stringify(@{$self->elements})) . ')';
78 }
79  
80  
81 ## Turns any references (nested lists) into a plain-old flat list.
82 ## Lists can nest to an arbitrary level, but having references to
83 ## anything other than arrays is not supported.
84 7591 ▶sub _flatten {
Subroutine _flatten: called CC=2 SCAR=6.9
85 7591 ▶ map { ref $_ eq 'ARRAY' ? _flatten(@{$_}) : $_ } @_
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 16 31818 31834
86 }
87  
88 10 ▶sub is_vector {
Subroutine is_vector: called CC=1 SCAR=0.0
Pod documented
89 10 return 1;
90 }
91  
92  
93 45 ▶sub to_pl {
Subroutine to_pl: called CC=3 SCAR=11.0
Pod documented
94 45 my $self = shift;
95 100 ▶ [ map { (blessed $_ && $_->can('to_pl')) ?
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) && $_->can('to_pl') ? : 21 79 100
Condition100%3/3
builtin::blessed($_) and $_->can("to_pl")
!ll&&!rl&&r
74521
MC/DC100%2/2
builtin::blessed($_) and $_->can("to_pl")
builtin::blessed($_) $_->can("to_pl")
Truth table100%3/3
A and B
A= builtin::blessed($_)B= $_->can("to_pl")
ABresult
0X0
100
111
96 $_->to_pl : $_ }
97 45 @{$self->elements} ]
98 }
99  
100 25 1; # End of Statistics::R::REXP::Vector
101  
102 __END__
« Statistics/R/IO/ParserState.pm ↑ Summary Statistics/R/REXP/Logical.pm »