| 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::NQuads - N-Quads Parser | ||||||||||||||
| 7 | |||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||
| 9 | |||||||||||||||
| 10 | This document describes AtteanX::Parser::NQuads version 0.040 | ||||||||||||||
| 11 | |||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||
| 13 | |||||||||||||||
| 14 | use Attean; | ||||||||||||||
| 15 | my $parser = Attean->get_parser('NQuads')->new(); | ||||||||||||||
| 16 | |||||||||||||||
| 17 | # Parse data from a file-handle and handle quads in the 'handler' callback | ||||||||||||||
| 18 | $parser->parse_cb_from_io( $fh ); | ||||||||||||||
| 19 | |||||||||||||||
| 20 | # Parse the given byte-string, and return an iterator of quads | ||||||||||||||
| 21 | my $iter = $parser->parse_iter_from_bytes('<http://example.org/subject> <tag:example.org:predicate> "object" <http://example.org/graph> .'); | ||||||||||||||
| 22 | while (my $quad = $iter->next) { | ||||||||||||||
| 23 | print $quad->as_string; | ||||||||||||||
| 24 | } | ||||||||||||||
| 25 | |||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||
| 27 | |||||||||||||||
| 28 | This module implements a parser for the N-Quads format. | ||||||||||||||
| 29 | |||||||||||||||
| 30 | =head1 ROLES | ||||||||||||||
| 31 | |||||||||||||||
| 32 | This class consumes L<Attean::API::Parser>, L<Attean::API::PullParser> | ||||||||||||||
| 33 | and <Attean::API::MixedStatementParser>. | ||||||||||||||
| 34 | |||||||||||||||
| 35 | =head1 METHODS | ||||||||||||||
| 36 | |||||||||||||||
| 37 | =over 4 | ||||||||||||||
| 38 | |||||||||||||||
| 39 | =item C<< parse_iter_from_io( $fh ) >> | ||||||||||||||
| 40 | |||||||||||||||
| 41 | Returns an L<Attean::API::Iterator> that result from parsing the data read from | ||||||||||||||
| 42 | the L<IO::Handle> object C<< $fh >>. | ||||||||||||||
| 43 | |||||||||||||||
| 44 | =item C<< parse_iter_from_bytes( $data ) >> | ||||||||||||||
| 45 | |||||||||||||||
| 46 | Returns an L<Attean::API::Iterator> that result from parsing the data read from | ||||||||||||||
| 47 | the UTF-8 encoded byte string C<< $data >>. | ||||||||||||||
| 48 | |||||||||||||||
| 49 | =cut | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 4 | package AtteanX::Parser::NQuads 0.040 { | |||||||||||||
| 52 | 4 | ▶ | use utf8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 53 | |||||||||||||||
| 54 | 4 | ▶ | use Attean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 55 | 4 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 56 | 4 | extends 'AtteanX::Parser::NTuples'; | |||||||||||||
| 57 | |||||||||||||||
| 58 | =item C<< canonical_media_type >> | ||||||||||||||
| 59 | |||||||||||||||
| 60 | Returns the canonical media type for N-Quads: application/n-quads. | ||||||||||||||
| 61 | |||||||||||||||
| 62 | =cut | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 1 | ▶ | sub canonical_media_type { return "application/n-quads" } | ||||||||||||
|
Subroutine
canonical_media_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 65 | |||||||||||||||
| 66 | =item C<< media_types >> | ||||||||||||||
| 67 | |||||||||||||||
| 68 | Returns a list of media types that may be parsed with the N-Triples parser: | ||||||||||||||
| 69 | application/n-quads. | ||||||||||||||
| 70 | |||||||||||||||
| 71 | =cut | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 5 | ▶ | sub media_types { | ||||||||||||
|
Subroutine
media_types: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 74 | 5 | return [qw(application/n-quads)]; | |||||||||||||
| 75 | } | ||||||||||||||
| 76 | |||||||||||||||
| 77 | =item C<< file_extensions >> | ||||||||||||||
| 78 | |||||||||||||||
| 79 | Returns a list of file extensions that may be parsed with the parser. | ||||||||||||||
| 80 | |||||||||||||||
| 81 | =cut | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 13 | ▶ | sub file_extensions { return [qw(nq)] } | ||||||||||||
|
Subroutine
file_extensions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 84 | |||||||||||||||
| 85 | 4 | with 'Attean::API::MixedStatementParser'; | |||||||||||||
| 86 | 4 | with 'Attean::API::PullParser'; | |||||||||||||
| 87 | 4 | with 'Attean::API::CDTBlankNodeMappingParser'; | |||||||||||||
| 88 | |||||||||||||||
| 89 | 17 | ▶ | sub _binding { | ||||||||||||
|
Subroutine
_binding: called CC=3 SCAR=11.2
| |||||||||||||||
| 90 | 17 | my $self = shift; | |||||||||||||
| 91 | 17 | my $nodes = shift; | |||||||||||||
| 92 | 17 | my $lineno = shift; | |||||||||||||
| 93 | 17 | ▶ | if (scalar(@$nodes) == 3) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 94 | 3 | return Attean::Triple->new(@$nodes)->validate; | |||||||||||||
| 95 | } elsif (scalar(@$nodes) == 4) { | ||||||||||||||
| 96 | 14 | return Attean::Quad->new(@$nodes)->validate; | |||||||||||||
| 97 | } else { | ||||||||||||||
| 98 | 0 | die qq[Not valid N-Quads data at line $lineno]; | |||||||||||||
| 99 | } | ||||||||||||||
| 100 | } | ||||||||||||||
| 101 | } | ||||||||||||||
| 102 | |||||||||||||||
| 103 | 4 | 1; | |||||||||||||
| 104 | |||||||||||||||
| 105 | __END__ | ||||||||||||||