Attean
view release on metacpan or search on metacpan
lib/AtteanX/Parser/NTuples.pm view on Meta::CPAN
use v5.14;
use warnings;
=head1 NAME
AtteanX::Parser::NTuples - Shared functionality for N-Triples and N-Quads parsers
=head1 VERSION
This document describes AtteanX::Parser::NTuples version 0.038
=head1 SYNOPSIS
use Attean;
=head1 DESCRIPTION
This module provides a base class for RDF formats N-Triples and N-Quads.
=head1 ATTRIBUTES
=over 4
=item C<< blank_nodes >>
=item C<< has_blank_nodes_map >>
=back
=head1 METHODS
=over 4
=cut
package AtteanX::Parser::NTuples 0.038 {
use utf8;
use Moo;
use Attean;
use Carp qw(carp);
use Encode qw(decode);
use Types::Standard qw(Bool HashRef ArrayRef HashRef Str Maybe InstanceOf ConsumerOf);
use namespace::clean;
has 'blank_nodes' => (is => 'ro', isa => HashRef[ConsumerOf['Attean::API::Blank']], predicate => 'has_blank_nodes_map', default => sub { +{} });
=item C<< parse_term_from_bytes( $bytes ) >>
Parses the given C<< $bytes >> and returns a corresponding L<Attean::API::Term> object.
=cut
sub parse_term_from_bytes {
my $self = shift;
unless (ref($self)) {
$self = $self->new();
}
my $string = shift;
my $n = $self->_eat_node( 0, $string );
return $n;
}
=item C<< parse_iter_from_bytes( $data ) >>
Returns an iterator of L<Attean::API::Binding> objects that result from parsing
the data read from the UTF-8 encoded byte string C<< $data >>.
=cut
sub parse_iter_from_bytes {
my $self = shift;
my $data = shift;
$data = Encode::encode("utf-8", $data);
open(my $fh, '<:encoding(UTF-8)', \$data);
return $self->parse_iter_from_io($fh);
}
=item C<< parse_iter_from_io( $fh ) >>
Returns an iterator of L<Attean::API::Binding> objects that result from parsing
the data read from the L<IO::Handle> object C<< $fh >>.
=cut
sub parse_iter_from_io {
my $self = shift;
my $fh = shift;
my $lineno = 0;
my $line;
my $gen = sub {
while (defined($line = <$fh>)) {
($line, my @extra) = split(/\r\n|\r|\n/, $line, 2);
$lineno++;
next unless (defined($line) and length($line));
next unless ($line =~ /\S/);
chomp($line);
$line =~ s/^\s*//;
$line =~ s/\s*$//;
next if ($line =~ /^#/);
my @nodes = ();
while (my $n = $self->_eat_node( $lineno, $line )) {
( run in 0.506 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )