| 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.040 | ||||||||||
| 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 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 4 | package AtteanX::Parser::SPARQLXML 0.040 { | |||||||||
| 32 | 4 | ▶ | use XML::SAX::ParserFactory; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 4 | ▶ | use Attean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 4 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 4 | ▶ | use Encode qw(encode); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 4 | ▶ | use PerlIO::Layers qw(query_handle); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 4 | ▶ | use AtteanX::Parser::SPARQLXML::SAXHandler; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 38 | |||||||||||
| 39 | =item C<< canonical_media_type >> | ||||||||||
| 40 | |||||||||||
| 41 | Returns the canonical media type for SPARQL XML: application/sparql-results+xml. | ||||||||||
| 42 | |||||||||||
| 43 | =cut | ||||||||||
| 44 | |||||||||||
| 45 | 1 | ▶ | sub canonical_media_type { return "application/sparql-results+xml" } | ||||||||
|
Subroutine
canonical_media_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 46 | |||||||||||
| 47 | =item C<< media_types >> | ||||||||||
| 48 | |||||||||||
| 49 | Returns a list of media types that may be parsed with the SPARQL XML parser: | ||||||||||
| 50 | application/sparql-results+xml. | ||||||||||
| 51 | |||||||||||
| 52 | =cut | ||||||||||
| 53 | |||||||||||
| 54 | 4 | ▶ | sub media_types { | ||||||||
|
Subroutine
media_types: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 55 | 4 | return [qw(application/sparql-results+xml)]; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | =item C<< file_extensions >> | ||||||||||
| 59 | |||||||||||
| 60 | Returns a list of file extensions that may be parsed with the parser. | ||||||||||
| 61 | |||||||||||
| 62 | =cut | ||||||||||
| 63 | |||||||||||
| 64 | 3 | ▶ | sub file_extensions { return [qw(srx)] } | ||||||||
|
Subroutine
file_extensions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 65 | |||||||||||
| 66 | 4 | with 'Attean::API::ResultOrTermParser'; | |||||||||
| 67 | 4 | with 'Attean::API::PushParser'; | |||||||||
| 68 | |||||||||||
| 69 | =item C<< parse_cb_from_io( $fh ) >> | ||||||||||
| 70 | |||||||||||
| 71 | Calls the C<< $parser->handler >> function once for each | ||||||||||
| 72 | L<Attean::API::Binding> object that result from parsing | ||||||||||
| 73 | the data read from the L<IO::Handle> object C<< $fh >>. | ||||||||||
| 74 | |||||||||||
| 75 | =cut | ||||||||||
| 76 | |||||||||||
| 77 | 1 | ▶ | sub parse_cb_from_io { | ||||||||
|
Subroutine
parse_cb_from_io: called CC=2 SCAR=8.7
Pod
documented
| |||||||||||
| 78 | 1 | my $self = shift; | |||||||||
| 79 | 1 | my $fh = shift; | |||||||||
| 80 | 1 | my $handler = AtteanX::Parser::SPARQLXML::SAXHandler->new($self->handler); | |||||||||
| 81 | 1 | my $p = XML::SAX::ParserFactory->parser(Handler => $handler); | |||||||||
| 82 | 1 | ▶ | if (query_handle($fh, 'utf8')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | # the filehandle already has utf-8 decoding applied, but the XML | ||||||||||
| 84 | # parser is expecting utf-8 *encoded* bytes, so we need to | ||||||||||
| 85 | # re-encode the data before parsing. | ||||||||||
| 86 | 0 | my $string = do { local($/); <$fh> }; | |||||||||
| 87 | 0 | my $data = encode('UTF-8', $string, Encode::FB_CROAK); | |||||||||
| 88 | 0 | $p->parse_string($data); | |||||||||
| 89 | } else { | ||||||||||
| 90 | 1 | $p->parse_file( $fh ); | |||||||||
| 91 | } | ||||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | =item C<< parse_cb_from_bytes( $data ) >> | ||||||||||
| 95 | |||||||||||
| 96 | Calls the C<< $parser->handler >> function once for each | ||||||||||
| 97 | L<Attean::API::Binding> object that result from parsing | ||||||||||
| 98 | the data read from the UTF-8 encoded byte string C<< $data >>. | ||||||||||
| 99 | |||||||||||
| 100 | =cut | ||||||||||
| 101 | |||||||||||
| 102 | 2 | ▶ | sub parse_cb_from_bytes { | ||||||||
|
Subroutine
parse_cb_from_bytes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 103 | 2 | my $self = shift; | |||||||||
| 104 | 2 | my $data = shift; | |||||||||
| 105 | |||||||||||
| 106 | 2 | my $handler = AtteanX::Parser::SPARQLXML::SAXHandler->new($self->handler); | |||||||||
| 107 | 2 | my $p = XML::SAX::ParserFactory->parser(Handler => $handler); | |||||||||
| 108 | 2 | $p->parse_string( $data ); | |||||||||
| 109 | } | ||||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | |||||||||||
| 113 | 4 | 1; | |||||||||
| 114 | |||||||||||
| 115 | __END__ | ||||||||||