blib/lib/Dallycot/AST/Zip.pm

filter: Statementstmt 61.4% 43 / 70 Branchbran 40.0% 4 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 14 / 18 Podpod 0.0% 0 / 3 totaltotal 60.4% 61 / 101 CC 6 SCAR 13.5
CC
6
Cov
59%
execute
11.3
to_string
2.0
to_rdf
2.0
CRAP 3.9
« blib/lib/Dallycot/Value/Vector.pm ↑ Summary blib/lib/Dallycot/Value/Set.pm »
1 package Dallycot::AST::Zip;
2 29 our $AUTHORITY = 'cpan:JSMITH';
3  
4 # ABSTRACT: Combines a set of collections into a collection of vectors
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(collect deferred);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 29 ▶use List::Util qw(max);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 29 ▶use List::MoreUtils qw(all any each_array);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub to_string {
18 0 ▶ my ($self) = @_;
Subroutine to_string: not called CC=1 SCAR=6.9
Pod undocumented
19 0 return '(' . join( ' Z ', map { $_->to_string } @{$self} ) . ')';
20 }
21  
22 sub to_rdf {
23 0 ▶ my($self, $model) = @_;
Subroutine to_rdf: not called CC=1 SCAR=6.9
Pod undocumented
24  
25 0 return $model -> apply(
26 $model -> meta_uri('loc:zip'),
27 [ @$self ],
28 {}
29 );
30 # my $bnode = $model->bnode;
31 # $model -> add_type($bnode, 'loc:Zip');
32 #
33 # $model -> add_list($bnode, 'loc:expressions',
34 # map { $_ -> to_rdf($model) } @$self
35 # );
36 # return $bnode;
37 }
38  
39 sub execute {
40 30 ▶ my ( $self, $engine ) = @_;
Subroutine execute: called CC=6 SCAR=24.3
Pod undocumented
41  
42 # produce a vector with the head of each thing
43 # then a tail promise for the rest
44 # unless we're all vectors, in which case zip everything up now!
45 30 ▶ if ( any { $_->isa('Dallycot::AST') } @$self ) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 3 branches
BranchTrueFalseTotal
if (&any(sub { $_->isa('Dallycot::AST'); } , @$self)) { } 9 21 30
elsif (&all(sub { $_->isa('Dallycot::Value::Vector'); } , @$self)) { } 0 21 21
elsif (&all(sub { $_->isa('Dallycot::Value::String'); } , @$self)) { } 0 21 21
46 return $engine->collect(@$self)->then(
47 sub {
48 8 ▶ my $newself = bless \@_ => __PACKAGE__;
Subroutine __ANON__: called CC=1 SCAR=0.0
49 8 $newself->execute($engine);
50 }
51 9 );
52 }
53 21 ▶ elsif ( all { $_->isa('Dallycot::Value::Vector') } @$self ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
54  
55 # all vectors
56 0 my $it = each_arrayref(@$self);
57 0 my @results;
58 0 ▶ while ( my @vals = $it->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@vals) = &$it()) 0 0 0
59 0 push @results, bless \@vals => 'Dallycot::Value::Vector';
60 }
61  
62 0 my $d = deferred;
63  
64 0 $d->resolve( bless \@results => 'Dallycot::Value::Vector' );
65  
66 0 return $d->promise;
67 }
68 21 ▶ elsif ( all { $_->isa('Dallycot::Value::String') } @$self ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
69  
70 # all strings
71 0 my @sources = map { \{ $_->value } } @$self;
72 0 my $length = max( map { length $$_ } @sources );
73 0 my @results;
74 0 ▶ for ( my $idx = 0; $idx < $length; $idx++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < $length) 0 0 0
75 0 my $s = join( "", map { substr( $$_, $idx, 1 ) } @sources );
76 0 push @results, Dallycot::Value::String->new($s);
77 }
78 0 my $d = deferred;
79  
80 0 $d->resolve( bless \@results => 'Dallycot::Value::Vector' );
81  
82 0 return $d->promise;
83 }
84 else {
85 21 my $d = deferred;
86  
87 42 collect( map { $_->head($engine) } @$self )->done(
88 sub {
89 20 ▶ my (@heads) = map {@$_} @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
90 40 collect( map { $_->tail($engine) } @$self )->done(
91 sub {
92 16 ▶ my (@tails) = map {@$_} @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
93 16 my $r;
94 16 $d->resolve(
95 $r = bless [
96 ( bless \@heads => 'Dallycot::Value::Vector' ),
97  
98 undef,
99  
100 Dallycot::Value::Lambda->new(
101 expression => ( bless \@tails => __PACKAGE__ ),
102 bindings => [],
103 bindings_with_defaults => [],
104 options => {}
105 )
106 ] => 'Dallycot::Value::Stream'
107 );
108 },
109 sub {
110 0 ▶ $d->reject(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 }
112 20 );
113 },
114 sub {
115 0 ▶ $d->reject(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
116 }
117 21 );
118  
119 21 return $d->promise;
120 }
121 }
122  
123 29 1;
« blib/lib/Dallycot/Value/Vector.pm ↑ Summary blib/lib/Dallycot/Value/Set.pm »