| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # AtteanX::Parser::SPARQLXML | 
| 2 |  |  |  |  |  |  | # ----------------------------------------------------------------------------- | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | =head1 NAME | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | AtteanX::Parser::SPARQLXML - SPARQL XML Parser | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | =head1 VERSION | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | This document describes AtteanX::Parser::SPARQLXML version 0.033 | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | use Attean; | 
| 15 |  |  |  |  |  |  | my $parser = Attean->get_parser('SPARQLXML')->new(); | 
| 16 |  |  |  |  |  |  | $parser->parse_cb_from_io( $fh ); | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | ... | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =head1 METHODS | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =over 4 | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =cut | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 4 |  |  | 4 |  | 10633 | use v5.14; | 
|  | 4 |  |  |  |  | 15 |  | 
| 29 | 4 |  |  | 4 |  | 24 | use warnings; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 197 |  | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | use XML::SAX::ParserFactory; | 
| 32 | 4 |  |  | 4 |  | 479 | use Attean; | 
|  | 4 |  |  |  |  | 3801 |  | 
|  | 4 |  |  |  |  | 111 |  | 
| 33 | 4 |  |  | 4 |  | 20 | use Moo; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 28 |  | 
| 34 | 4 |  |  | 4 |  | 26 | use Encode qw(encode); | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 30 |  | 
| 35 | 4 |  |  | 4 |  | 1362 | use PerlIO::Layers qw(query_handle); | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 183 |  | 
| 36 | 4 |  |  | 4 |  | 1780 | use AtteanX::Parser::SPARQLXML::SAXHandler; | 
|  | 4 |  |  |  |  | 6888 |  | 
|  | 4 |  |  |  |  | 229 |  | 
| 37 | 4 |  |  | 4 |  | 2007 |  | 
|  | 4 |  |  |  |  | 13 |  | 
|  | 4 |  |  |  |  | 925 |  | 
| 38 |  |  |  |  |  |  | =item C<< canonical_media_type >> | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | Returns the canonical media type for SPARQL XML: application/sparql-results+xml. | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =cut | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 1 |  |  | 1 | 1 | 767 | =item C<< media_types >> | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | Returns a list of media types that may be parsed with the SPARQL XML parser: | 
| 48 |  |  |  |  |  |  | application/sparql-results+xml. | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =cut | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | return [qw(application/sparql-results+xml)]; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 4 |  |  | 4 | 1 | 14 | =item C<< file_extensions >> | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | Returns a list of file extensions that may be parsed with the parser. | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =cut | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | with 'Attean::API::ResultOrTermParser'; | 
| 63 |  |  |  |  |  |  | with 'Attean::API::PushParser'; | 
| 64 | 3 |  |  | 3 | 1 | 11 |  | 
| 65 |  |  |  |  |  |  | =item C<< parse_cb_from_io( $fh ) >> | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | Calls the C<< $parser->handler >> function once for each | 
| 68 |  |  |  |  |  |  | L<Attean::API::Binding> object 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 |  |  |  |  |  |  | my $handler	= AtteanX::Parser::SPARQLXML::SAXHandler->new($self->handler); | 
| 76 |  |  |  |  |  |  | my $p		= XML::SAX::ParserFactory->parser(Handler => $handler); | 
| 77 |  |  |  |  |  |  | if (query_handle($fh, 'utf8')) { | 
| 78 | 1 |  |  | 1 | 1 | 2 | # the filehandle already has utf-8 decoding applied, but the XML | 
| 79 | 1 |  |  |  |  | 3 | # parser is expecting utf-8 *encoded* bytes, so we need to | 
| 80 | 1 |  |  |  |  | 16 | # re-encode the data before parsing. | 
| 81 | 1 |  |  |  |  | 9 | my $string	= do { local($/); <$fh> }; | 
| 82 | 1 | 50 |  |  |  | 397 | my $data	= encode('UTF-8', $string, Encode::FB_CROAK); | 
| 83 |  |  |  |  |  |  | $p->parse_string($data); | 
| 84 |  |  |  |  |  |  | } else { | 
| 85 |  |  |  |  |  |  | $p->parse_file( $fh ); | 
| 86 | 0 |  |  |  |  | 0 | } | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 87 | 0 |  |  |  |  | 0 | } | 
| 88 | 0 |  |  |  |  | 0 |  | 
| 89 |  |  |  |  |  |  | =item C<< parse_cb_from_bytes( $data ) >> | 
| 90 | 1 |  |  |  |  | 39 |  | 
| 91 |  |  |  |  |  |  | Calls the C<< $parser->handler >> function once for each | 
| 92 |  |  |  |  |  |  | L<Attean::API::Binding> object that result from parsing | 
| 93 |  |  |  |  |  |  | the data read from the UTF-8 encoded byte string C<< $data >>. | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =cut | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | my $self	= shift; | 
| 98 |  |  |  |  |  |  | my $data	= shift; | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | my $handler	= AtteanX::Parser::SPARQLXML::SAXHandler->new($self->handler); | 
| 101 |  |  |  |  |  |  | my $p		= XML::SAX::ParserFactory->parser(Handler => $handler); | 
| 102 |  |  |  |  |  |  | $p->parse_string( $data ); | 
| 103 | 2 |  |  | 2 | 1 | 77 | } | 
| 104 | 2 |  |  |  |  | 4 | } | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 2 |  |  |  |  | 37 |  | 
| 107 | 2 |  |  |  |  | 19 | 1; | 
| 108 | 2 |  |  |  |  | 65711 |  | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =back | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | =head1 BUGS | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | Please report any bugs or feature requests to through the GitHub web interface | 
| 115 |  |  |  |  |  |  | at L<https://github.com/kasei/perlrdf/issues>. | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =head1 AUTHOR | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | Gregory Todd Williams  C<< <gwilliams@cpan.org> >> | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | Copyright (c) 2014--2022 Gregory Todd Williams. This | 
| 124 |  |  |  |  |  |  | program is free software; you can redistribute it and/or modify it under | 
| 125 |  |  |  |  |  |  | the same terms as Perl itself. | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =cut |