| 1 | package Language::LispPerl::Seq; | ||||||||||
| 2 | 6 | $Language::LispPerl::Seq::VERSION = '0.007'; | |||||||||
| 3 | 6 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 6 | ▶ | use Language::LispPerl::Logger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 6 | ▶ | use Language::LispPerl::Printer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 6 | our $id = 0; | |||||||||
| 9 | |||||||||||
| 10 | 6 | has 'class' => ( is => 'ro', isa => 'Str', default => 'Seq' ); | |||||||||
| 11 | 6 | has 'type' => ( is => 'rw', isa => 'Str', default => 'list' ); | |||||||||
| 12 | 1364 | ▶ | has 'value' => ( is => 'rw', default => sub{ [] } ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1375 | ▶ | has 'object_id' => ( is => 'ro', isa => 'Str', default => sub{ 'seq'.( $id++ ); } ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 6 | has 'meta_data' => ( is => 'rw' ); | |||||||||
| 15 | 1375 | ▶ | has 'pos' => ( is => 'rw', isa => 'HashRef', default => sub{ | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 16 | return { | ||||||||||
| 17 | 1375 | filename => "unknown", | |||||||||
| 18 | line => 0, | ||||||||||
| 19 | col => 0 | ||||||||||
| 20 | } | ||||||||||
| 21 | 6 | }); | |||||||||
| 22 | |||||||||||
| 23 | 38 | ▶ | sub to_hash{ | ||||||||
|
Subroutine
to_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 38 | my ($self) = @_; | |||||||||
| 25 | return { | ||||||||||
| 26 | 38 | class => $self->class(), | |||||||||
| 27 | type => $self->type(), | ||||||||||
| 28 | value => Language::LispPerl::Printer::to_perl( $self->value() ), | ||||||||||
| 29 | object_id => $self->object_id(), | ||||||||||
| 30 | meta_data => Language::LispPerl::Printer::to_perl( $self->meta_data() ), | ||||||||||
| 31 | pos => Language::LispPerl::Printer::to_perl( $self->pos() ), | ||||||||||
| 32 | __class => $self->blessed(), | ||||||||||
| 33 | }; | ||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 19 | ▶ | sub from_hash{ | ||||||||
|
Subroutine
from_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 37 | 19 | my ($class, $hash) = @_; | |||||||||
| 38 | return $class->new({ | ||||||||||
| 39 | 19 | map{ $_ => Language::LispPerl::Reader::from_perl( $hash->{$_} ) } keys %$hash | |||||||||
| 40 | }); | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub prepend { | ||||||||
|
Subroutine
prepend: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | 0 | my $v = shift; | |||||||||
| 47 | 0 | unshift @{ $self->{value} }, $v; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 3476 | ▶ | sub append { | ||||||||
|
Subroutine
append: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 51 | 3476 | my $self = shift; | |||||||||
| 52 | 3476 | my $v = shift; | |||||||||
| 53 | 3476 | push @{ $self->{value} }, $v; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 4373 | ▶ | sub size { | ||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 57 | 4373 | my $self = shift; | |||||||||
| 58 | 4373 | return scalar @{ $self->{value} }; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 895 | ▶ | sub first { | ||||||||
|
Subroutine
first: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 62 | 895 | my $self = shift; | |||||||||
| 63 | 895 | ▶ | return undef if ( $self->size() < 1 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 895 | return $self->{value}->[0]; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 944 | ▶ | sub second { | ||||||||
|
Subroutine
second: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 68 | 944 | my $self = shift; | |||||||||
| 69 | 944 | ▶ | return undef if ( $self->size() < 2 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 944 | return $self->{value}->[1]; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 436 | ▶ | sub third { | ||||||||
|
Subroutine
third: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 74 | 436 | my $self = shift; | |||||||||
| 75 | 436 | ▶ | return undef if ( $self->size() < 3 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 434 | return $self->{value}->[2]; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 10 | ▶ | sub fourth { | ||||||||
|
Subroutine
fourth: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 80 | 10 | my $self = shift; | |||||||||
| 81 | 10 | ▶ | return undef if ( $self->size() < 4 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 10 | return $self->{value}->[3]; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 363 | ▶ | sub slice { | ||||||||
|
Subroutine
slice: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 86 | 363 | my $self = shift; | |||||||||
| 87 | 363 | my @range = @_; | |||||||||
| 88 | 363 | return @{ $self->{value} }[@range]; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 114 | ▶ | sub each { | ||||||||
|
Subroutine
each: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||
| 92 | 114 | my $self = shift; | |||||||||
| 93 | 114 | my $blk = shift; | |||||||||
| 94 | 114 | foreach my $i ( @{ $self->{value} } ) { | |||||||||
| 95 | 293 | ▶ | $blk->($i) if defined $i; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | } | ||||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 0 | ▶ | sub show { | ||||||||
|
Subroutine
show: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 100 | 0 | my $self = shift; | |||||||||
| 101 | 0 | my $indent = shift; | |||||||||
| 102 | 0 | ▶ | $indent = "" if !defined $indent; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 0 | print $indent . "type: " . $self->{type} . "\n"; | |||||||||
| 104 | 0 | print $indent . "(\n"; | |||||||||
| 105 | 0 | ▶ | $self->each( sub { $_[0]->show( $indent . " " ); print $indent . " ,\n"; } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 106 | 0 | ); | |||||||||
| 107 | 0 | print $indent . ")\n"; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 1 | ▶ | sub error { | ||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 111 | 1 | my $self = shift; | |||||||||
| 112 | 1 | my $msg = shift; | |||||||||
| 113 | 1 | $msg .= " ["; | |||||||||
| 114 | 1 | $msg .= Language::LispPerl::Printer::to_string($self); | |||||||||
| 115 | 1 | $msg .= "] @[file: " . $self->{pos}->{filename}; | |||||||||
| 116 | 1 | $msg .= " ;line: " . $self->{pos}->{line}; | |||||||||
| 117 | 1 | $msg .= " ;col: " . $self->{pos}->{col} . "]"; | |||||||||
| 118 | 1 | Language::LispPerl::Logger::error($msg); | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | |||||||||||
| 122 | 6 | __PACKAGE__->meta()->make_immutable(); | |||||||||
| 123 | 6 | 1; | |||||||||