File Coverage

blib/lib/Statistics/R/REXP/Integer.pm
Criterion Covered Total %
statement 29 29 100.0
branch 7 8 87.5
condition 2 6 33.3
subroutine 9 9 100.0
pod 0 2 0.0
total 47 54 87.0


line stmt bran cond sub pod time code
1             package Statistics::R::REXP::Integer;
2             # ABSTRACT: an R integer vector
3             $Statistics::R::REXP::Integer::VERSION = '1.0001';
4 19     19   17314 use 5.010;
  19         38  
5              
6 19     19   57 use Scalar::Util qw(looks_like_number);
  19         18  
  19         718  
7              
8 19     19   492 use Class::Tiny::Antlers;
  19         4113  
  19         78  
9 19     19   1909 use namespace::clean;
  19         14648  
  19         67  
10              
11             extends 'Statistics::R::REXP::Vector';
12 19     19   3928 use overload;
  19         1182  
  19         90  
13              
14              
15 19     19   592 use constant sexptype => 'INTSXP';
  19         24  
  19         3977  
16              
17 446     446   2099 sub _type { 'integer'; }
18              
19              
20             sub BUILDARGS {
21 2014     2014 0 219527 my $class = shift;
22 2014         5335 my $attributes = $class->SUPER::BUILDARGS(@_);
23              
24 2013 100       4500 if (ref($attributes->{elements}) eq 'ARRAY') {
25             $attributes->{elements} = [
26 13992 100       27755 map { looks_like_number($_) ? int($_ + ($_ <=> 0) * 0.5) : undef }
27 1999         1697 Statistics::R::REXP::Vector::_flatten(@{$attributes->{elements}})
  1999         4956  
28             ]
29             }
30             $attributes
31 2013         3956 }
32              
33              
34             sub BUILD {
35 2010     2010 0 44447 my ($self, $args) = @_;
36              
37             # Required attribute type
38             die "Elements of the 'elements' attribute must be integers" if defined $self->elements &&
39 2010 100 33     27217 grep { defined($_) && !(looks_like_number($_) && int($_) == $_) } @{$self->elements}
  13992 50 33     62692  
  2010         32496  
40             }
41              
42              
43             1; # End of Statistics::R::REXP::Integer
44              
45             __END__