| 1 | 50 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 2 | 50 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | Attean::API::Iterator - Typed iterator | ||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | This document describes Attean::API::Iterator version 0.040 | ||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | The Attean::API::Iterator role defines a common API for typed iterators. | ||||||||||||||||||||||||||||||||||
| 15 | This package also defines several type-specific iterator roles: | ||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | =over 4 | ||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | =item * L<Attean::API::TripleIterator> | ||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | =item * L<Attean::API::QuadIterator> | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | =item * L<Attean::API::MixedStatementIterator> | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | =item * L<Attean::API::MixedPatternIterator> | ||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | =item * L<Attean::API::ResultIterator> | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | =back | ||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | These roles will automatically be applied to iterators during construction when appropriate. | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | The following attributes exist: | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | =over 4 | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | =item C<< item_type >> | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | A string indicating the type of elements returned by the iterator. | ||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | =back | ||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | =head1 REQUIRED METHODS | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | The following methods are required by the L<Attean::API::Iterator> role: | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | =over 4 | ||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | =item C<< next >> | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | Returns the next element from the iterator, or C<< undef >> upon exhaustion. | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | =back | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | The L<Attean::API::Iterator> role provides default implementations of the | ||||||||||||||||||||||||||||||||||
| 60 | following methods: | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | =over 4 | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | =item C<< elements >> | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | Returns a list of all remaining elements in the iterator. | ||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | =item C<< map( \&mapper [, $result_type] ) >> | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | Returns a new L<Attean::API::Iterator> object with each element mapped using | ||||||||||||||||||||||||||||||||||
| 71 | the supplied C<< &mapper >> function. If the iterator elements are of the same | ||||||||||||||||||||||||||||||||||
| 72 | type as those in the referent iterator, only a mapping function is required. | ||||||||||||||||||||||||||||||||||
| 73 | Otherwise, the supplied L<Type::Tiny> C<< $result_type >> object must indicate | ||||||||||||||||||||||||||||||||||
| 74 | the new iterator's type information. | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | =item C<< grep( \&filter ) >> | ||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | Returns a new L<Attean::API::Iterator> object that filters elements from the | ||||||||||||||||||||||||||||||||||
| 79 | referent iterator based on whether calling C<< &filter( $element ) >> for each | ||||||||||||||||||||||||||||||||||
| 80 | C<< $element >> results in a true value. | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | =item C<< offset( $offset ) >> | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | Returns the L<Attean::API::Iterator> referent after skipping the first | ||||||||||||||||||||||||||||||||||
| 85 | C<< $offset >> elements. | ||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | =item C<< limit( $limit ) >> | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | Returns a new L<Attean::API::Iterator> object which returns the first | ||||||||||||||||||||||||||||||||||
| 90 | C<< $limit >> elements of the referent. | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | =item C<< materialize >> | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | Returns a new L<Attean::API::RepeatableIterator> object containing all the | ||||||||||||||||||||||||||||||||||
| 95 | elements from the referent. | ||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 50 | package Attean::API::Iterator 0.040 { | |||||||||||||||||||||||||||||||||
| 100 | 50 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 101 | 50 | ▶ | use Types::Standard qw(Str Object InstanceOf); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 102 | 50 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 50 | has 'item_type' => (is => 'ro', isa => Str, required => 1); | |||||||||||||||||||||||||||||||||
| 107 | 50 | requires 'next'; | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 647 | ▶ | sub BUILD {} | ||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 110 | 1798 | ▶ | around 'BUILD' => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||
| 111 | 1798 | my $orig = shift; | |||||||||||||||||||||||||||||||||
| 112 | 1798 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 113 | 1798 | my $args = shift; | |||||||||||||||||||||||||||||||||
| 114 | 1798 | $self->$orig($args); | |||||||||||||||||||||||||||||||||
| 115 | 1796 | my $role = $self->item_type; | |||||||||||||||||||||||||||||||||
| 116 | 1796 | ▶ | if (Moo::Role->is_role($role)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 117 | 2525 | ▶ | my $check = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 118 | 2525 | my $check = shift; | |||||||||||||||||||||||||||||||||
| 119 | 2525 | ▶ | return ($role eq $check or Moo::Role::does_role($role, $check)); | ||||||||||||||||||||||||||||||||
|
Condition100%3/3
$role eq $check || Moo::Role::does_role($role, $check)
MC/DC100%2/2
$role eq $check || Moo::Role::does_role($role, $check)
$role eq $check
Moo::Role::does_role($role, $check)
Truth table100%3/3
A || B
A= $role eq $checkB= Moo::Role::does_role($role, $check)
| |||||||||||||||||||||||||||||||||||
| 120 | 901 | }; | |||||||||||||||||||||||||||||||||
| 121 | 901 | ▶ | if ($check->('Attean::API::Quad')) { | ||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||
| 122 | 436 | Moo::Role->apply_roles_to_object($self, 'Attean::API::QuadIterator'); | |||||||||||||||||||||||||||||||||
| 123 | } elsif ($check->('Attean::API::Triple')) { | ||||||||||||||||||||||||||||||||||
| 124 | 182 | Moo::Role->apply_roles_to_object($self, 'Attean::API::TripleIterator'); | |||||||||||||||||||||||||||||||||
| 125 | } elsif ($check->('Attean::API::TripleOrQuad')) { | ||||||||||||||||||||||||||||||||||
| 126 | 13 | Moo::Role->apply_roles_to_object($self, 'Attean::API::MixedStatementIterator'); | |||||||||||||||||||||||||||||||||
| 127 | } elsif ($check->('Attean::API::TripleOrQuadPattern')) { | ||||||||||||||||||||||||||||||||||
| 128 | 30 | Moo::Role->apply_roles_to_object($self, 'Attean::API::MixedPatternIterator'); | |||||||||||||||||||||||||||||||||
| 129 | } elsif ($check->('Attean::API::Result')) { | ||||||||||||||||||||||||||||||||||
| 130 | 152 | Moo::Role->apply_roles_to_object($self, 'Attean::API::ResultIterator'); | |||||||||||||||||||||||||||||||||
| 131 | 152 | ▶ | my $vars = $args->{variables} // confess "Construction of a Attean::API::ResultIterator must include a variables list"; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"variables"} // confess("Construction of a Attean::API::ResultIterator must include a variables list")
MC/DC0%0/1
$args->{"variables"} // confess("Construction of a Attean::API::ResultIterator must include a variables list")
$args->{"variables"}
Truth table50%1/2
A
A= $args->{"variables"}
| |||||||||||||||||||||||||||||||||||
| 132 | 152 | $self->variables($vars); | |||||||||||||||||||||||||||||||||
| 133 | } elsif ($check->('Attean::API::Term')) { | ||||||||||||||||||||||||||||||||||
| 134 | 84 | Moo::Role->apply_roles_to_object($self, 'Attean::API::TermIterator'); | |||||||||||||||||||||||||||||||||
| 135 | } elsif ($check->('Attean::API::ResultOrTerm')) { | ||||||||||||||||||||||||||||||||||
| 136 | 2 | Moo::Role->apply_roles_to_object($self, 'Attean::API::ResultOrTermIterator'); | |||||||||||||||||||||||||||||||||
| 137 | 2 | ▶ | $self->variables($args->{variables} || []); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'variables'} || []
MC/DC0%0/1
$args->{'variables'} || []
$args->{'variables'}
Truth table50%1/2
A
A= $args->{'variables'}
| |||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | 901 | ▶ | if ($self->does('Attean::API::RepeatableIterator') and $check->('Attean::API::Binding')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->does("Attean::API::RepeatableIterator") and &$check("Attean::API::Binding")
MC/DC100%2/2
$self->does("Attean::API::RepeatableIterator") and &$check("Attean::API::Binding")
$self->does("Attean::API::RepeatableIterator")
&$check("Attean::API::Binding")
Truth table100%3/3
A and B
A= $self->does("Attean::API::RepeatableIterator")B= &$check("Attean::API::Binding")
| |||||||||||||||||||||||||||||||||||
| 141 | 205 | Moo::Role->apply_roles_to_object($self, 'Attean::API::CanonicalizingBindingSet'); | |||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||
| 144 | 50 | }; | |||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | 50 | ▶ | if ($ENV{ATTEAN_TYPECHECK}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | around 'next' => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 148 | 0 | my $orig = shift; | |||||||||||||||||||||||||||||||||
| 149 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 150 | 0 | my $type = $self->item_type; | |||||||||||||||||||||||||||||||||
| 151 | 0 | my $class = ref($self); | |||||||||||||||||||||||||||||||||
| 152 | 0 | my $term = $self->$orig(@_); | |||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | return unless defined($term); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if (blessed($term)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | unless ($term->does($type) or $term->isa($type)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$term->does($type) or $term->isa($type)
MC/DC0%0/2
$term->does($type) or $term->isa($type)
$term->does($type)
$term->isa($type)
Truth table0%0/3
A or B
A= $term->does($type)B= $term->isa($type)
| |||||||||||||||||||||||||||||||||||
| 156 | 0 | die "${class} returned an element that failed conformance check for $type: $term"; | |||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||
| 159 | 0 | return $term; | |||||||||||||||||||||||||||||||||
| 160 | 0 | }; | |||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||
| 163 | 61 | ▶ | sub elements { | ||||||||||||||||||||||||||||||||
|
Subroutine
elements: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 164 | 61 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 165 | 61 | my @elements; | |||||||||||||||||||||||||||||||||
| 166 | 61 | ▶ | while (my $item = $self->next) { push(@elements, $item); } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 167 | 61 | return @elements; | |||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||
| 170 | 165 | ▶ | sub map { | ||||||||||||||||||||||||||||||||
|
Subroutine
map: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 171 | 165 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 172 | 165 | my $block = shift; | |||||||||||||||||||||||||||||||||
| 173 | 165 | ▶ | my $type = shift || $self->item_type; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $self->item_type
MC/DC0%0/2
shift() || $self->item_type
shift()
$self->item_type
Truth table66%2/3
A || B
A= shift()B= $self->item_type
| |||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | 165 | my $generator; | |||||||||||||||||||||||||||||||||
| 176 | 165 | ▶ | if (blessed($block) and $block->does('Attean::Mapper')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($block) and $block->does("Attean::Mapper")
MC/DC50%1/2
builtin::blessed($block) and $block->does("Attean::Mapper")
builtin::blessed($block)
$block->does("Attean::Mapper")
Truth table66%2/3
A and B
A= builtin::blessed($block)B= $block->does("Attean::Mapper")
| |||||||||||||||||||||||||||||||||||
| 177 | 4 | ▶ | $generator = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||
| 178 | 4 | my $item = $self->next(); | |||||||||||||||||||||||||||||||||
| 179 | 4 | ▶ | return unless defined($item); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 180 | 4 | my $new = $block->map($item); | |||||||||||||||||||||||||||||||||
| 181 | 4 | return $new; | |||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||
| 183 | 2 | } else { | |||||||||||||||||||||||||||||||||
| 184 | 163 | my @buffer; | |||||||||||||||||||||||||||||||||
| 185 | 503 | ▶ | $generator = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 186 | 503 | while (1) { | |||||||||||||||||||||||||||||||||
| 187 | 859 | ▶ | return shift(@buffer) if (scalar(@buffer)); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 188 | 503 | my $item = $self->next(); | |||||||||||||||||||||||||||||||||
| 189 | 503 | ▶ | return unless defined($item); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 190 | 356 | local($_) = $item; | |||||||||||||||||||||||||||||||||
| 191 | 356 | push(@buffer, $block->($item)); | |||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||
| 194 | 163 | } | |||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||
| 196 | # copy variables into new iterator if $self does ::ResultIterator or ::ResultOrTermIterator | ||||||||||||||||||||||||||||||||||
| 197 | 165 | my %args = @_; | |||||||||||||||||||||||||||||||||
| 198 | 165 | ▶ | if ($self->can('variables') and not exists $args{variables}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->can("variables") and not exists $args{"variables"}
MC/DC100%2/2
$self->can("variables") and not exists $args{"variables"}
$self->can("variables")
not exists $args{"variables"}
Truth table100%3/3
A and not(B)
A= $self->can("variables")B= not exists $args{"variables"}
| |||||||||||||||||||||||||||||||||||
| 199 | 101 | $args{variables} = $self->variables; | |||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||
| 202 | 165 | return Attean::CodeIterator->new( %args, item_type => $type, generator => $generator ); | |||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||
| 205 | 195 | ▶ | sub grep { | ||||||||||||||||||||||||||||||||
|
Subroutine
grep: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 206 | 195 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 207 | 195 | my $block = shift; | |||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||
| 209 | # copy variables into new iterator if $self does ::ResultIterator or ::ResultOrTermIterator | ||||||||||||||||||||||||||||||||||
| 210 | 195 | my %args = @_; | |||||||||||||||||||||||||||||||||
| 211 | 195 | ▶ | if ($self->can('variables') and not exists $args{variables}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->can("variables") and not exists $args{"variables"}
MC/DC50%1/2
$self->can("variables") and not exists $args{"variables"}
$self->can("variables")
not exists $args{"variables"}
Truth table66%2/3
A and not(B)
A= $self->can("variables")B= not exists $args{"variables"}
| |||||||||||||||||||||||||||||||||||
| 212 | 182 | $args{variables} = $self->variables; | |||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||
| 215 | Attean::CodeIterator->new( | ||||||||||||||||||||||||||||||||||
| 216 | %args, | ||||||||||||||||||||||||||||||||||
| 217 | item_type => $self->item_type, | ||||||||||||||||||||||||||||||||||
| 218 | 682 | ▶ | generator => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 219 | 682 | while (1) { | |||||||||||||||||||||||||||||||||
| 220 | 1196 | my $item = $self->next(); | |||||||||||||||||||||||||||||||||
| 221 | 1196 | ▶ | return unless defined($item); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 222 | 1014 | local($_) = $item; | |||||||||||||||||||||||||||||||||
| 223 | 1014 | ▶ | return $item if ($block->($item)); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||
| 226 | 195 | ); | |||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||
| 229 | 3 | ▶ | sub offset { | ||||||||||||||||||||||||||||||||
|
Subroutine
offset: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 230 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 231 | 3 | my $offset = shift; | |||||||||||||||||||||||||||||||||
| 232 | 3 | $self->next for (1 .. $offset); | |||||||||||||||||||||||||||||||||
| 233 | 3 | return $self; | |||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||
| 236 | 3 | ▶ | sub limit { | ||||||||||||||||||||||||||||||||
|
Subroutine
limit: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 237 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 238 | 3 | my $limit = shift; | |||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||
| 240 | # copy variables into new iterator if $self does ::ResultIterator or ::ResultOrTermIterator | ||||||||||||||||||||||||||||||||||
| 241 | 3 | my %args = @_; | |||||||||||||||||||||||||||||||||
| 242 | 3 | ▶ | if ($self->can('variables') and not exists $args{variables}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->can("variables") and not exists $args{"variables"}
MC/DC50%1/2
$self->can("variables") and not exists $args{"variables"}
$self->can("variables")
not exists $args{"variables"}
Truth table66%2/3
A and not(B)
A= $self->can("variables")B= not exists $args{"variables"}
| |||||||||||||||||||||||||||||||||||
| 243 | 2 | $args{variables} = $self->variables; | |||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||
| 246 | Attean::CodeIterator->new( | ||||||||||||||||||||||||||||||||||
| 247 | %args, | ||||||||||||||||||||||||||||||||||
| 248 | item_type => $self->item_type, | ||||||||||||||||||||||||||||||||||
| 249 | 10 | ▶ | generator => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 250 | 10 | ▶ | return unless $limit; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 251 | 7 | my $item = $self->next(); | |||||||||||||||||||||||||||||||||
| 252 | 7 | ▶ | return unless defined($item); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 253 | 7 | $limit--; | |||||||||||||||||||||||||||||||||
| 254 | 7 | return $item; | |||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||
| 256 | 3 | ); | |||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | sub materialize { | ||||||||||||||||||||||||||||||||
|
Subroutine
materialize: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 260 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 261 | 0 | my @data = $self->elements; | |||||||||||||||||||||||||||||||||
| 262 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if ($self->can('variables') and not exists $args{variables}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->can("variables") and not exists $args{"variables"}
MC/DC0%0/2
$self->can("variables") and not exists $args{"variables"}
$self->can("variables")
not exists $args{"variables"}
Truth table0%0/3
A and not(B)
A= $self->can("variables")B= not exists $args{"variables"}
| |||||||||||||||||||||||||||||||||||
| 264 | 0 | $args{variables} = $self->variables; | |||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||
| 267 | 0 | return Attean::ListIterator->new( %args, values => \@data, item_type => $self->item_type ); | |||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||
| 270 | =item C<< debug( [$name] ) >> | ||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||
| 272 | Print each item as it is consumed (with the string generated by C<< as_string >>), prepended by C<< $name >>. | ||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||
| 274 | =cut | ||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 277 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | my $name = shift // 'Iterator item'; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() // "Iterator item"
MC/DC0%0/1
shift() // "Iterator item"
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | return $self->grep(sub { my $r = shift; say "$name: " . $r->as_string; return 1; }); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||
| 283 | 50 | package Attean::API::StringyItemIterator 0.040 { | |||||||||||||||||||||||||||||||||
| 284 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 285 | 2 | ▶ | sub uniq { | ||||||||||||||||||||||||||||||||
|
Subroutine
uniq: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 286 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||
| 288 | 2 | my %seen; | |||||||||||||||||||||||||||||||||
| 289 | 16 | ▶ | return $self->grep(sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 290 | 16 | my $r = shift; | |||||||||||||||||||||||||||||||||
| 291 | 16 | return not($seen{ $r->as_string }++); | |||||||||||||||||||||||||||||||||
| 292 | 2 | }); | |||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||
| 296 | 50 | package Attean::API::RepeatableIterator 0.040 { | |||||||||||||||||||||||||||||||||
| 297 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 298 | 50 | requires 'reset'; | |||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||
| 300 | 843 | ▶ | sub elements { | ||||||||||||||||||||||||||||||||
|
Subroutine
elements: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 301 | 843 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 302 | 843 | my @elements; | |||||||||||||||||||||||||||||||||
| 303 | 843 | ▶ | while (my $item = $self->next) { push(@elements, $item); } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 304 | 843 | $self->reset; | |||||||||||||||||||||||||||||||||
| 305 | 843 | return @elements; | |||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | sub peek { | ||||||||||||||||||||||||||||||||
|
Subroutine
peek: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 309 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 310 | 0 | my $item = $self->next; | |||||||||||||||||||||||||||||||||
| 311 | 0 | $self->reset; | |||||||||||||||||||||||||||||||||
| 312 | 0 | return $item; | |||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||
| 315 | 38 | ▶ | sub materialize { | ||||||||||||||||||||||||||||||||
|
Subroutine
materialize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 316 | 38 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 317 | 38 | return $self; | |||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | sub size { | ||||||||||||||||||||||||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 321 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 322 | 0 | my @elements = $self->elements; | |||||||||||||||||||||||||||||||||
| 323 | 0 | return scalar(@elements); | |||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||
| 326 | 50 | with 'Attean::API::Iterator'; | |||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||
| 329 | 50 | package Attean::API::CanonicalizingBindingIterator { | |||||||||||||||||||||||||||||||||
| 330 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | sub canonicalize { | ||||||||||||||||||||||||||||||||
|
Subroutine
canonicalize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 332 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 333 | 0 | my $mapper = Attean::TermMap->canonicalization_map; | |||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | return $self->map(sub { shift->apply_map( $mapper ) }); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||
| 338 | 50 | package Attean::API::ResultOrTermIterator 0.040 { | |||||||||||||||||||||||||||||||||
| 339 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 340 | 50 | ▶ | use Types::Standard qw(ArrayRef Str); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 341 | 2 | ▶ | has 'variables' => (is => 'rw', isa => ArrayRef[Str], default => sub { [] }); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 342 | 50 | with 'Attean::API::StringyItemIterator'; | |||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | sub canonicalize { | ||||||||||||||||||||||||||||||||
|
Subroutine
canonicalize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 345 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 346 | 0 | my $mapper = Attean::TermMap->canonicalization_map; | |||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | return $self->map(sub{ | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 348 | 0 | my $item = shift; | |||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if ($item->does('Attean::API::Term')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 350 | 0 | return $mapper->map($item); | |||||||||||||||||||||||||||||||||
| 351 | } else { | ||||||||||||||||||||||||||||||||||
| 352 | 0 | my %values = map { $_ => $mapper->map($item->value($_)) } $item->variables; | |||||||||||||||||||||||||||||||||
| 353 | 0 | return Attean::Result->new( bindings => \%values ); | |||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||
| 355 | 0 | }); | |||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||
| 358 | 7 | ▶ | around 'grep' => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 359 | 7 | my $orig = shift; | |||||||||||||||||||||||||||||||||
| 360 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 361 | 7 | my $block = shift; | |||||||||||||||||||||||||||||||||
| 362 | 7 | my $iter = $orig->($self, $block, @_); | |||||||||||||||||||||||||||||||||
| 363 | Attean::CodeIterator->new( | ||||||||||||||||||||||||||||||||||
| 364 | item_type => $iter->item_type, | ||||||||||||||||||||||||||||||||||
| 365 | 13 | ▶ | generator => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 366 | 13 | return $iter->next(); | |||||||||||||||||||||||||||||||||
| 367 | }, | ||||||||||||||||||||||||||||||||||
| 368 | 7 | variables => $self->variables, | |||||||||||||||||||||||||||||||||
| 369 | ); | ||||||||||||||||||||||||||||||||||
| 370 | 50 | }; | |||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||
| 373 | 50 | package Attean::API::StatementIterator 0.040 { | |||||||||||||||||||||||||||||||||
| 374 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 375 | 50 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 376 | 50 | with 'Attean::API::StringyItemIterator'; | |||||||||||||||||||||||||||||||||
| 377 | 50 | requires 'variables'; | |||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||
| 379 | 123 | ▶ | sub matching_pattern { | ||||||||||||||||||||||||||||||||
|
Subroutine
matching_pattern: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 380 | 123 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 381 | 123 | my @nodes = @_; | |||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||
| 383 | 123 | ▶ | if (scalar(@nodes) == 1 and $nodes[0]->does('Attean::API::QuadPattern')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @nodes == 1 and $nodes[0]->does("Attean::API::QuadPattern")
MC/DC100%2/2
scalar @nodes == 1 and $nodes[0]->does("Attean::API::QuadPattern")
scalar @nodes == 1
$nodes[0]->does("Attean::API::QuadPattern")
Truth table100%3/3
A and B
A= scalar @nodes == 1B= $nodes[0]->does("Attean::API::QuadPattern")
| |||||||||||||||||||||||||||||||||||
| 384 | 101 | my $pattern = $nodes[0]; | |||||||||||||||||||||||||||||||||
| 385 | 101 | @nodes = $pattern->values; | |||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||
| 388 | 123 | my %bound; | |||||||||||||||||||||||||||||||||
| 389 | 123 | my @pos_names = $self->variables; | |||||||||||||||||||||||||||||||||
| 390 | 123 | foreach my $pos (0 .. $#pos_names) { | |||||||||||||||||||||||||||||||||
| 391 | 492 | my $n = $nodes[ $pos ]; | |||||||||||||||||||||||||||||||||
| 392 | 492 | ▶ | if (blessed($n)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 393 | 419 | $bound{ $pos_names[$pos] } = $n; | |||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||
| 397 | 123 | my $pattern = Attean::QuadPattern->new( %bound ); | |||||||||||||||||||||||||||||||||
| 398 | 231 | ▶ | return $self->grep(sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 399 | 231 | my $q = shift; | |||||||||||||||||||||||||||||||||
| 400 | 231 | my $binding = $pattern->unify($q); | |||||||||||||||||||||||||||||||||
| 401 | 231 | ▶ | return $binding ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 402 | 123 | }); | |||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||
| 406 | 50 | package Attean::API::TripleIterator 0.040 { | |||||||||||||||||||||||||||||||||
| 407 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 408 | 50 | with 'Attean::API::CanonicalizingBindingIterator'; | |||||||||||||||||||||||||||||||||
| 409 | 50 | with 'Attean::API::StatementIterator'; | |||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||
| 411 | 30 | ▶ | sub as_quads { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_quads: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 412 | 30 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 413 | 30 | my $graph = shift; | |||||||||||||||||||||||||||||||||
| 414 | 30 | ▶ | return $self->map(sub { $_->as_quad($graph) }, 'Attean::API::Quad'); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||
| 417 | 101 | ▶ | sub variables { | ||||||||||||||||||||||||||||||||
|
Subroutine
variables: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 418 | 101 | return qw(subject predicate object); | |||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||
| 422 | 50 | package Attean::API::QuadIterator 0.040 { | |||||||||||||||||||||||||||||||||
| 423 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 424 | 50 | with 'Attean::API::CanonicalizingBindingIterator'; | |||||||||||||||||||||||||||||||||
| 425 | 50 | with 'Attean::API::StatementIterator'; | |||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||
| 427 | 267 | ▶ | sub variables { | ||||||||||||||||||||||||||||||||
|
Subroutine
variables: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 428 | 267 | return qw(subject predicate object graph); | |||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | sub as_triples { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_triples: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 432 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | return $self->map(sub { Attean::Triple->new(($_->values)[0..2]) }, 'Attean::API::Triple'); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||
| 437 | 50 | package Attean::API::MixedStatementIterator 0.040 { | |||||||||||||||||||||||||||||||||
| 438 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 439 | 50 | with 'Attean::API::CanonicalizingBindingIterator'; | |||||||||||||||||||||||||||||||||
| 440 | 50 | with 'Attean::API::StringyItemIterator'; | |||||||||||||||||||||||||||||||||
| 441 | 2 | ▶ | sub as_quads { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_quads: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 442 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 443 | 2 | my $graph = shift; | |||||||||||||||||||||||||||||||||
| 444 | return $self->map( | ||||||||||||||||||||||||||||||||||
| 445 | 10 | ▶ | sub { $_->does('Attean::API::Quad') ? $_ : $_->as_quad($graph) }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 446 | 2 | 'Attean::API::Quad' | |||||||||||||||||||||||||||||||||
| 447 | ); | ||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||
| 451 | 50 | package Attean::API::MixedPatternIterator 0.040 { | |||||||||||||||||||||||||||||||||
| 452 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 453 | 50 | with 'Attean::API::CanonicalizingBindingIterator'; | |||||||||||||||||||||||||||||||||
| 454 | 50 | with 'Attean::API::StringyItemIterator'; | |||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | sub as_quads { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_quads: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 456 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 457 | 0 | my $graph = shift; | |||||||||||||||||||||||||||||||||
| 458 | return $self->map( | ||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | sub { $_->does('Attean::API::QuadPattern') ? $_ : $_->as_quad($graph) }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 460 | 0 | 'Attean::API::QuadPattern' | |||||||||||||||||||||||||||||||||
| 461 | ); | ||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||
| 465 | 50 | package Attean::API::ResultIterator 0.040 { | |||||||||||||||||||||||||||||||||
| 466 | 50 | ▶ | use Types::Standard qw(Str ArrayRef); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 467 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||
| 469 | 50 | with 'Attean::API::CanonicalizingBindingIterator'; | |||||||||||||||||||||||||||||||||
| 470 | 50 | with 'Attean::API::StringyItemIterator'; | |||||||||||||||||||||||||||||||||
| 471 | 50 | has 'variables' => (is => 'rw', isa => ArrayRef[Str], required => 1); | |||||||||||||||||||||||||||||||||
| 472 | 5 | ▶ | sub join { | ||||||||||||||||||||||||||||||||
|
Subroutine
join: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 473 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 474 | 5 | my $rhs = shift; | |||||||||||||||||||||||||||||||||
| 475 | 5 | my @vars = keys %{ { map { $_ => 1 } (@{ $self->variables }, @{ $rhs->variables }) } }; | |||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||
| 477 | 5 | my @rhs = $rhs->elements; | |||||||||||||||||||||||||||||||||
| 478 | 5 | my @results; | |||||||||||||||||||||||||||||||||
| 479 | 5 | ▶ | while (my $lhs = $self->next) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 480 | 6 | foreach my $rhs (@rhs) { | |||||||||||||||||||||||||||||||||
| 481 | 9 | ▶ | if (my $j = $lhs->join($rhs)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 482 | 7 | push(@results, $j); | |||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||
| 486 | 5 | return Attean::ListIterator->new( values => \@results, item_type => $self->item_type, variables => \@vars); | |||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||
| 489 | 50 | with 'Attean::API::ResultOrTermIterator'; | |||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||
| 492 | 50 | package Attean::API::TermIterator 0.040 { | |||||||||||||||||||||||||||||||||
| 493 | 50 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | sub canonicalize { | ||||||||||||||||||||||||||||||||
|
Subroutine
canonicalize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 495 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 496 | 0 | my $mapper = Attean::TermMap->canonicalization_map; | |||||||||||||||||||||||||||||||||
| 497 | 0 | return $self->map( $mapper ); | |||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||
| 500 | # for an iterator of terms representing something like an ASK query, pull the first result, and return | ||||||||||||||||||||||||||||||||||
| 501 | # a boolean value based on the term; | ||||||||||||||||||||||||||||||||||
| 502 | 4 | ▶ | sub get_boolean { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_boolean: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 503 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 504 | 4 | my $v = $self->next(); | |||||||||||||||||||||||||||||||||
| 505 | 4 | ▶ | return 0 unless ($v); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 506 | 4 | my $b = $v->canonicalized_term->value; | |||||||||||||||||||||||||||||||||
| 507 | 4 | return ($b eq 'true'); | |||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||
| 510 | 50 | with 'Attean::API::CanonicalizingBindingIterator'; | |||||||||||||||||||||||||||||||||
| 511 | 50 | with 'Attean::API::StringyItemIterator'; | |||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||
| 514 | 50 | 1; | |||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||
| 516 | __END__ | ||||||||||||||||||||||||||||||||||