| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 50 |  |  | 50 |  | 663 | use v5.14; | 
|  | 50 |  |  |  |  | 161 |  | 
| 2 | 50 |  |  | 50 |  | 245 | use warnings; | 
|  | 50 |  |  |  |  | 96 |  | 
|  | 50 |  |  |  |  | 2340 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | =head1 NAME | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | Attean::API::Query - Utility package defining query-related roles | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | =head1 VERSION | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | This document describes Attean::API::Query version 0.032 | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | use v5.14; | 
| 15 |  |  |  |  |  |  | use Attean; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | This is a utility package for defining query-related roles: | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | =over 4 | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | =item * L<Attean::API::DirectedAcyclicGraph> | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =cut | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | use Scalar::Util qw(refaddr); | 
| 28 | 50 |  |  | 50 |  | 254 | use Types::Standard qw(ArrayRef ConsumerOf); | 
|  | 50 |  |  |  |  | 90 |  | 
|  | 50 |  |  |  |  | 1893 |  | 
| 29 | 50 |  |  | 50 |  | 252 |  | 
|  | 50 |  |  |  |  | 97 |  | 
|  | 50 |  |  |  |  | 290 |  | 
| 30 |  |  |  |  |  |  | use Moo::Role; | 
| 31 | 50 |  |  | 50 |  | 24304 |  | 
|  | 50 |  |  |  |  | 93 |  | 
|  | 50 |  |  |  |  | 425 |  | 
| 32 |  |  |  |  |  |  | # =item C<< children >> | 
| 33 |  |  |  |  |  |  | # | 
| 34 |  |  |  |  |  |  | # An ARRAY reference of L<Attean::API::DirectedAcyclicGraph> objects. | 
| 35 |  |  |  |  |  |  | # | 
| 36 |  |  |  |  |  |  | # =back | 
| 37 |  |  |  |  |  |  | # | 
| 38 |  |  |  |  |  |  | # =cut | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | has 'children' => ( | 
| 41 |  |  |  |  |  |  | is => 'ro', | 
| 42 |  |  |  |  |  |  | isa => ArrayRef[ConsumerOf['Attean::API::DirectedAcyclicGraph']], | 
| 43 |  |  |  |  |  |  | default => sub { [] }, | 
| 44 |  |  |  |  |  |  | ); | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | # =item C<< is_leaf >> | 
| 47 |  |  |  |  |  |  | # | 
| 48 |  |  |  |  |  |  | # Returns true if the referent has zero C<< children >>, false otherwise. | 
| 49 |  |  |  |  |  |  | # | 
| 50 |  |  |  |  |  |  | # =cut | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | my $self	= shift; | 
| 53 |  |  |  |  |  |  | return not(scalar(@{ $self->children })); | 
| 54 | 3 |  |  | 3 | 0 | 1377 | } | 
| 55 | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 19 |  | 
| 56 |  |  |  |  |  |  | # =item C<< walk( prefix => \&pre_cb, postfix => \&pre_cb ) >> | 
| 57 |  |  |  |  |  |  | # | 
| 58 |  |  |  |  |  |  | # Walks the graph rooted at the referent, calling C<< &pre_cb >> (if supplied) | 
| 59 |  |  |  |  |  |  | # before descending, and C<< &post_cb >> (if supplied) after descending. The | 
| 60 |  |  |  |  |  |  | # callback functions are passed the current graph walk node as the single | 
| 61 |  |  |  |  |  |  | # argument. | 
| 62 |  |  |  |  |  |  | # | 
| 63 |  |  |  |  |  |  | # =cut | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | my $self	= shift; | 
| 66 |  |  |  |  |  |  | my %args	= @_; | 
| 67 |  |  |  |  |  |  | my $level	= $args{ level } // 0; | 
| 68 | 150 |  |  | 150 | 0 | 246 | my $parent	= $args{ parent }; | 
| 69 | 150 |  |  |  |  | 476 | if (my $cb = $args{ prefix }) { | 
| 70 | 150 |  | 100 |  |  | 489 | $cb->( $self, $level, $parent ); | 
| 71 | 150 |  |  |  |  | 245 | } | 
| 72 | 150 | 50 |  |  |  | 309 | foreach my $c (@{ $self->children }) { | 
| 73 | 150 |  |  |  |  | 267 | $c->walk( %args, level => (1+$level), parent => $self ); | 
| 74 |  |  |  |  |  |  | } | 
| 75 | 150 |  |  |  |  | 1119 | if (my $cb = $args{ postfix }) { | 
|  | 150 |  |  |  |  | 464 |  | 
| 76 | 99 |  |  |  |  | 447 | $cb->( $self, $level, $parent ); | 
| 77 |  |  |  |  |  |  | } | 
| 78 | 150 | 100 |  |  |  | 498 | } | 
| 79 | 2 |  |  |  |  | 8 |  | 
| 80 |  |  |  |  |  |  | # =item C<< has_only_subtree_types( @classes ) >> | 
| 81 |  |  |  |  |  |  | # | 
| 82 |  |  |  |  |  |  | # Returns true if the invocant and all of its sub-trees are instances of only | 
| 83 |  |  |  |  |  |  | # the listed classes, false otherwise. | 
| 84 |  |  |  |  |  |  | # | 
| 85 |  |  |  |  |  |  | # =cut | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | my $self	= shift; | 
| 88 |  |  |  |  |  |  | my @types	= @_; | 
| 89 |  |  |  |  |  |  | my %types	= map { $_ => 1 } @types; | 
| 90 |  |  |  |  |  |  | return 0 unless (exists $types{ ref($self) }); | 
| 91 | 2 |  |  | 2 | 0 | 15 |  | 
| 92 | 2 |  |  |  |  | 5 | my %classes; | 
| 93 | 2 |  |  |  |  | 6 | $self->walk( prefix => sub { | 
|  | 2 |  |  |  |  | 8 |  | 
| 94 | 2 | 100 |  |  |  | 10 | my $plan	= shift; | 
| 95 |  |  |  |  |  |  | $classes{ref($plan)}++; | 
| 96 | 1 |  |  |  |  | 3 | }); | 
| 97 |  |  |  |  |  |  | foreach my $type (@types) { | 
| 98 | 1 |  |  | 1 |  | 1 | delete $classes{$type}; | 
| 99 | 1 |  |  |  |  | 4 | } | 
| 100 | 1 |  |  |  |  | 9 | my @keys	= keys %classes; | 
| 101 | 1 |  |  |  |  | 4 | return (scalar(@keys) == 0) ? 1 : 0; | 
| 102 | 1 |  |  |  |  | 3 | } | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 1 |  |  |  |  | 5 | # =item C<< cover( prefix => \&pre_cb, postfix => \&pre_cb ) >> | 
| 105 | 1 | 50 |  |  |  | 7 | # | 
| 106 |  |  |  |  |  |  | # Similar to C<< walk >>, walks the graph rooted at the referent, calling | 
| 107 |  |  |  |  |  |  | # C<< &pre_cb >> (if supplied) before descending, and C<< &post_cb >> (if | 
| 108 |  |  |  |  |  |  | # supplied) after descending. However, unlike C<< walk >>, each node in the graph | 
| 109 |  |  |  |  |  |  | # is visited only once. | 
| 110 |  |  |  |  |  |  | # | 
| 111 |  |  |  |  |  |  | # =cut | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | my $self	= shift; | 
| 114 |  |  |  |  |  |  | return $self->_cover({}, @_); | 
| 115 |  |  |  |  |  |  | } | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | my $self	= shift; | 
| 118 | 1 |  |  | 1 | 0 | 2 | my $seen	= shift; | 
| 119 | 1 |  |  |  |  | 5 | my %cb		= @_; | 
| 120 |  |  |  |  |  |  | return if ($seen->{refaddr($self)}++); | 
| 121 |  |  |  |  |  |  | if (my $cb = $cb{ prefix }) { | 
| 122 |  |  |  |  |  |  | $cb->( $self ); | 
| 123 | 3 |  |  | 3 |  | 6 | } | 
| 124 | 3 |  |  |  |  | 4 | foreach my $c (@{ $self->children }) { | 
| 125 | 3 |  |  |  |  | 5 | $c->_cover( $seen, %cb ); | 
| 126 | 3 | 100 |  |  |  | 15 | } | 
| 127 | 2 | 50 |  |  |  | 7 | if (my $cb = $cb{ postfix }) { | 
| 128 | 2 |  |  |  |  | 3 | $cb->( $self ); | 
| 129 |  |  |  |  |  |  | } | 
| 130 | 2 |  |  |  |  | 6 | } | 
|  | 2 |  |  |  |  | 7 |  | 
| 131 | 2 |  |  |  |  | 8 |  | 
| 132 |  |  |  |  |  |  | my $self	= shift; | 
| 133 | 2 | 50 |  |  |  | 8 | my @types	= @_; | 
| 134 | 0 |  |  |  |  | 0 | my @p; | 
| 135 |  |  |  |  |  |  | $self->walk( prefix => sub { | 
| 136 |  |  |  |  |  |  | my $a	= shift; | 
| 137 |  |  |  |  |  |  | foreach my $t (@types) { | 
| 138 |  |  |  |  |  |  | push(@p, $a) if ($a->isa($t) or $a->does($t)); | 
| 139 | 11 |  |  | 11 | 0 | 1750 | } | 
| 140 | 11 |  |  |  |  | 27 | }); | 
| 141 | 11 |  |  |  |  | 22 | return @p; | 
| 142 |  |  |  |  |  |  | } | 
| 143 | 43 |  |  | 43 |  | 52 | } | 
| 144 | 43 |  |  |  |  | 66 |  | 
| 145 | 43 | 100 | 66 |  |  | 222 | use AtteanX::SPARQL::Constants; | 
| 146 |  |  |  |  |  |  | use AtteanX::SPARQL::Token; | 
| 147 | 11 |  |  |  |  | 99 | use Encode qw(decode_utf8); | 
| 148 | 11 |  |  |  |  | 96 | use Attean::API::Iterator; | 
| 149 |  |  |  |  |  |  | use Attean::API::Serializer; | 
| 150 |  |  |  |  |  |  | use AtteanX::Serializer::SPARQL; | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | use Moo::Role; | 
| 153 | 50 |  |  | 50 |  | 39141 |  | 
|  | 50 |  |  |  |  | 109 |  | 
|  | 50 |  |  |  |  | 6270 |  | 
| 154 | 50 |  |  | 50 |  | 285 | requires 'sparql_tokens'; | 
|  | 50 |  |  |  |  | 97 |  | 
|  | 50 |  |  |  |  | 1042 |  | 
| 155 | 50 |  |  | 50 |  | 22671 |  | 
|  | 50 |  |  |  |  | 486867 |  | 
|  | 50 |  |  |  |  | 3326 |  | 
| 156 | 50 |  |  | 50 |  | 18659 | my $self	= shift; | 
|  | 50 |  |  |  |  | 151 |  | 
|  | 50 |  |  |  |  | 1742 |  | 
| 157 | 50 |  |  | 50 |  | 20613 | my $s		= AtteanX::Serializer::SPARQL->new(); | 
|  | 50 |  |  |  |  | 168 |  | 
|  | 50 |  |  |  |  | 2314 |  | 
| 158 | 50 |  |  | 50 |  | 20740 | my $i		= $self->sparql_tokens; | 
|  | 50 |  |  |  |  | 136 |  | 
|  | 50 |  |  |  |  | 1326 |  | 
| 159 |  |  |  |  |  |  | my $bytes	= $s->serialize_iter_to_bytes($i); | 
| 160 | 50 |  |  | 50 |  | 325 | return decode_utf8($bytes); | 
|  | 50 |  |  |  |  | 97 |  | 
|  | 50 |  |  |  |  | 200 |  | 
| 161 |  |  |  |  |  |  | } | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | my $self	= shift; | 
| 164 |  |  |  |  |  |  | if ($self->does('Attean::API::SPARQLQuerySerializable')) { | 
| 165 | 54 |  |  | 54 | 0 | 18300 | my $l	= AtteanX::SPARQL::Token->lbrace; | 
| 166 | 54 |  |  |  |  | 1383 | my $r	= AtteanX::SPARQL::Token->rbrace; | 
| 167 | 54 |  |  |  |  | 9544 | my @tokens; | 
| 168 | 54 |  |  |  |  | 2543 | push(@tokens, $l); | 
| 169 | 54 |  |  |  |  | 1320 | push(@tokens, $self->sparql_tokens->elements); | 
| 170 |  |  |  |  |  |  | push(@tokens, $r); | 
| 171 |  |  |  |  |  |  | return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' ); | 
| 172 |  |  |  |  |  |  | } else { | 
| 173 | 29 |  |  | 29 | 0 | 62 | return $self->sparql_tokens; | 
| 174 | 29 | 50 |  |  |  | 122 | } | 
| 175 | 0 |  |  |  |  | 0 | } | 
| 176 | 0 |  |  |  |  | 0 |  | 
| 177 | 0 |  |  |  |  | 0 | my $self	= shift; | 
| 178 | 0 |  |  |  |  | 0 | my $dataset	= shift; | 
| 179 | 0 |  |  |  |  | 0 | my @default	= @{ $dataset->{ default } || [] }; | 
| 180 | 0 |  |  |  |  | 0 | my @named	= @{ $dataset->{ named } || [] }; | 
| 181 | 0 |  |  |  |  | 0 | my $has_dataset	= (scalar(@default) + scalar(@named)); | 
| 182 |  |  |  |  |  |  | my @tokens; | 
| 183 | 29 |  |  |  |  | 835 | if ($has_dataset) { | 
| 184 |  |  |  |  |  |  | my $from		= AtteanX::SPARQL::Token->keyword('FROM'); | 
| 185 |  |  |  |  |  |  | my $named		= AtteanX::SPARQL::Token->keyword('NAMED'); | 
| 186 |  |  |  |  |  |  | foreach my $i (sort { $a->as_string cmp $b->as_string } @default) { | 
| 187 |  |  |  |  |  |  | push(@tokens, $from); | 
| 188 | 33 |  |  | 33 | 0 | 72 | push(@tokens, $i->sparql_tokens->elements); | 
| 189 | 33 |  |  |  |  | 62 | } | 
| 190 | 33 | 100 |  |  |  | 62 | foreach my $i (sort { $a->as_string cmp $b->as_string } @named) { | 
|  | 33 |  |  |  |  | 166 |  | 
| 191 | 33 | 100 |  |  |  | 65 | push(@tokens, $from); | 
|  | 33 |  |  |  |  | 135 |  | 
| 192 | 33 |  |  |  |  | 73 | push(@tokens, $named); | 
| 193 | 33 |  |  |  |  | 56 | push(@tokens, $i->sparql_tokens->elements); | 
| 194 | 33 | 100 |  |  |  | 82 | } | 
| 195 | 4 |  |  |  |  | 17 | } | 
| 196 | 4 |  |  |  |  | 166 | return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' ); | 
| 197 | 4 |  |  |  |  | 165 | } | 
|  | 0 |  |  |  |  | 0 |  | 
| 198 | 4 |  |  |  |  | 14 |  | 
| 199 | 4 |  |  |  |  | 33 | my $self	= shift; | 
| 200 |  |  |  |  |  |  | my %args	= @_; | 
| 201 | 4 |  |  |  |  | 15 | my $dataset	= $args{dataset} || {}; | 
|  | 0 |  |  |  |  | 0 |  | 
| 202 | 4 |  |  |  |  | 9 |  | 
| 203 | 4 |  |  |  |  | 8 | my $as		= AtteanX::SPARQL::Token->keyword('AS'); | 
| 204 | 4 |  |  |  |  | 16 | my $lparen	= AtteanX::SPARQL::Token->lparen; | 
| 205 |  |  |  |  |  |  | my $rparen	= AtteanX::SPARQL::Token->rparen; | 
| 206 |  |  |  |  |  |  |  | 
| 207 | 33 |  |  |  |  | 592 | my $algebra	= $self; | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | my %modifiers; | 
| 210 |  |  |  |  |  |  | my $form	= 'SELECT'; | 
| 211 | 33 |  |  | 33 | 0 | 62 | if ($algebra->isa('Attean::Algebra::Ask')) { | 
| 212 | 33 |  |  |  |  | 70 | $form	= 'ASK'; | 
| 213 | 33 |  | 100 |  |  | 242 | ($algebra)	= @{ $algebra->children }; | 
| 214 |  |  |  |  |  |  | } elsif ($algebra->isa('Attean::Algebra::Describe')) { | 
| 215 | 33 |  |  |  |  | 197 | $form	= 'DESCRIBE'; | 
| 216 | 33 |  |  |  |  | 1871 | $modifiers{describe}	= $algebra->terms; | 
| 217 | 33 |  |  |  |  | 1408 | ($algebra)	= @{ $algebra->children }; | 
| 218 |  |  |  |  |  |  | } elsif ($algebra->isa('Attean::Algebra::Construct')) { | 
| 219 | 33 |  |  |  |  | 1313 | $form	= 'CONSTRUCT'; | 
| 220 |  |  |  |  |  |  | $modifiers{construct}	= $algebra->triples; | 
| 221 | 33 |  |  |  |  | 61 | ($algebra)	= @{ $algebra->children }; | 
| 222 | 33 |  |  |  |  | 76 | } | 
| 223 | 33 | 100 |  |  |  | 540 |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
| 224 | 3 |  |  |  |  | 7 | unless ($form eq 'CONSTRUCT' or $form eq 'DESCRIBE') { | 
| 225 | 3 |  |  |  |  | 5 | while ($algebra->isa('Attean::Algebra::Extend') or $algebra->isa('Attean::Algebra::Group') or $algebra->isa('Attean::Algebra::OrderBy') or $algebra->isa('Attean::Algebra::Distinct') or $algebra->isa('Attean::Algebra::Reduced') or $algebra->isa('Attean::Algebra::Slice') or $algebra->isa('Attean::Algebra::Project')) { | 
|  | 3 |  |  |  |  | 16 |  | 
| 226 |  |  |  |  |  |  | # TODO: Handle HAVING | 
| 227 | 3 |  |  |  |  | 7 | # TODO: Error if Slice appears before distinct/reduced | 
| 228 | 3 |  |  |  |  | 16 | if ($algebra->isa('Attean::Algebra::Distinct')) { | 
| 229 | 3 |  |  |  |  | 5 | $modifiers{ distinct }	= 1; | 
|  | 3 |  |  |  |  | 12 |  | 
| 230 |  |  |  |  |  |  | } elsif ($algebra->isa('Attean::Algebra::Reduced')) { | 
| 231 | 3 |  |  |  |  | 8 | $modifiers{ reduced }	= 1; | 
| 232 | 3 |  |  |  |  | 19 | } elsif ($algebra->isa('Attean::Algebra::Slice')) { | 
| 233 | 3 |  |  |  |  | 7 | if ($algebra->limit >= 0) { | 
|  | 3 |  |  |  |  | 11 |  | 
| 234 |  |  |  |  |  |  | $modifiers{ limit }		= $algebra->limit; | 
| 235 |  |  |  |  |  |  | } | 
| 236 | 33 | 100 | 100 |  |  | 203 | if ($algebra->offset > 0) { | 
| 237 | 27 |  | 100 |  |  | 747 | $modifiers{ offset }	= $algebra->offset; | 
|  |  |  | 100 |  |  |  |  | 
|  |  |  | 100 |  |  |  |  | 
|  |  |  | 100 |  |  |  |  | 
|  |  |  | 100 |  |  |  |  | 
|  |  |  | 100 |  |  |  |  | 
| 238 |  |  |  |  |  |  | } | 
| 239 |  |  |  |  |  |  | } elsif ($algebra->isa('Attean::Algebra::OrderBy')) { | 
| 240 | 30 | 100 |  |  |  | 377 | $modifiers{order}	= $algebra->comparators; | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 241 | 4 |  |  |  |  | 9 | } elsif ($algebra->isa('Attean::Algebra::Extend')) { | 
| 242 |  |  |  |  |  |  | my $v		= $algebra->variable; | 
| 243 | 2 |  |  |  |  | 3 | my $name	= $v->value; | 
| 244 |  |  |  |  |  |  | my $expr	= $algebra->expression; | 
| 245 | 6 | 50 |  |  |  | 20 | my @tokens; | 
| 246 | 6 |  |  |  |  | 14 | push(@tokens, $lparen); | 
| 247 |  |  |  |  |  |  | push(@tokens, $expr->sparql_tokens->elements); | 
| 248 | 6 | 100 |  |  |  | 18 | push(@tokens, $as); | 
| 249 | 4 |  |  |  |  | 9 | push(@tokens, $v->sparql_tokens->elements); | 
| 250 |  |  |  |  |  |  | push(@tokens, $rparen); | 
| 251 |  |  |  |  |  |  | $modifiers{project_expression_tokens}{$name}	= \@tokens; | 
| 252 | 1 |  |  |  |  | 7 | } elsif ($algebra->isa('Attean::Algebra::Project')) { | 
| 253 |  |  |  |  |  |  | my $vars	= $algebra->variables; | 
| 254 | 4 |  |  |  |  | 10 | my ($child)	= @{ $algebra->children }; | 
| 255 | 4 |  |  |  |  | 10 | my @vars	= sort(map { $_->value } @$vars); | 
| 256 | 4 |  |  |  |  | 13 | my @subvars	= sort($child->in_scope_variables); | 
| 257 | 4 |  |  |  |  | 10 | if (scalar(@vars) == scalar(@subvars) and join('.', @vars) eq join('.', @subvars)) { | 
| 258 | 4 |  |  |  |  | 11 | # this is a SELECT * query | 
| 259 | 4 |  |  |  |  | 27 | } else { | 
| 260 | 4 |  |  |  |  | 16 | foreach my $v (@$vars) { | 
| 261 | 4 |  |  |  |  | 17 | my $name	= $v->value; | 
| 262 | 4 |  |  |  |  | 24 | unless ($modifiers{project_variables}{$name}++) { | 
| 263 | 4 |  |  |  |  | 20 | push(@{ $modifiers{project_variables_order} }, $name); | 
| 264 |  |  |  |  |  |  | } | 
| 265 | 12 |  |  |  |  | 54 | } | 
| 266 | 12 |  |  |  |  | 25 | } | 
|  | 12 |  |  |  |  | 53 |  | 
| 267 | 12 |  |  |  |  | 46 | } elsif ($algebra->isa('Attean::Algebra::Group')) { | 
|  | 22 |  |  |  |  | 106 |  | 
| 268 | 12 |  |  |  |  | 65 | my $aggs	= $algebra->aggregates; | 
| 269 | 12 | 100 | 100 |  |  | 766 | my $groups	= $algebra->groupby; | 
| 270 |  |  |  |  |  |  | foreach my $agg (@$aggs) { | 
| 271 |  |  |  |  |  |  | my $v		= $agg->variable; | 
| 272 | 7 |  |  |  |  | 199 | my $name	= $v->value; | 
| 273 | 13 |  |  |  |  | 32 | my @tokens; | 
| 274 | 13 | 50 |  |  |  | 46 | push(@tokens, $lparen); | 
| 275 | 13 |  |  |  |  | 17 | push(@tokens, $agg->sparql_tokens->elements); | 
|  | 13 |  |  |  |  | 45 |  | 
| 276 |  |  |  |  |  |  | push(@tokens, $as); | 
| 277 |  |  |  |  |  |  | push(@tokens, $v->sparql_tokens->elements); | 
| 278 |  |  |  |  |  |  | push(@tokens, $rparen); | 
| 279 |  |  |  |  |  |  | unless ($modifiers{project_variables}{$name}++) { | 
| 280 | 1 |  |  |  |  | 4 | push(@{ $modifiers{project_variables_order} }, $name); | 
| 281 | 1 |  |  |  |  | 6 | } | 
| 282 | 1 |  |  |  |  | 3 | $modifiers{project_expression_tokens}{$name}	= \@tokens; | 
| 283 | 1 |  |  |  |  | 7 | } | 
| 284 | 1 |  |  |  |  | 5 | foreach my $group (@$groups) { | 
| 285 | 1 |  |  |  |  | 3 | push(@{ $modifiers{groups} }, $group->sparql_tokens->elements); | 
| 286 | 1 |  |  |  |  | 5 | } | 
| 287 | 1 |  |  |  |  | 10 | } else { | 
| 288 | 1 |  |  |  |  | 7 | die "Unexpected pattern type encountered in query_tokens: " . ref($algebra); | 
| 289 | 1 |  |  |  |  | 6 | } | 
| 290 | 1 |  |  |  |  | 5 | ($algebra)	= @{ $algebra->children }; | 
| 291 | 1 | 50 |  |  |  | 10 | } | 
| 292 | 1 |  |  |  |  | 4 | } | 
|  | 1 |  |  |  |  | 6 |  | 
| 293 |  |  |  |  |  |  |  | 
| 294 | 1 |  |  |  |  | 5 | my @tokens; | 
| 295 |  |  |  |  |  |  |  | 
| 296 | 1 |  |  |  |  | 4 | my $where	= AtteanX::SPARQL::Token->keyword('WHERE'); | 
| 297 | 1 |  |  |  |  | 2 | my $lbrace	= AtteanX::SPARQL::Token->lbrace; | 
|  | 1 |  |  |  |  | 9 |  | 
| 298 |  |  |  |  |  |  | my $rbrace	= AtteanX::SPARQL::Token->rbrace; | 
| 299 |  |  |  |  |  |  |  | 
| 300 | 0 |  |  |  |  | 0 |  | 
| 301 |  |  |  |  |  |  | if ($form eq 'SELECT') { | 
| 302 | 30 |  |  |  |  | 50 | push(@tokens, AtteanX::SPARQL::Token->keyword('SELECT')); | 
|  | 30 |  |  |  |  | 582 |  | 
| 303 |  |  |  |  |  |  | if ($modifiers{distinct}) { | 
| 304 |  |  |  |  |  |  | push(@tokens, AtteanX::SPARQL::Token->keyword('DISTINCT')); | 
| 305 |  |  |  |  |  |  | } elsif ($modifiers{reduced}) { | 
| 306 | 33 |  |  |  |  | 95 | push(@tokens, AtteanX::SPARQL::Token->keyword('REDUCED')); | 
| 307 |  |  |  |  |  |  | } | 
| 308 | 33 |  |  |  |  | 111 |  | 
| 309 | 33 |  |  |  |  | 1523 | if (my $p = $modifiers{project_variables_order}) { | 
| 310 | 33 |  |  |  |  | 1359 | foreach my $name (@$p) { | 
| 311 |  |  |  |  |  |  | if (my $etokens = $modifiers{project_expression_tokens}{$name}) { | 
| 312 |  |  |  |  |  |  | push(@tokens, @$etokens); | 
| 313 | 33 | 100 |  |  |  | 1368 | } else { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 314 | 24 |  |  |  |  | 94 | my $v	= Attean::Variable->new( value => $name ); | 
| 315 | 24 | 100 |  |  |  | 1074 | push(@tokens, $v->sparql_tokens->elements); | 
|  |  | 100 |  |  |  |  |  | 
| 316 | 4 |  |  |  |  | 11 | } | 
| 317 |  |  |  |  |  |  | } | 
| 318 | 2 |  |  |  |  | 6 | } else { | 
| 319 |  |  |  |  |  |  | push(@tokens, AtteanX::SPARQL::Token->star); | 
| 320 |  |  |  |  |  |  | } | 
| 321 | 24 | 100 |  |  |  | 308 |  | 
| 322 | 8 |  |  |  |  | 25 | push(@tokens, $self->dataset_tokens($dataset)->elements); | 
| 323 | 14 | 100 |  |  |  | 48 |  | 
| 324 | 5 |  |  |  |  | 29 | push(@tokens, $where); | 
| 325 |  |  |  |  |  |  | if ($algebra->isa('Attean::Algebra::Join')) { | 
| 326 | 9 |  |  |  |  | 167 | # don't emit extraneous braces at the top-level | 
| 327 | 9 |  |  |  |  | 532 | push(@tokens, $algebra->sparql_tokens->elements); | 
| 328 |  |  |  |  |  |  | } else { | 
| 329 |  |  |  |  |  |  | push(@tokens, $lbrace); | 
| 330 |  |  |  |  |  |  | push(@tokens, $algebra->sparql_tokens->elements); | 
| 331 | 16 |  |  |  |  | 58 | push(@tokens, $rbrace); | 
| 332 |  |  |  |  |  |  | } | 
| 333 |  |  |  |  |  |  | if (my $groups = $modifiers{groups}) { | 
| 334 | 24 |  |  |  |  | 706 | push(@tokens, AtteanX::SPARQL::Token->keyword('GROUP')); | 
| 335 |  |  |  |  |  |  | push(@tokens, AtteanX::SPARQL::Token->keyword('BY')); | 
| 336 | 24 |  |  |  |  | 74 | push(@tokens, @$groups); | 
| 337 | 24 | 100 |  |  |  | 167 | } | 
| 338 |  |  |  |  |  |  | if (my $expr = $modifiers{having}) { | 
| 339 | 1 |  |  |  |  | 10 | push(@tokens, AtteanX::SPARQL::Token->keyword('HAVING')); | 
| 340 |  |  |  |  |  |  | push(@tokens, $expr->sparql_tokens->elements); | 
| 341 | 23 |  |  |  |  | 57 | } | 
| 342 | 23 |  |  |  |  | 109 | if (my $comps = $modifiers{order}) { | 
| 343 | 23 |  |  |  |  | 83 | push(@tokens, AtteanX::SPARQL::Token->keyword('ORDER')); | 
| 344 |  |  |  |  |  |  | push(@tokens, AtteanX::SPARQL::Token->keyword('BY')); | 
| 345 | 24 | 100 |  |  |  | 92 | foreach my $c (@$comps) { | 
| 346 | 1 |  |  |  |  | 9 | push(@tokens, $c->sparql_tokens->elements); | 
| 347 | 1 |  |  |  |  | 50 | } | 
| 348 | 1 |  |  |  |  | 43 | } | 
| 349 |  |  |  |  |  |  | if (exists $modifiers{limit}) { | 
| 350 | 24 | 50 |  |  |  | 110 | push(@tokens, AtteanX::SPARQL::Token->keyword('LIMIT')); | 
| 351 | 0 |  |  |  |  | 0 | push(@tokens, AtteanX::SPARQL::Token->integer($modifiers{limit})); | 
| 352 | 0 |  |  |  |  | 0 | } | 
| 353 |  |  |  |  |  |  | if (exists $modifiers{offset}) { | 
| 354 | 24 | 100 |  |  |  | 88 | push(@tokens, AtteanX::SPARQL::Token->keyword('OFFSET')); | 
| 355 | 1 |  |  |  |  | 4 | push(@tokens, AtteanX::SPARQL::Token->integer($modifiers{offset})); | 
| 356 | 1 |  |  |  |  | 52 | } | 
| 357 | 1 |  |  |  |  | 43 | } elsif ($form eq 'DESCRIBE') { | 
| 358 | 1 |  |  |  |  | 6 | push(@tokens, AtteanX::SPARQL::Token->keyword('DESCRIBE')); | 
| 359 |  |  |  |  |  |  | foreach my $t (@{ $modifiers{describe} }) { | 
| 360 |  |  |  |  |  |  | push(@tokens, $t->sparql_tokens->elements); | 
| 361 | 24 | 100 |  |  |  | 87 | } | 
| 362 | 6 |  |  |  |  | 21 | push(@tokens, $self->dataset_tokens($dataset)->elements); | 
| 363 | 6 |  |  |  |  | 282 | push(@tokens, $where); | 
| 364 |  |  |  |  |  |  | push(@tokens, $lbrace); | 
| 365 | 24 | 100 |  |  |  | 310 | push(@tokens, $algebra->sparql_tokens->elements); | 
| 366 | 4 |  |  |  |  | 12 | push(@tokens, $rbrace); | 
| 367 | 4 |  |  |  |  | 160 | } elsif ($form eq 'CONSTRUCT') { | 
| 368 |  |  |  |  |  |  | push(@tokens, AtteanX::SPARQL::Token->keyword('CONSTRUCT')); | 
| 369 |  |  |  |  |  |  | push(@tokens, $lbrace); | 
| 370 | 3 |  |  |  |  | 12 | foreach my $t (@{ $modifiers{construct} }) { | 
| 371 | 3 |  |  |  |  | 126 | push(@tokens, $t->sparql_tokens->elements); | 
|  | 3 |  |  |  |  | 7 |  | 
| 372 | 5 |  |  |  |  | 25 | push(@tokens, AtteanX::SPARQL::Token->dot); | 
| 373 |  |  |  |  |  |  | } | 
| 374 | 3 |  |  |  |  | 18 | push(@tokens, $rbrace); | 
| 375 | 3 |  |  |  |  | 14 | push(@tokens, $self->dataset_tokens($dataset)->elements); | 
| 376 | 3 |  |  |  |  | 8 | push(@tokens, $where); | 
| 377 | 3 |  |  |  |  | 18 | push(@tokens, $lbrace); | 
| 378 | 3 |  |  |  |  | 14 | push(@tokens, $algebra->sparql_tokens->elements); | 
| 379 |  |  |  |  |  |  | push(@tokens, $rbrace); | 
| 380 | 3 |  |  |  |  | 11 | } elsif ($form eq 'ASK') { | 
| 381 | 3 |  |  |  |  | 121 | push(@tokens, AtteanX::SPARQL::Token->keyword('ASK')); | 
| 382 | 3 |  |  |  |  | 7 | push(@tokens, $self->dataset_tokens($dataset)->elements); | 
|  | 3 |  |  |  |  | 17 |  | 
| 383 | 3 |  |  |  |  | 14 | push(@tokens, $lbrace); | 
| 384 | 3 |  |  |  |  | 23 | push(@tokens, $algebra->sparql_tokens->elements); | 
| 385 |  |  |  |  |  |  | push(@tokens, $rbrace); | 
| 386 | 3 |  |  |  |  | 131 | } else { | 
| 387 | 3 |  |  |  |  | 15 | die "Unexpected query for '$form' in query_tokens"; | 
| 388 | 3 |  |  |  |  | 13 | } | 
| 389 | 3 |  |  |  |  | 6 | return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' ); | 
| 390 | 3 |  |  |  |  | 20 | } | 
| 391 | 3 |  |  |  |  | 12 | } | 
| 392 |  |  |  |  |  |  |  | 
| 393 | 3 |  |  |  |  | 12 | use Moo::Role; | 
| 394 | 3 |  |  |  |  | 127 | use namespace::clean; | 
| 395 | 3 |  |  |  |  | 16 | with 'Attean::API::SPARQLSerializable'; | 
| 396 | 3 |  |  |  |  | 27 |  | 
| 397 | 3 |  |  |  |  | 11 | my $self	= shift; | 
| 398 |  |  |  |  |  |  | return $self->query_tokens; | 
| 399 | 0 |  |  |  |  | 0 | } | 
| 400 |  |  |  |  |  |  | } | 
| 401 | 33 |  |  |  |  | 708 |  | 
| 402 |  |  |  |  |  |  | =item * L<Attean::API::Algebra> | 
| 403 |  |  |  |  |  |  |  | 
| 404 |  |  |  |  |  |  | =cut | 
| 405 |  |  |  |  |  |  |  | 
| 406 | 50 |  |  | 50 |  | 93701 | use Moo::Role; | 
|  | 50 |  |  |  |  | 102 |  | 
|  | 50 |  |  |  |  | 238 |  | 
| 407 | 50 |  |  | 50 |  | 16842 | use Types::Standard qw(ArrayRef ConsumerOf); | 
|  | 50 |  |  |  |  | 112 |  | 
|  | 50 |  |  |  |  | 306 |  | 
| 408 |  |  |  |  |  |  |  | 
| 409 |  |  |  |  |  |  | with 'Attean::API::SPARQLSerializable'; | 
| 410 |  |  |  |  |  |  | has 'hints' => (is => 'rw', isa => ArrayRef[ArrayRef[ConsumerOf['Attean::API::Term']]], default => sub { [] }); | 
| 411 | 26 |  |  | 26 | 0 | 111 |  | 
| 412 | 26 |  |  |  |  | 91 | requires 'as_sparql'; | 
| 413 |  |  |  |  |  |  | requires 'in_scope_variables';			# variables that will be in-scope after this operation is evaluated | 
| 414 |  |  |  |  |  |  |  | 
| 415 |  |  |  |  |  |  | my $self	= shift; | 
| 416 |  |  |  |  |  |  | return unless (scalar(@{ $self->children }) == 1); | 
| 417 |  |  |  |  |  |  | return $self->children->[0]; | 
| 418 |  |  |  |  |  |  | } | 
| 419 |  |  |  |  |  |  |  | 
| 420 |  |  |  |  |  |  | my $self	= shift; | 
| 421 | 50 |  |  | 50 |  | 27665 | return "$self"; | 
|  | 50 |  |  |  |  | 105 |  | 
|  | 50 |  |  |  |  | 193 |  | 
| 422 | 50 |  |  | 50 |  | 16008 | } | 
|  | 50 |  |  |  |  | 122 |  | 
|  | 50 |  |  |  |  | 338 |  | 
| 423 |  |  |  |  |  |  |  | 
| 424 |  |  |  |  |  |  | my $self	= shift; | 
| 425 |  |  |  |  |  |  | my $string	= ''; | 
| 426 |  |  |  |  |  |  | $self->walk( prefix => sub { | 
| 427 |  |  |  |  |  |  | my $a		= shift; | 
| 428 |  |  |  |  |  |  | my $level	= shift; | 
| 429 |  |  |  |  |  |  | my $parent	= shift; | 
| 430 |  |  |  |  |  |  | my $indent	= '  ' x $level; | 
| 431 | 2 |  |  | 2 | 0 | 6 | $string	.= "-$indent " .  $a->algebra_as_string($level) . "\n"; | 
| 432 | 2 | 100 |  |  |  | 3 | }); | 
|  | 2 |  |  |  |  | 11 |  | 
| 433 | 1 |  |  |  |  | 7 | return $string; | 
| 434 |  |  |  |  |  |  | } | 
| 435 |  |  |  |  |  |  |  | 
| 436 |  |  |  |  |  |  | my $self	= shift; | 
| 437 | 0 |  |  | 0 | 0 | 0 | my %blanks; | 
| 438 | 0 |  |  |  |  | 0 | $self->walk( prefix => sub { | 
| 439 |  |  |  |  |  |  | my $a	= shift; | 
| 440 |  |  |  |  |  |  | if ($a->isa('Attean::Algebra::BGP')) { | 
| 441 |  |  |  |  |  |  | my @triples	= @{ $a->triples }; | 
| 442 | 20 |  |  | 20 | 0 | 2793 | my @nodes	= grep { $_->does('Attean::API::Blank') } map { $_->values } @triples; | 
| 443 | 20 |  |  |  |  | 61 | foreach my $b (@nodes) { | 
| 444 |  |  |  |  |  |  | $blanks{ $b->value }	= $b; | 
| 445 | 74 |  |  | 74 |  | 98 | } | 
| 446 | 74 |  |  |  |  | 117 | } elsif ($a->isa('Attean::Algebra::Path')) { | 
| 447 | 74 |  |  |  |  | 105 | my @nodes	= grep { $_->does('Attean::API::Blank') } ($a->subject, $a->object); | 
| 448 | 74 |  |  |  |  | 136 | foreach my $b (@nodes) { | 
| 449 | 74 |  |  |  |  | 355 | $blanks{ $b->value }	= $b; | 
| 450 | 20 |  |  |  |  | 227 | } | 
| 451 | 20 |  |  |  |  | 304 | } | 
| 452 |  |  |  |  |  |  | }); | 
| 453 |  |  |  |  |  |  | return values %blanks; | 
| 454 |  |  |  |  |  |  | } | 
| 455 | 4 |  |  | 4 | 0 | 10 |  | 
| 456 | 4 |  |  |  |  | 7 | if ($ENV{ATTEAN_TYPECHECK}) { | 
| 457 |  |  |  |  |  |  | around 'BUILD' => sub { | 
| 458 | 4 |  |  | 4 |  | 9 | my $orig	= shift; | 
| 459 | 4 | 50 |  |  |  | 70 | my $self	= shift; | 
|  |  | 50 |  |  |  |  |  | 
| 460 | 0 |  |  |  |  | 0 | $self->$orig(@_); | 
|  | 0 |  |  |  |  | 0 |  | 
| 461 | 0 |  |  |  |  | 0 | my $name	= ref($self); | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 462 | 0 |  |  |  |  | 0 | $name		=~ s/^.*://; | 
| 463 | 0 |  |  |  |  | 0 | if ($self->can('arity')) { | 
| 464 |  |  |  |  |  |  | my $arity	= $self->arity; | 
| 465 |  |  |  |  |  |  | my $children	= $self->children; | 
| 466 | 0 |  |  |  |  | 0 | my $size	= scalar(@$children); | 
|  | 0 |  |  |  |  | 0 |  | 
| 467 | 0 |  |  |  |  | 0 | unless ($size == $arity) { | 
| 468 | 0 |  |  |  |  | 0 | Carp::confess "${name} algebra construction with bad number of children (expected $arity, but got $size)"; | 
| 469 |  |  |  |  |  |  | } | 
| 470 |  |  |  |  |  |  | } | 
| 471 | 4 |  |  |  |  | 46 | } | 
| 472 | 4 |  |  |  |  | 42 | } | 
| 473 |  |  |  |  |  |  | } | 
| 474 |  |  |  |  |  |  |  | 
| 475 |  |  |  | 502 | 0 |  | =item * L<Attean::API::QueryTree> | 
| 476 |  |  |  |  |  |  |  | 
| 477 |  |  |  |  |  |  | =cut | 
| 478 |  |  |  |  |  |  |  | 
| 479 |  |  |  |  |  |  | use Moo::Role; | 
| 480 |  |  |  |  |  |  | with 'Attean::API::DirectedAcyclicGraph'; | 
| 481 |  |  |  |  |  |  | } | 
| 482 |  |  |  |  |  |  |  | 
| 483 |  |  |  |  |  |  | =item * L<Attean::API::NullaryQueryTree> | 
| 484 |  |  |  |  |  |  |  | 
| 485 |  |  |  |  |  |  | =cut | 
| 486 |  |  |  |  |  |  |  | 
| 487 |  |  |  |  |  |  | use Moo::Role; | 
| 488 |  |  |  |  |  |  | with 'Attean::API::QueryTree'; | 
| 489 |  |  |  |  |  |  | } | 
| 490 |  |  |  |  |  |  |  | 
| 491 |  |  |  |  |  |  | =item * L<Attean::API::UnaryQueryTree> | 
| 492 |  |  |  |  |  |  |  | 
| 493 |  |  |  |  |  |  | =cut | 
| 494 |  |  |  |  |  |  |  | 
| 495 |  |  |  |  |  |  | use Moo::Role; | 
| 496 |  |  |  |  |  |  | with 'Attean::API::QueryTree'; | 
| 497 |  |  |  |  |  |  |  | 
| 498 |  |  |  |  |  |  | my $self	= shift; | 
| 499 |  |  |  |  |  |  | return $self->children->[0]; | 
| 500 | 50 |  |  | 50 |  | 58508 | } | 
|  | 50 |  |  |  |  | 126 |  | 
|  | 50 |  |  |  |  | 245 |  | 
| 501 |  |  |  |  |  |  | } | 
| 502 |  |  |  |  |  |  |  | 
| 503 |  |  |  |  |  |  | =item * L<Attean::API::BinaryQueryTree> | 
| 504 |  |  |  |  |  |  |  | 
| 505 |  |  |  |  |  |  | =cut | 
| 506 |  |  |  |  |  |  |  | 
| 507 |  |  |  |  |  |  | use Moo::Role; | 
| 508 |  |  |  |  |  |  | with 'Attean::API::QueryTree'; | 
| 509 | 50 |  |  | 50 |  | 17481 | } | 
|  | 50 |  |  |  |  | 124 |  | 
|  | 50 |  |  |  |  | 232 |  | 
| 510 | 1 |  |  | 1 | 0 | 5 |  | 
| 511 |  |  |  |  |  |  | =item * L<Attean::API::PropertyPath> | 
| 512 |  |  |  |  |  |  |  | 
| 513 |  |  |  |  |  |  | =cut | 
| 514 |  |  |  |  |  |  |  | 
| 515 |  |  |  |  |  |  | use Moo::Role; | 
| 516 |  |  |  |  |  |  | with 'Attean::API::QueryTree'; | 
| 517 |  |  |  |  |  |  | requires 'as_string'; | 
| 518 |  |  |  |  |  |  | requires 'as_sparql'; | 
| 519 | 50 |  |  | 50 |  | 16970 | } | 
|  | 50 |  |  |  |  | 107 |  | 
|  | 50 |  |  |  |  | 208 |  | 
| 520 | 2 |  |  | 2 | 0 | 386 |  | 
| 521 |  |  |  |  |  |  | =item * L<Attean::API::UnaryPropertyPath> | 
| 522 |  |  |  |  |  |  |  | 
| 523 |  |  |  |  |  |  | =cut | 
| 524 | 36 |  |  | 36 | 0 | 12641 |  | 
| 525 | 36 |  |  |  |  | 279 | use Types::Standard qw(ConsumerOf); | 
| 526 |  |  |  |  |  |  |  | 
| 527 |  |  |  |  |  |  | use Moo::Role; | 
| 528 |  |  |  |  |  |  |  | 
| 529 |  |  |  |  |  |  | # 	has 'path' => (is => 'ro', isa => ConsumerOf['Attean::API::PropertyPath'], required => 1); | 
| 530 |  |  |  |  |  |  | my $self	= shift; | 
| 531 |  |  |  |  |  |  | my ($path)	= @{ $self->children }; | 
| 532 |  |  |  |  |  |  | my $pstr	= $path->as_string; | 
| 533 |  |  |  |  |  |  | if ($path->does('Attean::API::UnaryPropertyPath')) { | 
| 534 | 50 |  |  | 50 |  | 19232 | $pstr	= "($pstr)"; | 
|  | 50 |  |  |  |  | 105 |  | 
|  | 50 |  |  |  |  | 208 |  | 
| 535 | 0 |  |  | 0 | 0 | 0 | } | 
| 536 |  |  |  |  |  |  | my $str	= sprintf("%s%s%s", $self->prefix_name, $pstr, $self->postfix_name); | 
| 537 |  |  |  |  |  |  | return $str; | 
| 538 |  |  |  |  |  |  | } | 
| 539 |  |  |  |  |  |  | my $self	= shift; | 
| 540 |  |  |  |  |  |  | return "Property Path " . $self->prefix_name . $self->postfix_name; | 
| 541 |  |  |  |  |  |  | } | 
| 542 |  |  |  |  |  |  | with 'Attean::API::PropertyPath', 'Attean::API::UnaryQueryTree'; | 
| 543 |  |  |  |  |  |  | } | 
| 544 | 50 |  |  | 50 |  | 17301 |  | 
|  | 50 |  |  |  |  | 104 |  | 
|  | 50 |  |  |  |  | 192 |  | 
| 545 |  |  |  |  |  |  | =item * L<Attean::API::NaryPropertyPath> | 
| 546 |  |  |  |  |  |  |  | 
| 547 |  |  |  |  |  |  | =cut | 
| 548 |  |  |  |  |  |  |  | 
| 549 |  |  |  |  |  |  | use Types::Standard qw(ArrayRef ConsumerOf); | 
| 550 |  |  |  |  |  |  |  | 
| 551 |  |  |  |  |  |  | use Moo::Role; | 
| 552 |  |  |  |  |  |  |  | 
| 553 |  |  |  |  |  |  | # 	has 'children' => (is => 'ro', isa => ArrayRef[ConsumerOf['Attean::API::PropertyPath']], required => 1); | 
| 554 |  |  |  |  |  |  | requires 'separator'; | 
| 555 | 50 |  |  | 50 |  | 18991 | my $self	= shift; | 
|  | 50 |  |  |  |  | 103 |  | 
|  | 50 |  |  |  |  | 288 |  | 
| 556 |  |  |  |  |  |  | my @children	= @{ $self->children }; | 
| 557 | 50 |  |  | 50 |  | 21428 | if (scalar(@children) == 1) { | 
|  | 50 |  |  |  |  | 145 |  | 
|  | 50 |  |  |  |  | 185 |  | 
| 558 |  |  |  |  |  |  | return $children[0]->as_string; | 
| 559 | 0 |  |  | 0 | 0 | 0 | } else { | 
| 560 |  |  |  |  |  |  | return sprintf("(%s)", join($self->separator, map { $_->as_string } @children)); | 
| 561 | 3 |  |  | 3 | 0 | 16 | } | 
| 562 | 4 |  |  | 4 | 0 | 14 | } | 
| 563 |  |  |  |  |  |  | my $self	= shift; | 
| 564 | 5 |  |  | 5 | 0 | 3506 | return "Property Path " . $self->separator; | 
| 565 | 5 |  |  |  |  | 9 | } | 
|  | 5 |  |  |  |  | 15 |  | 
| 566 | 5 |  |  |  |  | 16 | with 'Attean::API::PropertyPath'; | 
| 567 | 5 | 100 |  |  |  | 79 | } | 
| 568 | 1 |  |  |  |  | 16 |  | 
| 569 |  |  |  |  |  |  | =item * L<Attean::API::UnionScopeVariables> | 
| 570 | 5 |  |  |  |  | 104 |  | 
| 571 | 5 |  |  |  |  | 19 | =cut | 
| 572 |  |  |  |  |  |  |  | 
| 573 |  |  |  |  |  |  | use Moo::Role; | 
| 574 | 2 |  |  | 2 | 0 | 3 | my $self	= shift; | 
| 575 | 2 |  |  |  |  | 6 | my $set		= Set::Scalar->new(); | 
| 576 |  |  |  |  |  |  | foreach my $c (@{ $self->children }) { | 
| 577 |  |  |  |  |  |  | $set->insert( $c->in_scope_variables ); | 
| 578 |  |  |  |  |  |  | } | 
| 579 |  |  |  |  |  |  | return $set->elements; | 
| 580 |  |  |  |  |  |  | } | 
| 581 |  |  |  |  |  |  | } | 
| 582 |  |  |  |  |  |  |  | 
| 583 |  |  |  |  |  |  | =item * L<Attean::API::IntersectionScopeVariables> | 
| 584 |  |  |  |  |  |  |  | 
| 585 | 50 |  |  | 50 |  | 24502 | =cut | 
|  | 50 |  |  |  |  | 97 |  | 
|  | 50 |  |  |  |  | 232 |  | 
| 586 |  |  |  |  |  |  |  | 
| 587 | 50 |  |  | 50 |  | 25495 | use Moo::Role; | 
|  | 50 |  |  |  |  | 94 |  | 
|  | 50 |  |  |  |  | 208 |  | 
| 588 |  |  |  |  |  |  | my $self	= shift; | 
| 589 |  |  |  |  |  |  | my @c		= @{ $self->children }; | 
| 590 |  |  |  |  |  |  | return unless scalar(@c); | 
| 591 |  |  |  |  |  |  | my $set		= Set::Scalar->new(shift(@c)->in_scope_variables); | 
| 592 | 7 |  |  | 7 | 0 | 5428 | foreach my $c (@c) { | 
| 593 | 7 |  |  |  |  | 10 | my $rhs	= Set::Scalar->new($c->in_scope_variables); | 
|  | 7 |  |  |  |  | 24 |  | 
| 594 | 7 | 100 |  |  |  | 21 | $set	= $set->intersection($rhs); | 
| 595 | 2 |  |  |  |  | 7 | } | 
| 596 |  |  |  |  |  |  | return $set->elements; | 
| 597 | 5 |  |  |  |  | 23 | } | 
|  | 10 |  |  |  |  | 46 |  | 
| 598 |  |  |  |  |  |  | } | 
| 599 |  |  |  |  |  |  |  | 
| 600 |  |  |  |  |  |  | 1; | 
| 601 | 2 |  |  | 2 | 0 | 3 |  | 
| 602 | 2 |  |  |  |  | 12 | =back | 
| 603 |  |  |  |  |  |  |  | 
| 604 |  |  |  |  |  |  | =head1 BUGS | 
| 605 |  |  |  |  |  |  |  | 
| 606 |  |  |  |  |  |  | Please report any bugs or feature requests to through the GitHub web interface | 
| 607 |  |  |  |  |  |  | at L<https://github.com/kasei/attean/issues>. | 
| 608 |  |  |  |  |  |  |  | 
| 609 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 610 |  |  |  |  |  |  |  | 
| 611 |  |  |  |  |  |  |  | 
| 612 | 50 |  |  | 50 |  | 23303 |  | 
|  | 50 |  |  |  |  | 96 |  | 
|  | 50 |  |  |  |  | 191 |  | 
| 613 |  |  |  |  |  |  | =head1 AUTHOR | 
| 614 | 21 |  |  | 21 | 0 | 124 |  | 
| 615 | 21 |  |  |  |  | 154 | Gregory Todd Williams  C<< <gwilliams@cpan.org> >> | 
| 616 | 21 |  |  |  |  | 1615 |  | 
|  | 21 |  |  |  |  | 82 |  | 
| 617 | 28 |  |  |  |  | 889 | =head1 COPYRIGHT | 
| 618 |  |  |  |  |  |  |  | 
| 619 | 21 |  |  |  |  | 2520 | Copyright (c) 2014--2022 Gregory Todd Williams. | 
| 620 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it under | 
| 621 |  |  |  |  |  |  | the same terms as Perl itself. | 
| 622 |  |  |  |  |  |  |  | 
| 623 |  |  |  |  |  |  | =cut |