File Coverage

blib/lib/Language/LispPerl/Atom.pm
Criterion Covered Total %
statement 14 27 51.8
branch 0 2 0.0
condition n/a
subroutine 5 7 71.4
pod 0 4 0.0
total 19 40 47.5


line stmt bran cond sub pod time code
1             package Language::LispPerl::Atom;
2             $Language::LispPerl::Atom::VERSION = '0.005';
3 6     6   37 use Moose;
  6         134  
  6         57  
4              
5 6     6   40099 use Language::LispPerl::Printer;
  6         10  
  6         183  
6 6     6   33 use Language::LispPerl::Logger;
  6         10  
  6         3464  
7              
8             our $id = 0;
9              
10             has 'class' => ( is => 'ro', isa => 'Str', default => 'Atom' );
11             has 'type' => ( is => 'rw', isa => 'Str', required => 1 );
12              
13             has 'value' => ( is => 'rw', default => '' );
14             has 'object_id' => ( is => 'ro', isa => 'Str', default => sub{ 'atom'.( $id++ ); } );
15             has 'meta_data' => ( is => 'rw' );
16             # An atom that is a function can have a context.
17             has 'context' => ( is => 'rw' );
18             has 'pos' => ( is => 'ro', default => sub{
19             return {
20             filename => "unknown",
21             line => 0,
22             col => 0
23             };
24             });
25              
26             sub to_hash{
27 66     66 0 56 my ($self) = @_;
28             return {
29 66         1547 class => $self->class(),
30             type => $self->type(),
31             value => Language::LispPerl::Printer::to_perl( $self->value() ),
32             object_id => $self->object_id(),
33             meta_data => Language::LispPerl::Printer::to_perl( $self->meta_data() ),
34             pos => Language::LispPerl::Printer::to_perl( $self->pos() ),
35             # Note that we dont persist the function contexts
36             # This forbids the evaluation of closures in deflated evalers.
37             __class => $self->blessed(),
38             };
39             }
40              
41             sub from_hash{
42 33     33 0 33 my ($class, $hash) = @_;
43             return $class->new({
44 33         54 map{ $_ => Language::LispPerl::Reader::from_perl( $hash->{$_} ) } keys %$hash
  231         335  
45             });
46             }
47              
48              
49             sub show {
50 0     0 0   my $self = shift;
51 0           my $indent = shift;
52 0 0         $indent = "" if !defined $indent;
53              
54             #print $indent . "class: " . $self->{class} . "\n";
55 0           print $indent . "type: " . $self->{type} . "\n";
56 0           print $indent . "value: " . $self->{value} . "\n";
57             }
58              
59             sub error {
60 0     0 0   my $self = shift;
61 0           my $msg = shift;
62 0           $msg .= " [";
63 0           $msg .= Language::LispPerl::Printer::to_string($self);
64 0           $msg .= "] @[file: " . $self->{pos}->{filename};
65 0           $msg .= " ;line: " . $self->{pos}->{line};
66 0           $msg .= " ;col: " . $self->{pos}->{col} . "]";
67 0           Language::LispPerl::Logger::error($msg);
68             }
69              
70              
71             __PACKAGE__->meta()->make_immutable();
72             1;
73