| 1 | package Dallycot::AST::Unique; | ||||||||||
| 2 | 29 | our $AUTHORITY = 'cpan:JSMITH'; | |||||||||
| 3 | |||||||||||
| 4 | # ABSTRACT: Test that all values are unique | ||||||||||
| 5 | |||||||||||
| 6 | 29 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 29 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 29 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 29 | ▶ | use parent 'Dallycot::AST'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 29 | ▶ | use Promises qw(deferred); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | sub to_string { | ||||||||||
| 15 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
to_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 16 | 0 | return join( " <> ", map { $_->to_string } @{$self} ); | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | sub to_rdf { | ||||||||||
| 20 | 0 | ▶ | my($self, $model) = @_; | ||||||||
|
Subroutine
to_rdf: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 21 | |||||||||||
| 22 | # | ||||||||||
| 23 | # node -> expression_set -> [ ... ] | ||||||||||
| 24 | # | ||||||||||
| 25 | 0 | return $model -> apply( | |||||||||
| 26 | $model -> meta_uri('loc:all-unique'), | ||||||||||
| 27 | [ @$self ] | ||||||||||
| 28 | ); | ||||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | sub execute { | ||||||||||
| 32 | 0 | ▶ | my ( $self, $engine ) = @_; | ||||||||
|
Subroutine
execute: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 33 | |||||||||||
| 34 | return $engine->collect(@$self)->then( | ||||||||||
| 35 | sub { | ||||||||||
| 36 | 0 | ▶ | my (@values) = map {@$_} @_; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 37 | |||||||||||
| 38 | 0 | my @types = map { $_->type } @values; | |||||||||
| 39 | return $engine->coerce( @values, \@types )->then( | ||||||||||
| 40 | sub { | ||||||||||
| 41 | 0 | ▶ | my (@new_values) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 42 | |||||||||||
| 43 | # now make sure values are all different | ||||||||||
| 44 | 0 | my %seen; | |||||||||
| 45 | 0 | my @unique = grep { !$seen{ $_->id }++ } @new_values; | |||||||||
| 46 | 0 | ▶ | if ( @unique != @new_values ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | return $engine->FALSE; | |||||||||
| 48 | } | ||||||||||
| 49 | else { | ||||||||||
| 50 | 0 | return $engine->TRUE; | |||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | 0 | ); | |||||||||
| 54 | } | ||||||||||
| 55 | 0 | ); | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 29 | 1; | |||||||||