line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dallycot::Value::Set; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JSMITH'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: An in-memory set of unique values |
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
17283
|
use strict; |
|
23
|
|
|
|
|
43
|
|
|
23
|
|
|
|
|
2276
|
|
7
|
23
|
|
|
23
|
|
128
|
use warnings; |
|
23
|
|
|
|
|
30
|
|
|
23
|
|
|
|
|
631
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# RDF Bag |
10
|
|
|
|
|
|
|
|
11
|
23
|
|
|
23
|
|
87
|
use utf8; |
|
23
|
|
|
|
|
27
|
|
|
23
|
|
|
|
|
152
|
|
12
|
23
|
|
|
23
|
|
781
|
use parent 'Dallycot::Value::Collection'; |
|
23
|
|
|
|
|
51
|
|
|
23
|
|
|
|
|
117
|
|
13
|
|
|
|
|
|
|
|
14
|
23
|
|
|
23
|
|
1384
|
use Promises qw(deferred collect); |
|
23
|
|
|
|
|
36
|
|
|
23
|
|
|
|
|
199
|
|
15
|
|
|
|
|
|
|
|
16
|
23
|
|
|
23
|
|
5792
|
use Scalar::Util qw(blessed); |
|
23
|
|
|
|
|
70
|
|
|
23
|
|
|
|
|
23758
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
0
|
|
|
0
|
0
|
|
my ( $class, @values ) = @_; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
@values = values %{ +{ map { $_->id => $_ } @values } }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return bless \@values => __PACKAGE__; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub id { |
27
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
return "<|" . join("|", map { $_->id } @$self ) . "|>"; |
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub as_text { |
33
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return "<|" . join( " | ", map { $_->as_text } @$self ) . "|>"; |
|
0
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
0
|
0
|
|
sub is_defined { return 1 } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub is_empty { |
41
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return @$self != 0; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub calculate_length { |
47
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return Dallycot::Value::Numeric->new( scalar @$self ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub head { |
53
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $d = deferred; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if (@$self) { |
58
|
0
|
|
|
|
|
|
$d->resolve( $self->[0] ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
0
|
|
|
|
|
|
$d->resolve( $engine->UNDEFINED ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return $d->promise; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub tail { |
68
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $d = deferred; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
if (@$self) { |
73
|
0
|
|
|
|
|
|
$d->resolve( bless [ @$self[ 1 .. $#$self ] ] => __PACKAGE__ ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else { |
76
|
0
|
|
|
|
|
|
$d->resolve( Dallycot::Value::EmptyStream->new() ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return $d->promise; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub apply_map { |
83
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $transform ) = @_; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return collect( map { $transform->apply( $engine, {}, $_ ) } @$self )->then( |
86
|
|
|
|
|
|
|
sub { |
87
|
0
|
|
|
0
|
|
|
return $self->new( map {@$_} @_ ); |
|
0
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub apply_filter { |
93
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $filter ) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return collect( map { $filter->apply( $engine, {}, $_ ) } @$self )->then( |
96
|
|
|
|
|
|
|
sub { |
97
|
0
|
|
|
0
|
|
|
my (@hits) = map { $_->value } map {@$_} @_; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my @values; |
99
|
0
|
|
|
|
|
|
for ( my $i = 0; $i < @hits; $i++ ) { |
100
|
0
|
0
|
|
|
|
|
push @values, $self->[$i] if $hits[$i]; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
bless \@values => __PACKAGE__; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub prepend { |
108
|
0
|
|
|
0
|
0
|
|
my ( $self, @things ) = @_; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return $self->new( @things, @$self ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub union { |
114
|
0
|
|
|
0
|
0
|
|
my ( $self, $other ) = @_; |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
return Dallycot::Processor->UNDEFINED unless $other->isa(__PACKAGE__); |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return $self->new( @{$self}, @{$other} ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub intersection { |
122
|
0
|
|
|
0
|
0
|
|
my ( $self, $other ) = @_; |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
return Dallycot::Processor->UNDEFINED unless $other->isa(__PACKAGE__); |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $own_values = { map { $_->id => $_ } @$self }; |
|
0
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $other_values = { map { $_->id => $_ } @$other }; |
|
0
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
my @new_values; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
@new_values = @{$own_values}{ grep { $other_values->{$_} } keys %$own_values }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
return bless \@new_values => __PACKAGE__; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub fetch_property { |
138
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $prop ) = @_; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
return collect( map { $_->fetch_property( $engine, $prop ) } @$self )->then( |
141
|
|
|
|
|
|
|
sub { |
142
|
0
|
|
|
0
|
|
|
my (@values) = map {@$_} @_; |
|
0
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
return grep { blessed($_) && !$_->isa('Dallycot::Value::Undefined') } @values; |
|
0
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
} |
146
|
0
|
|
|
|
|
|
); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |