AtteanX/Serializer/SPARQLTSV.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.8% 13 / 14 Podpod 100% 5 / 5 totaltotal 97.7% 85 / 87 CC 5 SCAR 5.4
CC
5
Cov
99%
serialize_iter_to_io
3.0
serialize_iter_to_bytes
3.0
canonical_iri
2.0
CRAP 1.7
« Test/Attean/MutableTripleStore.pm ↑ Summary Attean/IteratorSequence.pm »
1 =head1 NAME
2  
3 AtteanX::Serializer::SPARQLTSV - SPARQL Results TSV Serializer
4  
5 =head1 VERSION
6  
7 This document describes AtteanX::Serializer::SPARQLTSV version 0.041
8  
9 =head1 SYNOPSIS
10  
11 use Attean;
12 my $s = Attean->get_serializer('SPARQLTSV')->new();
13 $s->serialize_iter_to_io( $fh, $iter );
14  
15 =head1 DESCRIPTION
16  
17 ...
18  
19 =head1 ATTRIBUTES
20  
21 =over 4
22  
23 =item C<< canonical_media_type >>
24  
25 =item C<< file_extensions >>
26  
27 =back
28  
29 =head1 METHODS
30  
31 =over 4
32  
33 =item C<< canonical_iri >>
34  
35 Returns the canonical IRI of this format.
36  
37 =cut
38  
39 3 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 2 package AtteanX::Serializer::SPARQLTSV 0.041 {
43 3 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 3 ▶ use Types::Standard qw(Str ArrayRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 3 ▶ use Encode qw(encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
46 3 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
47 3 ▶ use Attean::ListIterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 3 ▶ use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
49 3 ▶ use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 0 ▶ sub canonical_iri { return 'http://www.w3.org/ns/formats/SPARQL_Results_TSV' }
Subroutine canonical_iri: not called CC=1 SCAR=6.9
Pod documented
52 2 has 'canonical_media_type' => (is => 'ro', isa => Str, init_arg => undef, default => 'text/tab-separated-values');
53  
54 =item C<< media_types >>
55  
56 Returns a list of media types that identify the format produced by this serializer.
57  
58 =cut
59  
60 12 ▶ sub media_types {
Subroutine media_types: called CC=1 SCAR=0.0
Pod documented
61 12 return [qw(text/tab-separated-values)];
62 }
63  
64 =item C<< file_extensions >>
65  
66 Returns a list of file extensions associated with the serialized format.
67  
68 =cut
69  
70 5 ▶ sub file_extensions { return [qw(tsv)] };
Subroutine file_extensions: called CC=1 SCAR=0.0
Pod documented
71
72 =item C<< serialize_iter_to_io( $fh, $iterator ) >>
73  
74 Serializes the L<Attean::API::Binding> objects from C<< $iterator >> to the
75 L<IO::Handle> object C<< $fh >>.
76  
77 =cut
78  
79 2 ▶ sub serialize_iter_to_io {
Subroutine serialize_iter_to_io: called CC=3 SCAR=11.0
Pod documented
80 2 my $self = shift;
81 2 my $io = shift;
82 2 my $iter = shift;
83
84 2 my @vars = @{ $iter->variables };
85 2 $io->print(join("\t", map { "?$_" } @vars) . "\n");
86
87 2 ▶ while (my $t = $iter->next()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = $iter->next) 6 2 8
88 6 ▶ my @strings = map { blessed($_) ? $_->ntriples_string : '' } map { $t->value($_) } @vars;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) ? : 14 4 18
89 6 $io->print(join("\t", @strings) . "\n");
90 }
91 2 return;
92 }
93
94 =item C<< serialize_iter_to_bytes( $iterator ) >>
95  
96 Serializes the L<Attean::API::Binding> objects from C<< $iterator >>
97 and returns the serialization as a UTF-8 encoded byte string.
98  
99 =cut
100  
101 1 ▶ sub serialize_iter_to_bytes {
Subroutine serialize_iter_to_bytes: called CC=3 SCAR=11.0
Pod documented
102 1 my $self = shift;
103 1 my $iter = shift;
104 1 my $data = '';
105  
106 1 my @vars = @{ $iter->variables };
107 1 $data .= join("\t", map { "?$_" } @vars) . "\n";
108
109 1 ▶ while (my $t = $iter->next()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = $iter->next) 3 1 4
110 3 ▶ my @strings = map { blessed($_) ? $_->ntriples_string : '' } map { $t->value($_) } @vars;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) ? : 7 2 9
111 3 my $str = join("\t", @strings);
112 3 $data .= $str . "\n";
113 }
114 1 return encode('UTF-8', $data);
115 }
116  
117 2 with 'Attean::API::ResultSerializer', 'Attean::API::AppendableSerializer';
118 }
119  
120 2 1;
121  
122 __END__
« Test/Attean/MutableTripleStore.pm ↑ Summary Attean/IteratorSequence.pm »