| 1 | package CljPerl::Seq; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use CljPerl::Logger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use CljPerl::Printer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | our $VERSION = '0.10'; | |||||||||
| 10 | 2 | our $id = 0; | |||||||||
| 11 | |||||||||||
| 12 | 881 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 13 | 881 | my $class = shift; | |||||||||
| 14 | 881 | my $type = shift; | |||||||||
| 15 | 881 | ▶ | $type = "list" if !defined $type; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 881 | my $value = shift; | |||||||||
| 17 | 881 | my @seq = (); | |||||||||
| 18 | 881 | ▶ | $value = \@seq if !defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 881 | my $self = {class=>"Seq", | |||||||||
| 20 | type=>$type, | ||||||||||
| 21 | value=>$value, | ||||||||||
| 22 | object_id=>"seq" . ($id++), | ||||||||||
| 23 | meta=>undef, | ||||||||||
| 24 | pos=>{filename=>"unknown", | ||||||||||
| 25 | line=>0, | ||||||||||
| 26 | col=>0}}; | ||||||||||
| 27 | 881 | bless $self; | |||||||||
| 28 | 881 | return $self; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 829 | ▶ | sub class { | ||||||||
|
Subroutine
class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 32 | 829 | my $self = shift; | |||||||||
| 33 | 829 | return $self->{class}; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 1182 | ▶ | sub type { | ||||||||
|
Subroutine
type: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 37 | 1182 | my $self = shift; | |||||||||
| 38 | 1182 | my $type = shift; | |||||||||
| 39 | 1182 | ▶ | if(defined $type) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 115 | $self->{type} = $type; | |||||||||
| 41 | } else { | ||||||||||
| 42 | 1067 | return $self->{type}; | |||||||||
| 43 | } | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | sub object_id { | ||||||||
|
Subroutine
object_id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 47 | 0 | my $self = shift; | |||||||||
| 48 | 0 | return $self->{object_id}; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub meta { | ||||||||
|
Subroutine
meta: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 52 | 0 | my $self = shift; | |||||||||
| 53 | 0 | my $meta = shift; | |||||||||
| 54 | 0 | ▶ | if(defined $meta) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | $self->{meta} = $meta; | |||||||||
| 56 | } else { | ||||||||||
| 57 | 0 | return $self->{meta}; | |||||||||
| 58 | } | ||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 1127 | ▶ | sub value { | ||||||||
|
Subroutine
value: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 62 | 1127 | my $self = shift; | |||||||||
| 63 | 1127 | my $value = shift; | |||||||||
| 64 | 1127 | ▶ | if(defined $value) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 8 | $self->{value} = $value; | |||||||||
| 66 | } else { | ||||||||||
| 67 | 1119 | return $self->{value}; | |||||||||
| 68 | } | ||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | ▶ | sub prepend { | ||||||||
|
Subroutine
prepend: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 72 | 0 | my $self = shift; | |||||||||
| 73 | 0 | my $v = shift; | |||||||||
| 74 | 0 | unshift @{$self->{value}}, $v; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 2349 | ▶ | sub append { | ||||||||
|
Subroutine
append: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 78 | 2349 | my $self = shift; | |||||||||
| 79 | 2349 | my $v = shift; | |||||||||
| 80 | 2349 | push @{$self->{value}}, $v; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 3183 | ▶ | sub size { | ||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 84 | 3183 | my $self = shift; | |||||||||
| 85 | 3183 | return scalar @{$self->{value}}; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 656 | ▶ | sub first { | ||||||||
|
Subroutine
first: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 89 | 656 | my $self = shift; | |||||||||
| 90 | 656 | ▶ | return undef if($self->size() < 1); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 656 | return $self->{value}->[0]; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 703 | ▶ | sub second { | ||||||||
|
Subroutine
second: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 95 | 703 | my $self = shift; | |||||||||
| 96 | 703 | ▶ | return undef if($self->size() < 2); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 703 | return $self->{value}->[1]; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 295 | ▶ | sub third { | ||||||||
|
Subroutine
third: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 101 | 295 | my $self = shift; | |||||||||
| 102 | 295 | ▶ | return undef if($self->size() < 3); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 294 | return $self->{value}->[2]; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 7 | ▶ | sub fourth { | ||||||||
|
Subroutine
fourth: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 107 | 7 | my $self = shift; | |||||||||
| 108 | 7 | ▶ | return undef if($self->size() < 4); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | 7 | return $self->{value}->[3]; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 272 | ▶ | sub slice { | ||||||||
|
Subroutine
slice: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 113 | 272 | my $self = shift; | |||||||||
| 114 | 272 | my @range = @_; | |||||||||
| 115 | 272 | return @{$self->{value}}[@range]; | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | 9 | ▶ | sub each { | ||||||||
|
Subroutine
each: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||
| 119 | 9 | my $self = shift; | |||||||||
| 120 | 9 | my $blk = shift; | |||||||||
| 121 | 9 | foreach my $i (@{$self->{value}}) { | |||||||||
| 122 | 165 | ▶ | $blk->($i) if defined $i; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | } | ||||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | 0 | ▶ | sub show { | ||||||||
|
Subroutine
show: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 127 | 0 | my $self = shift; | |||||||||
| 128 | 0 | my $indent = shift; | |||||||||
| 129 | 0 | ▶ | $indent = "" if !defined $indent; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | 0 | print $indent . "type: " . $self->{type} . "\n"; | |||||||||
| 131 | 0 | print $indent . "(\n"; | |||||||||
| 132 | 0 | ▶ | $self->each(sub {$_[0]->show($indent . " "); print $indent . " ,\n";}); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 133 | 0 | print $indent . ")\n"; | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | 0 | ▶ | sub error { | ||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 137 | 0 | my $self = shift; | |||||||||
| 138 | 0 | my $msg = shift; | |||||||||
| 139 | 0 | $msg .= " ["; | |||||||||
| 140 | 0 | $msg .= CljPerl::Printer::to_string($self); | |||||||||
| 141 | 0 | $msg .= "] @[file: " . $self->{pos}->{filename}; | |||||||||
| 142 | 0 | $msg .= " ;line: " . $self->{pos}->{line}; | |||||||||
| 143 | 0 | $msg .= " ;col: " . $self->{pos}->{col} . "]"; | |||||||||
| 144 | 0 | CljPerl::Logger::error($msg); | |||||||||
| 145 | } | ||||||||||
| 146 | |||||||||||
| 147 | 2 | 1; | |||||||||