| 1 | package Language::LispPerl::Atom; | ||||||||||
| 2 | 6 | $Language::LispPerl::Atom::VERSION = '0.007'; | |||||||||
| 3 | 6 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 6 | ▶ | use Language::LispPerl::Printer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 6 | ▶ | use Language::LispPerl::Logger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 6 | our $id = 0; | |||||||||
| 9 | |||||||||||
| 10 | 6 | has 'class' => ( is => 'ro', isa => 'Str', default => 'Atom' ); | |||||||||
| 11 | 6 | has 'type' => ( is => 'rw', isa => 'Str', required => 1 ); | |||||||||
| 12 | |||||||||||
| 13 | 6 | has 'value' => ( is => 'rw', default => '' ); | |||||||||
| 14 | 3508 | ▶ | has 'object_id' => ( is => 'ro', isa => 'Str', default => sub{ 'atom'.( $id++ ); } ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 6 | has 'meta_data' => ( is => 'rw' ); | |||||||||
| 16 | # An atom that is a function can have a context. | ||||||||||
| 17 | 6 | has 'context' => ( is => 'rw' ); | |||||||||
| 18 | 3508 | ▶ | has 'pos' => ( is => 'ro', default => sub{ | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 19 | return { | ||||||||||
| 20 | 3508 | filename => "unknown", | |||||||||
| 21 | line => 0, | ||||||||||
| 22 | col => 0 | ||||||||||
| 23 | }; | ||||||||||
| 24 | 6 | }); | |||||||||
| 25 | |||||||||||
| 26 | 80 | ▶ | sub to_hash{ | ||||||||
|
Subroutine
to_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 27 | 80 | my ($self) = @_; | |||||||||
| 28 | return { | ||||||||||
| 29 | 80 | 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 | 40 | ▶ | sub from_hash{ | ||||||||
|
Subroutine
from_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 42 | 40 | my ($class, $hash) = @_; | |||||||||
| 43 | return $class->new({ | ||||||||||
| 44 | 40 | map{ $_ => Language::LispPerl::Reader::from_perl( $hash->{$_} ) } keys %$hash | |||||||||
| 45 | }); | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub show { | ||||||||
|
Subroutine
show: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 50 | 0 | my $self = shift; | |||||||||
| 51 | 0 | my $indent = shift; | |||||||||
| 52 | 0 | ▶ | $indent = "" if !defined $indent; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | sub error { | ||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 60 | 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 | 6 | __PACKAGE__->meta()->make_immutable(); | |||||||||
| 72 | 6 | 1; | |||||||||
| 73 | |||||||||||