Attean

 view release on metacpan or  search on metacpan

lib/AtteanX/Parser/SPARQL.pm  view on Meta::CPAN

object whose type is one of: L<Attean::Algebra::Query>,
L<Attean::Algebra::Update>, or L<Attean::Algebra::Sequence>.

=head1 ROLES

This class consumes L<Attean::API::Parser>, L<Attean::API::AtOnceParser>, and
L<Attean::API::AbbreviatingParser>.

=head1 ATTRIBUTES

=over 4

=item C<< canonical_media_type >>

=item C<< media_types >>

=item C<< file_extensions >>

=item C<< handled_type >>

=item C<< lexer >>

=item C<< args >>

=item C<< build >>

=item C<< update >>

=item C<< namespaces >>

=item C<< baseURI >>

=item C<< filters >>

=item C<< blank_nodes >>

=item C<< has_blank_nodes_map >>

=back

=head1 METHODS

=over 4

=cut

package AtteanX::Parser::SPARQL 0.035;

use strict;
use warnings;
no warnings 'redefine';
use Carp qw(cluck confess croak);

use Attean;
use Data::Dumper;
use URI::NamespaceMap;
use List::Util qw(mesh);
use AtteanX::Parser::SPARQLLex;
use AtteanX::SPARQL::Constants;
use Types::Standard qw(ConsumerOf InstanceOf HashRef ArrayRef Bool Str Int);
use Scalar::Util qw(blessed looks_like_number reftype refaddr);

######################################################################

use Moo;

has 'lexer' 		=> (is => 'rw', isa => InstanceOf['AtteanX::Parser::SPARQLLex::Iterator']);
has 'args'			=> (is => 'ro', isa => HashRef);
has 'build'			=> (is => 'rw', isa => HashRef);
has 'update'		=> (is => 'rw', isa => Bool);
has 'baseURI'		=> (is => 'rw');
has '_stack'		=> (is => 'rw', isa => ArrayRef);
has 'filters'		=> (is => 'rw', isa => ArrayRef);
has 'counter'		=> (is => 'rw', isa => Int, default => 0);
has '_pattern_container_stack'	=> (is => 'rw', isa => ArrayRef);
has 'blank_nodes'	=> (is => 'ro', isa => HashRef[ConsumerOf['Attean::API::Blank']], predicate => 'has_blank_nodes_map', default => sub { +{} });

sub file_extensions { return [qw(rq ru)] }

sub canonical_media_type { return "application/sparql-query" }

sub media_types {
	return [qw(application/sparql-query application/sparql-update)];
}

sub handled_type {
	state $ITEM_TYPE = Type::Tiny::Role->new(role => 'Attean::API::Algebra');
	return $ITEM_TYPE;
}

with 'Attean::API::AtOnceParser', 'Attean::API::Parser', 'Attean::API::AbbreviatingParser';
with 'Attean::API::CDTBlankNodeMappingParser';
with 'MooX::Log::Any';

sub BUILDARGS {
	my $class	= shift;
	my %args	= @_;
	my $ns		= delete $args{namespaces} // 	URI::NamespaceMap->new();
	my %a		= (args => \%args, namespaces => $ns);
	if (my $handler	= delete $args{handler}) {
		$a{handler}	= $handler;
	}
	return \%a;
}

################################################################################

sub _configure_lexer {
	my $self	= shift;
	my $l		= shift;
	$l->add_regex_rule( qr/RANK/, KEYWORD, sub { return uc(shift) } );
	return $l;
}

=item C<< parse ( $sparql ) >>

Parse the C<< $sparql >> query string and return the resulting
L<Attean::API::Algebra> object.

=cut



( run in 0.656 second using v1.01-cache-2.11-cpan-39bf76dae61 )