File Coverage

blib/lib/Statistics/R/REXP/Raw.pm
Criterion Covered Total %
statement 28 29 96.5
branch 6 6 100.0
condition 4 6 66.6
subroutine 8 9 88.8
pod 0 2 0.0
total 46 52 88.4


line stmt bran cond sub pod time code
1             package Statistics::R::REXP::Raw;
2             # ABSTRACT: an R raw vector
3             $Statistics::R::REXP::Raw::VERSION = '1.0001';
4 14     14   15380 use 5.010;
  14         30  
5              
6 14     14   42 use Scalar::Util qw(looks_like_number);
  14         15  
  14         672  
7              
8 14     14   474 use Class::Tiny::Antlers;
  14         3961  
  14         59  
9 14     14   1488 use namespace::clean;
  14         9405  
  14         54  
10              
11             extends 'Statistics::R::REXP::Vector';
12 14     14   2693 use overload;
  14         689  
  14         55  
13              
14              
15 14     14   425 use constant sexptype => 'RAWSXP';
  14         14  
  14         2661  
16              
17 0     0   0 sub _type { 'raw'; }
18              
19              
20             sub BUILDARGS {
21 90     90 0 83715 my $class = shift;
22 90         348 my $attributes = $class->SUPER::BUILDARGS(@_);
23              
24 89 100       300 if (ref($attributes->{elements}) eq 'ARRAY') {
25             $attributes->{elements} = [
26             map int,
27 75         87 Statistics::R::REXP::Vector::_flatten(@{$attributes->{elements}})
  75         226  
28             ]
29             }
30             $attributes
31 89         170 }
32              
33              
34             sub BUILD {
35 87     87 0 2044 my ($self, $args) = @_;
36              
37             # Required attribute type
38 87 100       1224 die 'Raw vectors cannot have attributes' if defined $self->attributes;
39             die 'Elements of raw vectors must be 0-255' if defined $self->elements &&
40 86 100 66     1404 grep { !($_ >= 0 && $_ <= 255) } @{$self->elements}
  265   66     1005  
  86         1508  
41             }
42              
43              
44             1; # End of Statistics::R::REXP::Raw
45              
46             __END__