File Coverage

blib/lib/Statistics/R/REXP/Logical.pm
Criterion Covered Total %
statement 26 26 100.0
branch 9 10 90.0
condition 3 6 50.0
subroutine 8 8 100.0
pod 0 2 0.0
total 46 52 88.4


line stmt bran cond sub pod time code
1             package Statistics::R::REXP::Logical;
2             # ABSTRACT: an R logical vector
3             $Statistics::R::REXP::Logical::VERSION = '1.0';
4 12     12   16196 use 5.010;
  12         24  
5              
6 12     12   473 use Class::Tiny::Antlers;
  12         4215  
  12         79  
7 12     12   1406 use namespace::clean;
  12         9999  
  12         48  
8              
9             extends 'Statistics::R::REXP::Vector';
10 12     12   2128 use overload;
  12         699  
  12         52  
11              
12              
13 12     12   395 use constant sexptype => 'LGLSXP';
  12         13  
  12         2236  
14              
15 4     4   9 sub _type { 'logical'; }
16              
17              
18             sub BUILDARGS {
19 202     202 0 89992 my $class = shift;
20 202         458 my $attributes = $class->SUPER::BUILDARGS(@_);
21              
22 201 100       425 if (ref($attributes->{elements}) eq 'ARRAY') {
23             $attributes->{elements} = [
24 322 100       708 map { defined $_ ? ($_ ? 1 : 0) : undef }
    100          
25 188         171 Statistics::R::REXP::Vector::_flatten(@{$attributes->{elements}})
  188         407  
26             ]
27             }
28             $attributes
29 201         308 }
30              
31              
32             sub BUILD {
33 198     198 0 4414 my ($self, $args) = @_;
34              
35             # Required attribute type
36             die "Elements of the 'elements' attribute must be 0, 1, or undef" if defined $self->elements &&
37 198 100 66     2780 grep { defined($_) && ($_ != 1 && $_ != 0) } @{$self->elements}
  322 50 33     1810  
  198         3311  
38             }
39              
40              
41             1; # End of Statistics::R::REXP::Logical
42              
43             __END__