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.0002';
4 14     14   46439 use 5.010;
  14         45  
5              
6 14     14   343 use Class::Tiny::Antlers;
  14         3044  
  14         80  
7 14     14   1885 use namespace::clean;
  14         8859  
  14         76  
8              
9             extends 'Statistics::R::REXP::Vector';
10 14     14   3578 use overload;
  14         701  
  14         68  
11              
12              
13 14     14   573 use constant sexptype => 'LGLSXP';
  14         28  
  14         2964  
14              
15 4     4   10 sub _type { 'logical'; }
16              
17              
18             sub BUILDARGS {
19 270     270 0 22602 my $class = shift;
20 270         775 my $attributes = $class->SUPER::BUILDARGS(@_);
21              
22 269 100       736 if (ref($attributes->{elements}) eq 'ARRAY') {
23             $attributes->{elements} = [
24 480 100       1232 map { defined $_ ? ($_ ? 1 : 0) : undef }
    100          
25 255         372 Statistics::R::REXP::Vector::_flatten(@{$attributes->{elements}})
  255         657  
26             ]
27             }
28             $attributes
29 269         606 }
30              
31              
32             sub BUILD {
33 266     266 0 6570 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 266 100 66     4107 grep { defined($_) && ($_ != 1 && $_ != 0) } @{$self->elements}
  480 50 33     2912  
  266         4729  
38             }
39              
40              
41             1; # End of Statistics::R::REXP::Logical
42              
43             __END__