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