AtteanX/Store/SimpleTripleStore.pm

filter: Statementstmt 98.5% 67 / 68 Branchbran 100% 8 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 15 / 15 Podpod 100% 3 / 3 totaltotal 98.9% 98 / 99 CC 8 SCAR 9.0
CC
8
Cov
99%
get_triples
5.0
remove_triple
4.0
BEGIN
1.0
CRAP 2.5
« AtteanX/Parser/SPARQLTSV.pm ↑ Summary Attean/IRI.pm »
1 =head1 NAME
2  
3 AtteanX::Store::SimpleTripleStore - SimpleTripleStore, unindexed, in-memory RDF store
4  
5 =head1 VERSION
6  
7 This document describes AtteanX::Store::SimpleTripleStore version 0.040
8  
9 =head1 SYNOPSIS
10  
11 use AtteanX::Store::SimpleTripleStore;
12  
13 =head1 DESCRIPTION
14  
15 AtteanX::Store::SimpleTripleStore provides an in-memory triple-store.
16  
17 =cut
18  
19 2 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 package AtteanX::Store::SimpleTripleStore 0.040 {
23 2 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶ use Type::Tiny::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶ use Types::Standard qw(Int ArrayRef HashRef ConsumerOf InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶ use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶ use Set::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶ use Digest::SHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶ use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶ use Scalar::Util qw(refaddr reftype blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶ use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 2 with 'Attean::API::MutableTripleStore';
34  
35 2 my @pos_names = Attean::API::Quad->variables;
36  
37 =head1 METHODS
38  
39 Beyond the methods documented below, this class inherits methods from the
40 L<Attean::API::QuadStore> class.
41  
42 =over 4
43  
44 =item C<< new ( triples => \@triples ) >>
45  
46 Returns a new memory-backed storage object.
47  
48 =cut
49  
50 10 ▶ has triples => (is => 'rw', isa => ArrayRef[ConsumerOf['Attean::API::Triple']], default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
51  
52 =item C<< get_triples ( $subject, $predicate, $object ) >>
53  
54 Returns a stream object of all statements matching the specified subject,
55 predicate and objects. Any of the arguments may be undef to match any value.
56  
57 =cut
58  
59 49 ▶ sub get_triples {
Subroutine get_triples: called CC=5 SCAR=16.1
Pod documented
60 49 my $self = shift;
61 49 my @nodes = @_;
62 49 my %bound;
63 49 foreach my $pos (0 .. 2) {
64 147 my $n = $nodes[ $pos ];
65 147 ▶ if (blessed($n) and $n->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($n) and $n->does("Attean::API::Variable")) 46 101 147
Condition100%3/3
builtin::blessed($n) and $n->does("Attean::API::Variable")
!ll&&!rl&&r
554646
MC/DC100%2/2
builtin::blessed($n) and $n->does("Attean::API::Variable")
builtin::blessed($n) $n->does("Attean::API::Variable")
Truth table100%3/3
A and B
A= builtin::blessed($n)B= $n->does("Attean::API::Variable")
ABresult
0X0
100
111
66 46 $n = undef;
67 46 $nodes[$pos] = undef;
68 }
69 147 ▶ if (blessed($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($n)) 46 101 147
70 46 $bound{ $pos_names[$pos] } = $n;
71 }
72 }
73
74 49 my $triples = $self->triples;
75 49 my $iter = Attean::ListIterator->new( values => $triples, item_type => 'Attean::API::Triple' );
76 return $iter->grep(sub {
77 my $q = shift;
78 foreach my $key (keys %bound) {
79 my $term = $q->$key();
80 my $eq = eval { $term->equals( $bound{$key} ) } || 0;
81 unless ($eq) {
82 return 0;
83 }
84 }
85 return 1;
86 49 });
87 0 return $iter;
88 }
89
90 =item C<< add_triple( $t ) >>
91  
92 =cut
93  
94 16 ▶ sub add_triple {
Subroutine add_triple: called CC=1 SCAR=0.0
Pod documented
95 16 my $self = shift;
96 16 my $t = shift;
97 16 push(@{ $self->triples }, $t);
98 }
99
100 =item C<< remove_triple( $t ) >>
101  
102 =cut
103  
104 1 ▶ sub remove_triple {
Subroutine remove_triple: called CC=4 SCAR=13.9
Pod documented
105 1 my $self = shift;
106 1 my $t = shift;
107 1 my @remove;
108 1 my $triples = $self->triples;
109 1 foreach my $i (0 .. $#{ $triples }) {
110 4 my $u = $triples->[$i];
111 4 ▶ if ($u->as_string eq $t->as_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u->as_string eq $t->as_string) 1 3 4
112 1 push(@remove, $i);
113 }
114 }
115 1 ▶ while (scalar(@remove)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @remove) 1 1 2
116 1 my $i = pop(@remove);
117 1 splice(@$triples, $i, 1, ());
118 }
119 }
120 }
121  
122 2 1;
123  
124 __END__
« AtteanX/Parser/SPARQLTSV.pm ↑ Summary Attean/IRI.pm »