Attean
view release on metacpan or search on metacpan
lib/AtteanX/Parser/Trig.pm view on Meta::CPAN
}
=head1 DESCRIPTION
This module implements a parser for the Trig RDF format.
=head1 ROLES
This class consumes L<Attean::API::Parser>, L<Attean::API::PushParser>,
<Attean::API::AbbreviatingParser>, and <Attean::API::TripleParser>.
=head1 ATTRIBUTES
=over 4
=item C<< canonical_media_type >>
=item C<< media_types >>
=item C<< file_extensions >>
=item C<< canonicalize >>
A boolean indicating whether term values should be canonicalized during parsing.
=back
=head1 METHODS
=over 4
=cut
package AtteanX::Parser::Trig 0.038 {
use Moo;
use Types::Standard qw(Bool ArrayRef HashRef Str Maybe InstanceOf);
use Types::Namespace qw( NamespaceMap );
use utf8;
use Carp qw(carp);
use Encode qw(encode);
use Scalar::Util qw(blessed);
use Attean::API::Parser;
use AtteanX::Parser::Turtle;
use AtteanX::Parser::Turtle::Constants;
use namespace::clean;
my $RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
my $XSD = 'http://www.w3.org/2001/XMLSchema#';
extends 'AtteanX::Parser::Turtle';
sub canonical_media_type { return "text/trig" }
sub media_types {
return [qw(text/trig)];
}
sub file_extensions { return [qw(trig)] }
has 'canonicalize' => (is => 'rw', isa => Bool, default => 0);
has '_map' => (is => 'ro', isa => HashRef[Str], default => sub { +{} });
with 'Attean::API::MixedStatementParser';
################################################################################
# this is the entry point where we change the rules from Turtle to Trig
sub _parse {
my $self = shift;
my $l = shift;
$l->check_for_bom;
while (my $t = $self->_next_nonws($l)) {
$self->_trigDoc($l, $t);
}
}
sub _trigDoc {
my $self = shift;
my $l = shift;
my $t = shift;
my $type = $t->type;
if ($type == TURTLEPREFIX or $type == PREFIX) {
$t = $self->_get_token_type($l, PREFIXNAME);
use Data::Dumper;
unless (defined($t->value)) {
my $tname = AtteanX::Parser::Turtle::Constants::decrypt_constant($t->type);
Carp::confess "undefined $tname token value: " . Dumper($t);
}
my $name = $t->value;
chop($name) if (substr($name, -1) eq ':');
# $name =~ s/:$//;
$t = $self->_get_token_type($l, IRI);
my %args = (value => $t->value);
if ($self->has_base) {
$args{base} = $self->base;
}
my $r = $self->new_iri(%args);
my $iri = $r->as_string;
if ($type == TURTLEPREFIX) {
$t = $self->_get_token_type($l, DOT);
# $t = $self->_next_nonws($l);
# if ($t and $t->type != DOT) {
# $self->_unget_token($t);
# }
}
$self->_map->{$name} = $iri;
if ($self->has_namespaces) {
my $ns = $self->namespaces;
unless ($ns->namespace_uri($name)) {
$ns->add_mapping($name, $iri);
}
}
}
elsif ($type == TURTLEBASE or $type == BASE) {
$t = $self->_get_token_type($l, IRI);
my %args = (value => $t->value);
if ($self->has_base) {
$args{base} = $self->base;
}
my $r = $self->new_iri(%args);
my $iri = $r->as_string;
( run in 0.612 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )