File Coverage

blib/lib/Statistics/R/REXP/Symbol.pm
Criterion Covered Total %
statement 32 33 96.9
branch 9 10 90.0
condition 2 3 66.6
subroutine 10 10 100.0
pod 1 3 33.3
total 54 59 91.5


line stmt bran cond sub pod time code
1             package Statistics::R::REXP::Symbol;
2             # ABSTRACT: an R symbol
3             $Statistics::R::REXP::Symbol::VERSION = '1.0';
4 15     15   18176 use 5.010;
  15         32  
5              
6 15     15   53 use Scalar::Util qw(blessed);
  15         15  
  15         658  
7              
8 15     15   816 use Class::Tiny::Antlers qw(-default around);
  15         4564  
  15         71  
9             #use Statistics::R::REXP::Types;
10 15     15   1823 use namespace::clean;
  15         10484  
  15         65  
11              
12             extends 'Statistics::R::REXP';
13              
14              
15 15     15   1809 use constant sexptype => 'SYMSXP';
  15         16  
  15         1136  
16              
17             has name => (
18             is => 'ro',
19             default => '',
20             );
21              
22             use overload
23 15     15   966 '""' => sub { 'symbol `'. shift->name .'`' };
  15     688   738  
  15         88  
  688         14780  
24              
25             sub BUILDARGS {
26 1490     1490 0 177208 my $class = shift;
27 1490         1729 my $attributes = {};
28            
29 1490 100       2686 if ( scalar @_ == 1) {
    100          
30 1468 50       2575 if ( ref $_[0] eq 'HASH' ) {
31 0         0 $attributes = $_[0]
32             }
33             else {
34 1468         2939 $attributes->{name} = $_[0]
35             }
36             }
37             elsif ( @_ % 2 ) {
38 1         8 die "The new() method for $class expects a hash reference or a key/value list."
39             . " You passed an odd number of arguments\n";
40             }
41             else {
42 21         46 $attributes = { @_ };
43             }
44            
45 1489 100 66     5286 if (blessed($attributes->{name}) &&
46             $attributes->{name}->isa('Statistics::R::REXP::Symbol')) {
47             $attributes->{name} = $attributes->{name}->name
48 2         46 }
49             $attributes
50 1489         2519 }
51              
52             sub BUILD {
53 1488     1488 0 9371 my ($self, $args) = @_;
54              
55 1488 100       21808 die "Attribute 'name' must be a scalar value" unless ref(\$self->name) eq 'SCALAR'
56             }
57              
58             around _eq => sub {
59             my $orig = shift;
60             $orig->(@_) and ($_[0]->name eq $_[1]->name);
61             };
62              
63              
64             sub to_pl {
65 11     11 1 458 my $self = shift;
66 11         174 $self->name
67             }
68              
69              
70             1; # End of Statistics::R::REXP::Symbol
71              
72             __END__