| 1 | package Dallycot::Value::Vector; | ||||||||||||||||||||||||||||
| 2 | 30 | our $AUTHORITY = 'cpan:JSMITH'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # ABSTRACT: A finite length, in-memory ordered set of 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 | 30 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 30 | ▶ | use parent 'Dallycot::Value::Collection'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 30 | ▶ | use Promises qw(deferred collect); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub new { | ||||||||||||||||||||||||||||
| 15 | 23 | ▶ | my ( $class, @values ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 23 | ▶ | $class = ref $class || $class; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 17 | 23 | return bless \@values => $class; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub values { | ||||||||||||||||||||||||||||
| 21 | 15 | ▶ | @{$_[0]}; | ||||||||||||||||||||||||||
|
Subroutine
values: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub is_empty { | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
is_empty: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | return @$self == 0; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub to_rdf { | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my($self, $model) = @_; | ||||||||||||||||||||||||||
|
Subroutine
to_rdf: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | $model -> list(map { $_ -> to_rdf($model) } @$self); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub is_defined { return 1 } | ||||||||||||||||||||||||||
|
Subroutine
is_defined: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub as_text { | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
as_text: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | return | ||||||||||||||||||||||||||||
| 42 | "< " | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | . join( ", ", map { defined($_) ? ( ( $_ eq $self ) ? '(self)' : $_->as_text ) : '(undef)' } @$self ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 44 | . " >"; | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub prepend { | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my ( $self, @things ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
prepend: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | return bless [ @things, @$self ] => __PACKAGE__; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub calculate_length { | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | my ( $self, $engine ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
calculate_length: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | return Dallycot::Value::Numeric->new( scalar @$self ); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub calculate_reverse { | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my ( $self, $engine ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
calculate_reverse: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | 1 | ▶ | my ( $self, $engine, $transform ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
apply_map: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 3 | return collect( map { $transform->apply( $engine, {}, $_ ) } @$self )->then( | |||||||||||||||||||||||||||
| 73 | sub { | ||||||||||||||||||||||||||||
| 74 | 1 | ▶ | my @values = map {@$_} @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 75 | 1 | bless \@values => __PACKAGE__; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 1 | ); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub apply_filter { | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my ( $self, $engine, $filter ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
apply_filter: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | return collect( map { $filter->apply( $engine, {}, $_ ) } @$self )->then( | |||||||||||||||||||||||||||
| 84 | sub { | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my (@hits) = map { $_->value } map {@$_} @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 86 | 0 | my @values; | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | for ( my $i = 0; $i < @hits; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | push @values, $self->[$i] if $hits[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | return bless \@values => __PACKAGE__; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 0 | ); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub value_at { | ||||||||||||||||||||||||||||
| 96 | 93 | ▶ | my ( $self, $engine, $index ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
value_at: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 93 | my $d = deferred; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 93 | ▶ | if ( $index > @$self || $index < 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$index > @$self or $index < 1
MC/DC0%0/2
$index > @$self or $index < 1
$index > @$self
$index < 1
Truth table33%1/3
A or B
A= $index > @$selfB= $index < 1
| |||||||||||||||||||||||||||||
| 101 | 0 | $d->resolve( $engine->UNDEFINED ); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | else { | ||||||||||||||||||||||||||||
| 104 | 93 | $d->resolve( $self->[ $index - 1 ] ); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 93 | return $d->promise; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub head { | ||||||||||||||||||||||||||||
| 111 | 1 | ▶ | my ( $self, $engine ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
head: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | my $d = deferred; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 1 | ▶ | if (@$self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 1 | $d->resolve( $self->[0] ); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | else { | ||||||||||||||||||||||||||||
| 119 | 0 | $d->resolve( $engine->UNDEFINED ); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 1 | return $d->promise; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | sub tail { | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my ( $self, $engine ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
tail: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | my $d = deferred; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if (@$self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 30 | 1; | |||||||||||||||||||||||||||