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.0';
4 17     17   16460 use 5.010;
  17         35  
5              
6 17     17   56 use Scalar::Util qw(looks_like_number);
  17         17  
  17         626  
7              
8 17     17   494 use Class::Tiny::Antlers;
  17         3820  
  17         71  
9 17     17   1759 use namespace::clean;
  17         9141  
  17         64  
10              
11             extends 'Statistics::R::REXP::Vector';
12 17     17   2818 use overload;
  17         656  
  17         67  
13              
14              
15 17     17   509 use constant sexptype => 'INTSXP';
  17         22  
  17         3403  
16              
17 278     278   1118 sub _type { 'integer'; }
18              
19              
20             sub BUILDARGS {
21 1182     1182 0 211371 my $class = shift;
22 1182         3844 my $attributes = $class->SUPER::BUILDARGS(@_);
23              
24 1181 100       2810 if (ref($attributes->{elements}) eq 'ARRAY') {
25             $attributes->{elements} = [
26 10906 100       20515 map { looks_like_number($_) ? int($_ + ($_ <=> 0) * 0.5) : undef }
27 1168         1213 Statistics::R::REXP::Vector::_flatten(@{$attributes->{elements}})
  1168         3193  
28             ]
29             }
30             $attributes
31 1181         2685 }
32              
33              
34             sub BUILD {
35 1178     1178 0 26435 my ($self, $args) = @_;
36              
37             # Required attribute type
38             die "Elements of the 'elements' attribute must be integers" if defined $self->elements &&
39 1178 100 33     16312 grep { defined($_) && !(looks_like_number($_) && int($_) == $_) } @{$self->elements}
  10906 50 33     46099  
  1178         19518  
40             }
41              
42              
43             1; # End of Statistics::R::REXP::Integer
44              
45             __END__