| 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.040 | ||||||||||
| 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 | =cut | ||||||||||
| 34 | |||||||||||
| 35 | 3 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | |||||||||||
| 38 | 2 | package AtteanX::Serializer::SPARQLTSV 0.040 { | |||||||||
| 39 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 3 | ▶ | use Types::Standard qw(Str ArrayRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 3 | ▶ | use Encode qw(encode); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | 3 | ▶ | use Scalar::Util qw(blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 3 | ▶ | use Attean::ListIterator; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 3 | ▶ | use List::Util qw(any); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 3 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | |||||||||||
| 47 | 2 | has 'canonical_media_type' => (is => 'ro', isa => Str, init_arg => undef, default => 'text/tab-separated-values'); | |||||||||
| 48 | |||||||||||
| 49 | =item C<< media_types >> | ||||||||||
| 50 | |||||||||||
| 51 | Returns a list of media types that identify the format produced by this serializer. | ||||||||||
| 52 | |||||||||||
| 53 | =cut | ||||||||||
| 54 | |||||||||||
| 55 | 12 | ▶ | sub media_types { | ||||||||
|
Subroutine
media_types: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 56 | 12 | return [qw(text/tab-separated-values)]; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | =item C<< file_extensions >> | ||||||||||
| 60 | |||||||||||
| 61 | Returns a list of file extensions associated with the serialized format. | ||||||||||
| 62 | |||||||||||
| 63 | =cut | ||||||||||
| 64 | |||||||||||
| 65 | 5 | ▶ | sub file_extensions { return [qw(tsv)] }; | ||||||||
|
Subroutine
file_extensions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 66 | |||||||||||
| 67 | =item C<< serialize_iter_to_io( $fh, $iterator ) >> | ||||||||||
| 68 | |||||||||||
| 69 | Serializes the L<Attean::API::Binding> objects from C<< $iterator >> to the | ||||||||||
| 70 | L<IO::Handle> object C<< $fh >>. | ||||||||||
| 71 | |||||||||||
| 72 | =cut | ||||||||||
| 73 | |||||||||||
| 74 | 2 | ▶ | sub serialize_iter_to_io { | ||||||||
|
Subroutine
serialize_iter_to_io: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 75 | 2 | my $self = shift; | |||||||||
| 76 | 2 | my $io = shift; | |||||||||
| 77 | 2 | my $iter = shift; | |||||||||
| 78 | |||||||||||
| 79 | 2 | my @vars = @{ $iter->variables }; | |||||||||
| 80 | 2 | $io->print(join("\t", map { "?$_" } @vars) . "\n"); | |||||||||
| 81 | |||||||||||
| 82 | 2 | ▶ | while (my $t = $iter->next()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 6 | ▶ | my @strings = map { blessed($_) ? $_->ntriples_string : '' } map { $t->value($_) } @vars; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 6 | $io->print(join("\t", @strings) . "\n"); | |||||||||
| 85 | } | ||||||||||
| 86 | 2 | return; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | =item C<< serialize_iter_to_bytes( $iterator ) >> | ||||||||||
| 90 | |||||||||||
| 91 | Serializes the L<Attean::API::Binding> objects from C<< $iterator >> | ||||||||||
| 92 | and returns the serialization as a UTF-8 encoded byte string. | ||||||||||
| 93 | |||||||||||
| 94 | =cut | ||||||||||
| 95 | |||||||||||
| 96 | 1 | ▶ | sub serialize_iter_to_bytes { | ||||||||
|
Subroutine
serialize_iter_to_bytes: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 97 | 1 | my $self = shift; | |||||||||
| 98 | 1 | my $iter = shift; | |||||||||
| 99 | 1 | my $data = ''; | |||||||||
| 100 | |||||||||||
| 101 | 1 | my @vars = @{ $iter->variables }; | |||||||||
| 102 | 1 | $data .= join("\t", map { "?$_" } @vars) . "\n"; | |||||||||
| 103 | |||||||||||
| 104 | 1 | ▶ | while (my $t = $iter->next()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 3 | ▶ | my @strings = map { blessed($_) ? $_->ntriples_string : '' } map { $t->value($_) } @vars; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 3 | my $str = join("\t", @strings); | |||||||||
| 107 | 3 | $data .= $str . "\n"; | |||||||||
| 108 | } | ||||||||||
| 109 | 1 | return encode('UTF-8', $data); | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 2 | with 'Attean::API::ResultSerializer', 'Attean::API::AppendableSerializer'; | |||||||||
| 113 | } | ||||||||||
| 114 | |||||||||||
| 115 | 2 | 1; | |||||||||
| 116 | |||||||||||
| 117 | __END__ | ||||||||||