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.0002';
4 19     19   48749 use 5.010;
  19         57  
5              
6 19     19   92 use Scalar::Util qw(looks_like_number);
  19         34  
  19         727  
7              
8 19     19   361 use Class::Tiny::Antlers;
  19         3023  
  19         88  
9 19     19   2377 use namespace::clean;
  19         8957  
  19         81  
10              
11             extends 'Statistics::R::REXP::Vector';
12 19     19   4878 use overload;
  19         742  
  19         161  
13              
14              
15 19     19   748 use constant sexptype => 'INTSXP';
  19         38  
  19         4181  
16              
17 446     446   2521 sub _type { 'integer'; }
18              
19              
20             sub BUILDARGS {
21 2014     2014 0 107455 my $class = shift;
22 2014         7248 my $attributes = $class->SUPER::BUILDARGS(@_);
23              
24 2013 100       7157 if (ref($attributes->{elements}) eq 'ARRAY') {
25             $attributes->{elements} = [
26 13992 100       39501 map { looks_like_number($_) ? int($_ + ($_ <=> 0) * 0.5) : undef }
27 1999         3608 Statistics::R::REXP::Vector::_flatten(@{$attributes->{elements}})
  1999         6616  
28             ]
29             }
30             $attributes
31 2013         5834 }
32              
33              
34             sub BUILD {
35 2010     2010 0 52967 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     30125 grep { defined($_) && !(looks_like_number($_) && int($_) == $_) } @{$self->elements}
  13992 50 33     63761  
  2010         37472  
40             }
41              
42              
43             1; # End of Statistics::R::REXP::Integer
44              
45             __END__