| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dallycot::Value::Vector; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JSMITH'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: A finite length, in-memory ordered set of values |
|
5
|
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
13260
|
use strict; |
|
|
23
|
|
|
|
|
42
|
|
|
|
23
|
|
|
|
|
812
|
|
|
7
|
23
|
|
|
23
|
|
97
|
use warnings; |
|
|
23
|
|
|
|
|
43
|
|
|
|
23
|
|
|
|
|
574
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
98
|
use utf8; |
|
|
23
|
|
|
|
|
33
|
|
|
|
23
|
|
|
|
|
132
|
|
|
10
|
23
|
|
|
23
|
|
561
|
use parent 'Dallycot::Value::Collection'; |
|
|
23
|
|
|
|
|
44
|
|
|
|
23
|
|
|
|
|
119
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
23
|
|
|
23
|
|
1315
|
use Promises qw(deferred collect); |
|
|
23
|
|
|
|
|
46
|
|
|
|
23
|
|
|
|
|
115
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
|
15
|
0
|
|
|
0
|
0
|
|
my ( $class, @values ) = @_; |
|
16
|
0
|
|
0
|
|
|
|
$class = ref $class || $class; |
|
17
|
0
|
|
|
|
|
|
return bless \@values => $class; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub values { |
|
21
|
0
|
|
|
0
|
0
|
|
@{$_[0]}; |
|
|
0
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub is_empty { |
|
25
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return @$self == 0; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub to_rdf { |
|
31
|
0
|
|
|
0
|
0
|
|
my($self, $model) = @_; |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$model -> list(map { $_ -> to_rdf($model) } @$self); |
|
|
0
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
0
|
0
|
|
sub is_defined { return 1 } |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub as_text { |
|
39
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return |
|
42
|
0
|
0
|
|
|
|
|
"< " |
|
|
|
0
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
. join( ", ", map { defined($_) ? ( ( $_ eq $self ) ? '(self)' : $_->as_text ) : '(undef)' } @$self ) |
|
44
|
|
|
|
|
|
|
. " >"; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub prepend { |
|
48
|
0
|
|
|
0
|
0
|
|
my ( $self, @things ) = @_; |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return bless [ @things, @$self ] => __PACKAGE__; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub calculate_length { |
|
54
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return Dallycot::Value::Numeric->new( scalar @$self ); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub calculate_reverse { |
|
60
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $d = deferred; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$d->resolve( $self->new( reverse @$self ) ); |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return $d->promise; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub apply_map { |
|
70
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $transform ) = @_; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return collect( map { $transform->apply( $engine, {}, $_ ) } @$self )->then( |
|
73
|
|
|
|
|
|
|
sub { |
|
74
|
0
|
|
|
0
|
|
|
my @values = map {@$_} @_; |
|
|
0
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
bless \@values => __PACKAGE__; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
0
|
|
|
|
|
|
); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub apply_filter { |
|
81
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $filter ) = @_; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return collect( map { $filter->apply( $engine, {}, $_ ) } @$self )->then( |
|
84
|
|
|
|
|
|
|
sub { |
|
85
|
0
|
|
|
0
|
|
|
my (@hits) = map { $_->value } map {@$_} @_; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my @values; |
|
87
|
0
|
|
|
|
|
|
for ( my $i = 0; $i < @hits; $i++ ) { |
|
88
|
0
|
0
|
|
|
|
|
push @values, $self->[$i] if $hits[$i]; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
0
|
|
|
|
|
|
return bless \@values => __PACKAGE__; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
0
|
|
|
|
|
|
); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub value_at { |
|
96
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $index ) = @_; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $d = deferred; |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
0
|
0
|
|
|
|
if ( $index > @$self || $index < 1 ) { |
|
101
|
0
|
|
|
|
|
|
$d->resolve( $engine->UNDEFINED ); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
else { |
|
104
|
0
|
|
|
|
|
|
$d->resolve( $self->[ $index - 1 ] ); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return $d->promise; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub head { |
|
111
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $d = deferred; |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
if (@$self) { |
|
116
|
0
|
|
|
|
|
|
$d->resolve( $self->[0] ); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
else { |
|
119
|
0
|
|
|
|
|
|
$d->resolve( $engine->UNDEFINED ); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
return $d->promise; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub tail { |
|
126
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $d = deferred; |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
if (@$self) { |
|
131
|
0
|
|
|
|
|
|
$d->resolve( bless [ @$self[ 1 .. $#$self ] ] => __PACKAGE__ ); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
else { |
|
134
|
0
|
|
|
|
|
|
$d->resolve( Dallycot::Value::EmptyStream->new ); |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return $d->promise; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |