| 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::QuadModel - RDF model backed by a quad-store | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | This document describes Attean::QuadModel version 0.040 | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | use v5.14; | ||||||||||||||||||||||||||||
| 15 | use Attean; | ||||||||||||||||||||||||||||
| 16 | my $model = Attean::QuadModel->new( store => $store ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | The Attean::QuadModel class represents a model that is backed by a single | ||||||||||||||||||||||||||||
| 21 | L<Attean::API::QuadStore|Attean::API::Store> object. | ||||||||||||||||||||||||||||
| 22 | It conforms to the L<Attean::API::Model> role. | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | The Attean::QuadModel constructor requires one named argument: | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =over 4 | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =item store | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | A L<Attean::API::QuadStore|Attean::API::Store> object representing the backing | ||||||||||||||||||||||||||||
| 31 | quad-store. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =back | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 METHODS | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =over 4 | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 45 | package Attean::QuadModel 0.040 { | |||||||||||||||||||||||||||
| 42 | 50 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 50 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 50 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 45 | has 'store' => ( | |||||||||||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||||||||||||
| 48 | does => 'Attean::API::QuadStore', | ||||||||||||||||||||||||||||
| 49 | required => 1, | ||||||||||||||||||||||||||||
| 50 | handles => [qw(size count_quads count_quads_estimate get_graphs holds)], | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =item C<< get_quads ( $subject, $predicate, $object, $graph ) >> | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | Returns an L<Attean::API::Iterator> for quads in the model that match the | ||||||||||||||||||||||||||||
| 56 | supplied C<< $subject >>, C<< $predicate >>, C<< $object >>, and C<< $graph >>. | ||||||||||||||||||||||||||||
| 57 | Any of these terms may be undefined or a L<Attean::API::Variable> object, in | ||||||||||||||||||||||||||||
| 58 | which case that term will be considered as a wildcard for the purposes of | ||||||||||||||||||||||||||||
| 59 | matching. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | The returned iterator conforms to both L<Attean::API::Iterator> and | ||||||||||||||||||||||||||||
| 62 | L<Attean::API::QuadIterator>. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 89 | ▶ | sub get_quads { | ||||||||||||||||||||||||||
|
Subroutine
get_quads: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 89 | my $self = shift; | |||||||||||||||||||||||||||
| 68 | 89 | my @nodes = @_[0..3]; | |||||||||||||||||||||||||||
| 69 | 89 | foreach my $i (0..3) { | |||||||||||||||||||||||||||
| 70 | 356 | my $t = $nodes[$i]; | |||||||||||||||||||||||||||
| 71 | 356 | ▶ | if (not(ref($t)) or reftype($t) ne 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $t or builtin::reftype($t) ne "ARRAY"
MC/DC100%2/2
not ref $t or builtin::reftype($t) ne "ARRAY"
not ref $t
builtin::reftype($t) ne "ARRAY"
Truth table100%3/3
not(A) or B
A= not ref $tB= builtin::reftype($t) ne "ARRAY"
| |||||||||||||||||||||||||||||
| 72 | 345 | $nodes[$i] = [$t]; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 89 | my @iters; | |||||||||||||||||||||||||||
| 77 | 89 | foreach my $s (@{ $nodes[0] }) { | |||||||||||||||||||||||||||
| 78 | 89 | foreach my $p (@{ $nodes[1] }) { | |||||||||||||||||||||||||||
| 79 | 91 | foreach my $o (@{ $nodes[2] }) { | |||||||||||||||||||||||||||
| 80 | 91 | foreach my $g (@{ $nodes[3] }) { | |||||||||||||||||||||||||||
| 81 | 95 | push(@iters, $self->store->get_quads($s, $p, $o, $g)); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 89 | ▶ | if (scalar(@iters) == 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 88 | 0 | return Attean::ListIterator->new(values => [], item_type => 'Attean::API::Quad'); | |||||||||||||||||||||||||||
| 89 | } elsif (scalar(@iters) == 1) { | ||||||||||||||||||||||||||||
| 90 | 87 | return shift(@iters); | |||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||
| 92 | 2 | return Attean::IteratorSequence->new( iterators => \@iters, item_type => $iters[0]->item_type ); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =item C<< plans_for_algebra( $algebra, $model, $active_graphs, $default_graphs ) >> | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Delegates to the underlying store if the store consumes Attean::API::CostPlanner. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 130 | ▶ | sub plans_for_algebra { | ||||||||||||||||||||||||||
|
Subroutine
plans_for_algebra: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 130 | my $self = shift; | |||||||||||||||||||||||||||
| 104 | 130 | ▶ | if ($self->store->does('Attean::API::CostPlanner')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 130 | return $self->store->plans_for_algebra(@_); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 0 | return; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =item C<< cost_for_plan( $plan ) >> | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Delegates to the underlying store if the store consumes Attean::API::CostPlanner. | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 1066 | ▶ | sub cost_for_plan { | ||||||||||||||||||||||||||
|
Subroutine
cost_for_plan: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 1066 | my $self = shift; | |||||||||||||||||||||||||||
| 118 | 1066 | ▶ | if ($self->store->does('Attean::API::CostPlanner')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 1066 | return $self->store->cost_for_plan(@_); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 0 | return; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 45 | with 'Attean::API::Model'; | |||||||||||||||||||||||||||
| 125 | 45 | with 'Attean::API::CostPlanner'; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 45 | package Attean::MutableQuadModel 0.040 { | |||||||||||||||||||||||||||
| 130 | 50 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 131 | 45 | extends 'Attean::QuadModel'; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 45 | has 'store' => ( | |||||||||||||||||||||||||||
| 134 | is => 'ro', | ||||||||||||||||||||||||||||
| 135 | does => 'Attean::API::MutableQuadStore', | ||||||||||||||||||||||||||||
| 136 | required => 1, | ||||||||||||||||||||||||||||
| 137 | handles => [qw(size count_quads count_quads_estimate add_quad remove_quad get_graphs create_graph drop_graph clear_graph add_iter)], | ||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 45 | with 'Attean::API::MutableModel'; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 45 | 1; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | __END__ | ||||||||||||||||||||||||||||