| 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
| |||||||||||||||||||||||||||||
| 28 | 2852 | ▶ | if ( ref $_[0] eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # Required methods | ||||||||||||||||||||||||||||
| 53 | 9539 | for my $req ( qw/_type/ ) { | |||||||||||||||||||||||||||
| 54 | 9539 | ▶ | die "$req method required" unless $self->can($req); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Required attribute type | ||||||||||||||||||||||||||||
| 58 | 9539 | ▶ | die "Attribute 'elements' must be an array reference" if defined $self->elements && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->elements and ref $self->elements ne "ARRAY"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
builtin::blessed($_) and $_->can("to_pl")
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")
| |||||||||||||||||||||||||||||
| 96 | $_->to_pl : $_ } | ||||||||||||||||||||||||||||
| 97 | 45 | @{$self->elements} ] | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 25 | 1; # End of Statistics::R::REXP::Vector | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||