line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Language::LispPerl::Seq; |
2
|
|
|
|
|
|
|
$Language::LispPerl::Seq::VERSION = '0.007'; |
3
|
6
|
|
|
6
|
|
22
|
use Moose; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
33
|
|
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
28391
|
use Language::LispPerl::Logger; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
147
|
|
6
|
6
|
|
|
6
|
|
2279
|
use Language::LispPerl::Printer; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
3916
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $id = 0; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'class' => ( is => 'ro', isa => 'Str', default => 'Seq' ); |
11
|
|
|
|
|
|
|
has 'type' => ( is => 'rw', isa => 'Str', default => 'list' ); |
12
|
|
|
|
|
|
|
has 'value' => ( is => 'rw', default => sub{ [] } ); |
13
|
|
|
|
|
|
|
has 'object_id' => ( is => 'ro', isa => 'Str', default => sub{ 'seq'.( $id++ ); } ); |
14
|
|
|
|
|
|
|
has 'meta_data' => ( is => 'rw' ); |
15
|
|
|
|
|
|
|
has 'pos' => ( is => 'rw', isa => 'HashRef', default => sub{ |
16
|
|
|
|
|
|
|
return { |
17
|
|
|
|
|
|
|
filename => "unknown", |
18
|
|
|
|
|
|
|
line => 0, |
19
|
|
|
|
|
|
|
col => 0 |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
}); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub to_hash{ |
24
|
38
|
|
|
38
|
0
|
43
|
my ($self) = @_; |
25
|
|
|
|
|
|
|
return { |
26
|
38
|
|
|
|
|
1078
|
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
|
|
|
|
|
|
|
sub from_hash{ |
37
|
19
|
|
|
19
|
0
|
25
|
my ($class, $hash) = @_; |
38
|
|
|
|
|
|
|
return $class->new({ |
39
|
19
|
|
|
|
|
43
|
map{ $_ => Language::LispPerl::Reader::from_perl( $hash->{$_} ) } keys %$hash |
|
133
|
|
|
|
|
223
|
|
40
|
|
|
|
|
|
|
}); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub prepend { |
45
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
46
|
0
|
|
|
|
|
0
|
my $v = shift; |
47
|
0
|
|
|
|
|
0
|
unshift @{ $self->{value} }, $v; |
|
0
|
|
|
|
|
0
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub append { |
51
|
1956
|
|
|
1956
|
0
|
1451
|
my $self = shift; |
52
|
1956
|
|
|
|
|
1277
|
my $v = shift; |
53
|
1956
|
|
|
|
|
1243
|
push @{ $self->{value} }, $v; |
|
1956
|
|
|
|
|
5489
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub size { |
57
|
1683
|
|
|
1683
|
0
|
1245
|
my $self = shift; |
58
|
1683
|
|
|
|
|
1107
|
return scalar @{ $self->{value} }; |
|
1683
|
|
|
|
|
3574
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub first { |
62
|
327
|
|
|
327
|
0
|
261
|
my $self = shift; |
63
|
327
|
50
|
|
|
|
335
|
return undef if ( $self->size() < 1 ); |
64
|
327
|
|
|
|
|
1084
|
return $self->{value}->[0]; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub second { |
68
|
330
|
|
|
330
|
0
|
282
|
my $self = shift; |
69
|
330
|
50
|
|
|
|
371
|
return undef if ( $self->size() < 2 ); |
70
|
330
|
|
|
|
|
3594
|
return $self->{value}->[1]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub third { |
74
|
200
|
|
|
200
|
0
|
175
|
my $self = shift; |
75
|
200
|
100
|
|
|
|
266
|
return undef if ( $self->size() < 3 ); |
76
|
199
|
|
|
|
|
718
|
return $self->{value}->[2]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub fourth { |
80
|
3
|
|
|
3
|
0
|
5
|
my $self = shift; |
81
|
3
|
50
|
|
|
|
7
|
return undef if ( $self->size() < 4 ); |
82
|
3
|
|
|
|
|
10
|
return $self->{value}->[3]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub slice { |
86
|
148
|
|
|
148
|
0
|
128
|
my $self = shift; |
87
|
148
|
|
|
|
|
201
|
my @range = @_; |
88
|
148
|
|
|
|
|
141
|
return @{ $self->{value} }[@range]; |
|
148
|
|
|
|
|
434
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub each { |
92
|
109
|
|
|
109
|
0
|
104
|
my $self = shift; |
93
|
109
|
|
|
|
|
85
|
my $blk = shift; |
94
|
109
|
|
|
|
|
86
|
foreach my $i ( @{ $self->{value} } ) { |
|
109
|
|
|
|
|
181
|
|
95
|
158
|
50
|
|
|
|
407
|
$blk->($i) if defined $i; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub show { |
100
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
101
|
0
|
|
|
|
|
0
|
my $indent = shift; |
102
|
0
|
0
|
|
|
|
0
|
$indent = "" if !defined $indent; |
103
|
0
|
|
|
|
|
0
|
print $indent . "type: " . $self->{type} . "\n"; |
104
|
0
|
|
|
|
|
0
|
print $indent . "(\n"; |
105
|
0
|
|
|
0
|
|
0
|
$self->each( sub { $_[0]->show( $indent . " " ); print $indent . " ,\n"; } |
|
0
|
|
|
|
|
0
|
|
106
|
0
|
|
|
|
|
0
|
); |
107
|
0
|
|
|
|
|
0
|
print $indent . ")\n"; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub error { |
111
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
112
|
1
|
|
|
|
|
1
|
my $msg = shift; |
113
|
1
|
|
|
|
|
3
|
$msg .= " ["; |
114
|
1
|
|
|
|
|
5
|
$msg .= Language::LispPerl::Printer::to_string($self); |
115
|
1
|
|
|
|
|
6
|
$msg .= "] @[file: " . $self->{pos}->{filename}; |
116
|
1
|
|
|
|
|
3
|
$msg .= " ;line: " . $self->{pos}->{line}; |
117
|
1
|
|
|
|
|
2
|
$msg .= " ;col: " . $self->{pos}->{col} . "]"; |
118
|
1
|
|
|
|
|
5
|
Language::LispPerl::Logger::error($msg); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
123
|
|
|
|
|
|
|
1; |