AtteanX/Parser/SPARQLTSV.pm

filter: Statementstmt 96.7% 59 / 61 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 100% 5 / 5 totaltotal 94.4% 85 / 90 CC 8 SCAR 9.3
CC
8
Cov
93%
__ANON__
5.0
parse_iter_from_io
4.0
BEGIN
1.0
CRAP 2.5
« AtteanX/API/Lexer.pm ↑ Summary AtteanX/Store/SimpleTripleStore.pm »
1 4 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 AtteanX::Parser::SPARQLTSV - SPARQL Results TSV Parser
7  
8 =head1 VERSION
9  
10 This document describes AtteanX::Parser::SPARQLTSV version 0.040
11  
12 =head1 SYNOPSIS
13  
14 use Attean;
15  
16 =head1 DESCRIPTION
17  
18 ...
19  
20 =head1 ATTRIBUTES
21  
22 =over 4
23  
24 =item C<< canonical_media_type >>
25  
26 =item C<< media_types >>
27  
28 =item C<< file_extensions >>
29  
30 =back
31  
32 =head1 METHODS
33  
34 =over 4
35  
36 =cut
37  
38 4 package AtteanX::Parser::SPARQLTSV 0.040 {
39 4 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 4 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 4 ▶ use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 4 ▶ use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 4 ▶ use Encode qw(decode);
Subroutine BEGIN: called CC=1 SCAR=0.0
44 4 ▶ use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 1 ▶ sub canonical_media_type { return "text/tab-separated-values" }
Subroutine canonical_media_type: called CC=1 SCAR=0.0
Pod documented
47  
48 4 ▶ sub media_types {
Subroutine media_types: called CC=1 SCAR=0.0
Pod documented
49 4 return [qw(text/tab-separated-values)];
50 }
51
52 4 ▶ sub file_extensions { return [qw(tsv)] }
Subroutine file_extensions: called CC=1 SCAR=0.0
Pod documented
53  
54 4 with 'Attean::API::ResultParser', 'Attean::API::PullParser', 'Attean::API::Parser';
55  
56 =item C<< parse_iter_from_bytes( $data ) >>
57  
58 Returns an iterator of L<Attean::API::Binding> objects that result from parsing
59 the data read from the UTF-8 encoded byte string C<< $data >>.
60  
61 =cut
62  
63 1 ▶ sub parse_iter_from_bytes {
Subroutine parse_iter_from_bytes: called CC=1 SCAR=0.0
Pod documented
64 1 my $self = shift;
65 1 my $data = shift;
66 1 open(my $fh, '<:encoding(UTF-8)', \$data);
67 1 return $self->parse_iter_from_io($fh);
68 }
69  
70 =item C<< parse_iter_from_io( $fh ) >>
71  
72 Returns an iterator of L<Attean::API::Binding> objects that result from parsing
73 the data read from the L<IO::Handle> object C<< $fh >>.
74  
75 =cut
76  
77 2 ▶ sub parse_iter_from_io {
Subroutine parse_iter_from_io: called CC=4 SCAR=14.0
Pod documented
78 2 my $self = shift;
79 2 my $fh = shift;
80
81 2 my $parser = Attean->get_parser('Turtle')->new(lazy_iris => $self->lazy_iris);
82  
83 2 my $line = <$fh>;
84 2 ▶ unless (defined($line)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 0 2 2
85 0 die "undefined header line in SPARQL/TSV parser";
86 }
87
88 2 chomp($line);
89 2 my @vars;
90 2 foreach my $v (split("\t", $line)) {
91 8 ▶ unless (substr($v, 0, 1) eq '?') {
Branch: 1 branch
BranchTrueFalseTotal
unless (substr($v, 0, 1) eq "?") 0 8 8
92 0 Carp::confess "Bad variable syntax in SPARQL TSV data: '$v'";
93 }
94 8 push(@vars, substr($v, 1));
95 }
96
97 5 ▶ my $gen = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
98 5 my $line = <$fh>;
99 5 ▶ return unless defined($line);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 2 3 5
100 3 chomp($line);
101 3 my @strings = split("\t", $line);
102 3 my %binding;
103 3 foreach my $i (0 .. $#vars) {
104 10 my $string = $strings[$i];
105 10 ▶ if (length($string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $string) 9 1 10
106 9 my $var = $vars[$i];
107 9 my $bytes = encode('UTF-8', $string, Encode::FB_CROAK);
108 9 my $term = $parser->parse_term_from_bytes($bytes);
109 9 ▶ if ($term) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term) 9 0 9
110 9 $binding{ $var } = $term;
111 }
112 }
113 }
114 3 return Attean::Result->new( bindings => \%binding );
115 2 };
116 2 return Attean::CodeIterator->new(
117 generator => $gen,
118 item_type => $self->handled_type->role,
119 variables => \@vars,
120 );
121 }
122  
123 }
124  
125 4 1;
126  
127 __END__
« AtteanX/API/Lexer.pm ↑ Summary AtteanX/Store/SimpleTripleStore.pm »