AtteanX/Parser/NTriples.pm

filter: Statementstmt 96.6% 29 / 30 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 95.4% 42 / 44 CC 2 SCAR 1.9
CC
2
Cov
94%
_binding
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« AtteanX/Serializer/CanonicalNTriples.pm ↑ Summary AtteanX/Parser/SPARQLXML.pm »
1 =head1 NAME
2  
3 AtteanX::Parser::NTriples - N-Triples Parser
4  
5 =head1 VERSION
6  
7 This document describes AtteanX::Parser::NTriples version 0.040
8  
9 =head1 SYNOPSIS
10  
11 use Attean;
12 my $parser = Attean->get_parser('NTriples')->new();
13  
14 # Parse data from a file-handle and handle triples in the 'handler' callback
15 $parser->parse_cb_from_io( $fh );
16
17 # Parse the given byte-string, and return an iterator of triples
18 my $iter = $parser->parse_iter_from_bytes('<http://example.org/subject> <tag:example.org:predicate> "object" .');
19 while (my $triple = $iter->next) {
20 print $triple->as_string;
21 }
22  
23 =head1 DESCRIPTION
24  
25 This module implements a parser for the N-Triples format.
26  
27 =head1 ROLES
28  
29 This class consumes L<Attean::API::Parser>, L<Attean::API::PullParser>
30 and <Attean::API::TripleParser>.
31  
32 =head1 METHODS
33  
34 =over 4
35  
36 =item C<< parse_iter_from_io( $fh ) >>
37  
38 Returns an L<Attean::API::Iterator> that result from parsing the data read from
39 the L<IO::Handle> object C<< $fh >>.
40  
41 =item C<< parse_iter_from_bytes( $data ) >>
42  
43 Returns an L<Attean::API::Iterator> that result from parsing the data read from
44 the UTF-8 encoded byte string C<< $data >>.
45  
46 =cut
47  
48 5 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 5 package AtteanX::Parser::NTriples 0.040 {
52 5 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
53
54 5 ▶ use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 5 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 5 extends 'AtteanX::Parser::NTuples';
57
58 =item C<< canonical_media_type >>
59  
60 Returns the canonical media type for N-Triples: application/n-triples.
61  
62 =cut
63  
64 1 ▶ sub canonical_media_type { return "application/n-triples" }
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-triples.
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-triples)];
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 12 ▶ sub file_extensions { return [qw(nt)] }
Subroutine file_extensions: called CC=1 SCAR=0.0
Pod documented
84  
85 5 with 'Attean::API::TripleParser';
86 5 with 'Attean::API::PullParser';
87 5 with 'Attean::API::Parser';
88 5 with 'Attean::API::CDTBlankNodeMappingParser';
89  
90 19 ▶ sub _binding {
Subroutine _binding: called CC=2 SCAR=7.2
91 19 my $self = shift;
92 19 my $nodes = shift;
93 19 my $lineno = shift;
94 19 ▶ if (scalar(@$nodes) == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$nodes == 3) { } 19 0 19
95 19 return Attean::Triple->new(@$nodes)->validate;
96 } else {
97 0 die qq[Not valid N-Triples data at line $lineno];
98 }
99 }
100 }
101  
102  
103 5 1;
104  
105 __END__
« AtteanX/Serializer/CanonicalNTriples.pm ↑ Summary AtteanX/Parser/SPARQLXML.pm »