| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 50 |  |  | 50 |  | 696 | use v5.14; | 
|  | 50 |  |  |  |  | 148 |  | 
| 2 | 50 |  |  | 50 |  | 258 | use warnings; | 
|  | 50 |  |  |  |  | 114 |  | 
|  | 50 |  |  |  |  | 2213 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | =head1 NAME | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | Attean::API::Store - Triple/quad store role | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | =head1 VERSION | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | This document describes Attean::Store version 0.033 | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | The Attean::Store role is an empty role that more specialized roles conform to: | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =over 4 | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =item * L<Attean::API::TripleStore> | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | =item * L<Attean::API::MutableTripleStore> | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =item * L<Attean::API::ETagCacheableTripleStore> | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =item * L<Attean::API::TimeCacheableTripleStore> | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =item * L<Attean::API::QuadStore> | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | =item * L<Attean::API::MutableQuadStore> | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =item * L<Attean::API::ETagCacheableQuadStore> | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =item * L<Attean::API::TimeCacheableQuadStore> | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =back | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =cut | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | use Moo::Role; | 
| 39 | 50 |  |  | 50 |  | 276 | } | 
|  | 50 |  |  |  |  | 101 |  | 
|  | 50 |  |  |  |  | 284 |  | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | use Scalar::Util qw(blessed); | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 50 |  |  | 50 |  | 16575 | use Moo::Role; | 
|  | 50 |  |  |  |  | 115 |  | 
|  | 50 |  |  |  |  | 2369 |  | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 50 |  |  | 50 |  | 285 | with 'Attean::API::Store'; | 
|  | 50 |  |  |  |  | 138 |  | 
|  | 50 |  |  |  |  | 237 |  | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | requires 'get_triples'; | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | before 'get_triples' => sub { | 
| 50 |  |  |  |  |  |  | if (scalar(@_) == 2 and blessed($_[1]) and not($_[1]->does('Attean::API::TermOrVariable'))) { | 
| 51 |  |  |  |  |  |  | my $type	= ref($_[0]); | 
| 52 |  |  |  |  |  |  | die "get_triples called with a single $type argument, but expecting a list of terms/variables"; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  | }; | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | my $self	= shift; | 
| 57 |  |  |  |  |  |  | my $iter	= $self->get_triples(@_); | 
| 58 |  |  |  |  |  |  | my $count	= 0; | 
| 59 | 25 |  |  | 25 | 0 | 592 | while (my $r = $iter->next) { | 
| 60 | 25 |  |  |  |  | 409 | $count++; | 
| 61 | 25 |  |  |  |  | 642 | } | 
| 62 | 25 |  |  |  |  | 63 | return $count; | 
| 63 | 209 |  |  |  |  | 384 | } | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 25 |  |  |  |  | 246 | my $self	= shift; | 
| 66 |  |  |  |  |  |  | return $self->count_triples(@_); | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 1 |  |  | 1 | 0 | 152 | my $self	= shift; | 
| 70 | 1 |  |  |  |  | 3 | return $self->count_triples(); | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | my $self = shift; | 
| 74 | 10 |  |  | 10 | 0 | 473 | return ($self->count_triples_estimate(@_) > 0) | 
| 75 | 10 |  |  |  |  | 25 | } | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 0 |  |  | 0 | 0 | 0 | use Moo::Role; | 
| 80 | 0 |  |  |  |  | 0 | with 'Attean::API::TripleStore'; | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | requires 'add_triple'; | 
| 83 |  |  |  |  |  |  | requires 'remove_triple'; | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | before 'add_triple' => sub { | 
| 86 | 50 |  |  | 50 |  | 28449 | my $self	= shift; | 
|  | 50 |  |  |  |  | 128 |  | 
|  | 50 |  |  |  |  | 199 |  | 
| 87 |  |  |  |  |  |  | my $quad	= shift; | 
| 88 |  |  |  |  |  |  | unless ($quad->is_ground) { | 
| 89 |  |  |  |  |  |  | die "Cannot add a non-ground triple (with variables) to a model"; | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  | }; | 
| 92 |  |  |  |  |  |  | } | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | use Moo::Role; | 
| 95 |  |  |  |  |  |  | with 'Attean::API::TripleStore'; | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | requires 'etag_value_for_triples'; | 
| 98 |  |  |  |  |  |  | } | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | use Moo::Role; | 
| 101 |  |  |  |  |  |  | with 'Attean::API::TripleStore'; | 
| 102 | 50 |  |  | 50 |  | 20349 |  | 
|  | 50 |  |  |  |  | 133 |  | 
|  | 50 |  |  |  |  | 224 |  | 
| 103 |  |  |  |  |  |  | requires 'mtime_for_triples'; | 
| 104 |  |  |  |  |  |  | } | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | use Scalar::Util qw(blessed); | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | use Moo::Role; | 
| 109 | 50 |  |  | 50 |  | 15927 |  | 
|  | 50 |  |  |  |  | 133 |  | 
|  | 50 |  |  |  |  | 215 |  | 
| 110 |  |  |  |  |  |  | with 'Attean::API::Store'; | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | requires 'get_quads'; | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | before 'get_quads' => sub { | 
| 115 |  |  |  |  |  |  | if (scalar(@_) == 2 and blessed($_[1]) and not($_[1]->does('Attean::API::TermOrVariable'))) { | 
| 116 | 50 |  |  | 50 |  | 16832 | my $type	= ref($_[0]); | 
|  | 50 |  |  |  |  | 106 |  | 
|  | 50 |  |  |  |  | 2247 |  | 
| 117 |  |  |  |  |  |  | die "get_quads called with a single $type argument, but expecting a list of terms/variables"; | 
| 118 | 50 |  |  | 50 |  | 286 | } | 
|  | 50 |  |  |  |  | 154 |  | 
|  | 50 |  |  |  |  | 216 |  | 
| 119 |  |  |  |  |  |  | }; | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | my $self	= shift; | 
| 122 |  |  |  |  |  |  | my $iter	= $self->get_quads(@_); | 
| 123 |  |  |  |  |  |  | my $count	= 0; | 
| 124 |  |  |  |  |  |  | while (my $r = $iter->next) { | 
| 125 |  |  |  |  |  |  | $count++; | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  | return $count; | 
| 128 |  |  |  |  |  |  | } | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | my $self	= shift; | 
| 131 |  |  |  |  |  |  | return $self->count_quads(@_); | 
| 132 | 11 |  |  | 11 | 0 | 352 | } | 
| 133 | 11 |  |  |  |  | 194 |  | 
| 134 | 11 |  |  |  |  | 311 | my $self = shift; | 
| 135 | 11 |  |  |  |  | 25 | return ($self->count_quads_estimate(@_) > 0) | 
| 136 | 22 |  |  |  |  | 49 | } | 
| 137 |  |  |  |  |  |  |  | 
| 138 | 11 |  |  |  |  | 108 | my $self	= shift; | 
| 139 |  |  |  |  |  |  | my $iter	= $self->get_quads(@_); | 
| 140 |  |  |  |  |  |  | my %graphs; | 
| 141 |  |  |  |  |  |  | while (my $r = $iter->next) { | 
| 142 | 12 |  |  | 12 | 0 | 502 | my $g	= $r->graph; | 
| 143 | 12 |  |  |  |  | 37 | $graphs{ $g->as_string }++; | 
| 144 |  |  |  |  |  |  | } | 
| 145 |  |  |  |  |  |  | return Attean::ListIterator->new( values => [map { Attean::IRI->new($_) } keys %graphs], item_type => 'Attean::API::Term' ); | 
| 146 |  |  |  |  |  |  | } | 
| 147 | 0 |  |  | 0 | 0 | 0 |  | 
| 148 | 0 |  |  |  |  | 0 | my $self	= shift; | 
| 149 |  |  |  |  |  |  | return $self->count_quads(); | 
| 150 |  |  |  |  |  |  | } | 
| 151 |  |  |  |  |  |  | } | 
| 152 | 3 |  |  | 3 | 0 | 14 |  | 
| 153 | 3 |  |  |  |  | 49 | use Role::Tiny (); | 
| 154 | 3 |  |  |  |  | 83 | use Moo::Role; | 
| 155 | 3 |  |  |  |  | 10 | use Type::Tiny::Role; | 
| 156 | 7 |  |  |  |  | 13 | with 'Attean::API::QuadStore'; | 
| 157 | 7 |  |  |  |  | 17 |  | 
| 158 |  |  |  |  |  |  | requires 'add_quad'; | 
| 159 | 3 |  |  |  |  | 20 | requires 'remove_quad'; | 
|  | 3 |  |  |  |  | 166 |  | 
| 160 |  |  |  |  |  |  | requires 'create_graph'; | 
| 161 |  |  |  |  |  |  | requires 'drop_graph'; | 
| 162 |  |  |  |  |  |  | requires 'clear_graph'; | 
| 163 | 2 |  |  | 2 | 0 | 472 |  | 
| 164 | 2 |  |  |  |  | 4 | before 'add_quad' => sub { | 
| 165 |  |  |  |  |  |  | my $self	= shift; | 
| 166 |  |  |  |  |  |  | my $quad	= shift; | 
| 167 |  |  |  |  |  |  | unless ($quad->is_ground) { | 
| 168 |  |  |  |  |  |  | die "Cannot add a non-ground quad (with variables) to a store"; | 
| 169 | 50 |  |  | 50 |  | 31356 | } | 
|  | 50 |  |  |  |  | 113 |  | 
|  | 50 |  |  |  |  | 969 |  | 
| 170 | 50 |  |  | 50 |  | 269 | }; | 
|  | 50 |  |  |  |  | 112 |  | 
|  | 50 |  |  |  |  | 266 |  | 
| 171 | 50 |  |  | 50 |  | 15971 |  | 
|  | 50 |  |  |  |  | 122 |  | 
|  | 50 |  |  |  |  | 6074 |  | 
| 172 |  |  |  |  |  |  | my $self	= shift; | 
| 173 |  |  |  |  |  |  | my $iter	= shift; | 
| 174 |  |  |  |  |  |  | my $type	= $iter->item_type; | 
| 175 |  |  |  |  |  |  | use Data::Dumper; | 
| 176 |  |  |  |  |  |  | die "Iterator type $type isn't quads" unless (Role::Tiny::does_role($type, 'Attean::API::Quad')); | 
| 177 |  |  |  |  |  |  | while (my $q = $iter->next) { | 
| 178 |  |  |  |  |  |  | $self->add_quad($q); | 
| 179 |  |  |  |  |  |  | } | 
| 180 |  |  |  |  |  |  | } | 
| 181 |  |  |  |  |  |  | } | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | use Moo::Role; | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | with 'Attean::API::QuadStore'; | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | requires 'etag_value_for_quads'; | 
| 188 |  |  |  |  |  |  | } | 
| 189 | 29 |  |  | 29 | 0 | 4887 |  | 
| 190 | 29 |  |  |  |  | 86 | use Moo::Role; | 
| 191 | 29 |  |  |  |  | 134 |  | 
| 192 | 50 |  |  | 50 |  | 384 | with 'Attean::API::QuadStore'; | 
|  | 50 |  |  |  |  | 128 |  | 
|  | 50 |  |  |  |  | 6618 |  | 
| 193 | 29 | 50 |  |  |  | 93 |  | 
| 194 | 29 |  |  |  |  | 603 | requires 'mtime_for_quads'; | 
| 195 | 93 |  |  |  |  | 2085 | } | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | use Moo::Role; | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | requires 'begin_bulk_updates'; | 
| 200 |  |  |  |  |  |  | requires 'end_bulk_updates'; | 
| 201 | 50 |  |  | 50 |  | 345 | } | 
|  | 50 |  |  |  |  | 124 |  | 
|  | 50 |  |  |  |  | 226 |  | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | use Moo::Role; | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | with 'Attean::API::Store'; | 
| 206 |  |  |  |  |  |  | } | 
| 207 |  |  |  |  |  |  |  | 
| 208 |  |  |  |  |  |  | 1; | 
| 209 | 50 |  |  | 50 |  | 17195 |  | 
|  | 50 |  |  |  |  | 112 |  | 
|  | 50 |  |  |  |  | 230 |  | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | =head1 BUGS | 
| 212 |  |  |  |  |  |  |  | 
| 213 |  |  |  |  |  |  | Please report any bugs or feature requests to through the GitHub web interface | 
| 214 |  |  |  |  |  |  | at L<https://github.com/kasei/attean/issues>. | 
| 215 |  |  |  |  |  |  |  | 
| 216 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 217 | 50 |  |  | 50 |  | 16513 |  | 
|  | 50 |  |  |  |  | 112 |  | 
|  | 50 |  |  |  |  | 220 |  | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  | =head1 AUTHOR | 
| 221 |  |  |  |  |  |  |  | 
| 222 |  |  |  |  |  |  | Gregory Todd Williams  C<< <gwilliams@cpan.org> >> | 
| 223 |  |  |  |  |  |  |  | 
| 224 | 50 |  |  | 50 |  | 15626 | =head1 COPYRIGHT | 
|  | 50 |  |  |  |  | 99 |  | 
|  | 50 |  |  |  |  | 219 |  | 
| 225 |  |  |  |  |  |  |  | 
| 226 |  |  |  |  |  |  | Copyright (c) 2014--2022 Gregory Todd Williams. | 
| 227 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it under | 
| 228 |  |  |  |  |  |  | the same terms as Perl itself. | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  | =cut |