| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 4 |  |  | 4 |  | 10536 | use v5.14; | 
|  | 4 |  |  |  |  | 15 |  | 
| 2 | 4 |  |  | 4 |  | 25 | use warnings; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 179 |  | 
| 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.032 | 
| 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 |  |  |  |  |  |  | use utf8; | 
| 39 | 4 |  |  | 4 |  | 22 | use Moo; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 31 |  | 
| 40 | 4 |  |  | 4 |  | 80 | use Attean; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 23 |  | 
| 41 | 4 |  |  | 4 |  | 1181 | use Encode; | 
|  | 4 |  |  |  |  | 11 |  | 
|  | 4 |  |  |  |  | 24 |  | 
| 42 | 4 |  |  | 4 |  | 21 | use Encode qw(decode); | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 294 |  | 
| 43 | 4 |  |  | 4 |  | 25 | use List::MoreUtils qw(zip); | 
|  | 4 |  |  |  |  | 10 |  | 
|  | 4 |  |  |  |  | 132 |  | 
| 44 | 4 |  |  | 4 |  | 24 | use namespace::clean; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 47 |  | 
| 45 | 4 |  |  | 4 |  | 3483 |  | 
|  | 4 |  |  |  |  | 13 |  | 
|  | 4 |  |  |  |  | 35 |  | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 1 |  |  | 1 | 1 | 620 | return [qw(text/tab-separated-values)]; | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 4 |  |  | 4 | 1 | 20 |  | 
| 51 |  |  |  |  |  |  | with 'Attean::API::ResultParser', 'Attean::API::PullParser', 'Attean::API::Parser'; | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 4 |  |  | 4 | 1 | 16 | =item C<< parse_iter_from_bytes( $data ) >> | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | Returns an iterator of L<Attean::API::Binding> objects that result from parsing | 
| 56 |  |  |  |  |  |  | the data read from the UTF-8 encoded byte string C<< $data >>. | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =cut | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | my $self	= shift; | 
| 61 |  |  |  |  |  |  | my $data	= shift; | 
| 62 |  |  |  |  |  |  | open(my $fh, '<:encoding(UTF-8)', \$data); | 
| 63 |  |  |  |  |  |  | return $self->parse_iter_from_io($fh); | 
| 64 |  |  |  |  |  |  | } | 
| 65 | 1 |  |  | 1 | 1 | 3 |  | 
| 66 | 1 |  |  |  |  | 2 | =item C<< parse_iter_from_io( $fh ) >> | 
| 67 | 1 |  |  | 1 |  | 5 |  | 
|  | 1 |  |  | 1 |  | 3 |  | 
|  | 1 |  |  |  |  | 8 |  | 
|  | 1 |  |  |  |  | 827 |  | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 5 |  | 
|  | 1 |  |  |  |  | 36 |  | 
| 68 | 1 |  |  |  |  | 963 | Returns an iterator of L<Attean::API::Binding> objects that result from parsing | 
| 69 |  |  |  |  |  |  | the data read from the L<IO::Handle> object C<< $fh >>. | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =cut | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | my $self	= shift; | 
| 74 |  |  |  |  |  |  | my $fh		= shift; | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | my $parser	= Attean->get_parser('Turtle')->new(lazy_iris => $self->lazy_iris); | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | my $line	= <$fh>; | 
| 79 | 2 |  |  | 2 | 1 | 5 | unless (defined($line)) { | 
| 80 | 2 |  |  |  |  | 4 | die "undefined header line in SPARQL/TSV parser"; | 
| 81 |  |  |  |  |  |  | } | 
| 82 | 2 |  |  |  |  | 12 |  | 
| 83 |  |  |  |  |  |  | chomp($line); | 
| 84 | 2 |  |  |  |  | 106 | my @vars; | 
| 85 | 2 | 50 |  |  |  | 18 | foreach my $v (split("\t", $line)) { | 
| 86 | 0 |  |  |  |  | 0 | unless (substr($v, 0, 1) eq '?') { | 
| 87 |  |  |  |  |  |  | Carp::confess "Bad variable syntax in SPARQL TSV data: '$v'"; | 
| 88 |  |  |  |  |  |  | } | 
| 89 | 2 |  |  |  |  | 6 | push(@vars, substr($v, 1)); | 
| 90 | 2 |  |  |  |  | 4 | } | 
| 91 | 2 |  |  |  |  | 11 |  | 
| 92 | 8 | 50 |  |  |  | 23 | my $gen		= sub { | 
| 93 | 0 |  |  |  |  | 0 | my $line	= <$fh>; | 
| 94 |  |  |  |  |  |  | return unless defined($line); | 
| 95 | 8 |  |  |  |  | 16 | chomp($line); | 
| 96 |  |  |  |  |  |  | my @strings	= split("\t", $line); | 
| 97 |  |  |  |  |  |  | my %binding; | 
| 98 |  |  |  |  |  |  | foreach my $i (0 .. $#vars) { | 
| 99 | 5 |  |  | 5 |  | 17 | my $string	= $strings[$i]; | 
| 100 | 5 | 100 |  |  |  | 18 | if (length($string)) { | 
| 101 | 3 |  |  |  |  | 6 | my $var	= $vars[$i]; | 
| 102 | 3 |  |  |  |  | 24 | my $bytes	= encode('UTF-8', $string, Encode::FB_CROAK); | 
| 103 | 3 |  |  |  |  | 5 | my $term	= $parser->parse_term_from_bytes($bytes); | 
| 104 | 3 |  |  |  |  | 9 | if ($term) { | 
| 105 | 10 |  |  |  |  | 22 | $binding{ $var }	= $term; | 
| 106 | 10 | 100 |  |  |  | 25 | } | 
| 107 | 9 |  |  |  |  | 16 | } | 
| 108 | 9 |  |  |  |  | 49 | } | 
| 109 | 9 |  |  |  |  | 335 | return Attean::Result->new( bindings => \%binding ); | 
| 110 | 9 | 50 |  |  |  | 23 | }; | 
| 111 | 9 |  |  |  |  | 29 | return Attean::CodeIterator->new( | 
| 112 |  |  |  |  |  |  | generator	=> $gen, | 
| 113 |  |  |  |  |  |  | item_type	=> $self->handled_type->role, | 
| 114 |  |  |  |  |  |  | variables	=> \@vars, | 
| 115 | 3 |  |  |  |  | 52 | ); | 
| 116 | 2 |  |  |  |  | 14 | } | 
| 117 | 2 |  |  |  |  | 12 |  | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | 1; | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =back | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | =head1 BUGS | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | Please report any bugs or feature requests to through the GitHub web interface | 
| 128 |  |  |  |  |  |  | at L<https://github.com/kasei/perlrdf/issues>. | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | =head1 AUTHOR | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | Gregory Todd Williams  C<< <gwilliams@cpan.org> >> | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | Copyright (c) 2014--2022 Gregory Todd Williams. This | 
| 137 |  |  |  |  |  |  | program is free software; you can redistribute it and/or modify it under | 
| 138 |  |  |  |  |  |  | the same terms as Perl itself. | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | =cut |