App-perlrdf-Command-Query

 view release on metacpan or  search on metacpan

lib/App/perlrdf/Command/Query.pm  view on Meta::CPAN

use utf8;

BEGIN {
	$App::perlrdf::Command::Query::AUTHORITY = 'cpan:TOBYINK';
	$App::perlrdf::Command::Query::VERSION   = '0.004';
}

use App::perlrdf -command;
use namespace::clean;

use constant abstract      => q (query stores, files or remote endpoints with SPARQL);
use constant command_names => qw( query sparql q );
use constant description   => <<'DESCRIPTION';
Use SPARQL to query:

	* an RDF::Trine::Store;
	* a remote SPARQL Protocol (1.0/1.1) endpoint; or
	* one or more input files;

But not a combination of the above.
DESCRIPTION

use constant opt_spec => (
	__PACKAGE__->store_opt_spec,
	[]=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>,
	[ 'input|i=s@',        'Input filename or URL' ],
	[ 'input-spec|I=s@',   'Input file specification' ],
	[ 'input-format|p=s',  'Input format (mnemonic: parse)' ], 
	[ 'input-base|b=s',    'Input base URI' ],
	[ 'graph|g=s',         'Graph URI for input' ],
	[ 'autograph|G',       'Generate graph URI based on input URI' ],
	[]=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>,
	[ 'endpoint=s',        'Remote SPARQL Protocol endpoint' ],
	[ 'query_method=s',    'Query method (GET/POST/etc)' ],
	[]=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>,
	[ 'execute|e=s',       'Query to execute' ],
	[ 'sparql-file|f=s',   'File containing query to execute' ],
	[]=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>
	[ 'output|o=s@',       'Output filename or URL' ],
	[ 'output-spec|O=s@',  'Output file specification' ],
	[ 'output-format|s=s', 'Output format (mnemonic: serialise)' ],
);

sub validate_args
{
	my ($self, $opt, $arg) = @_;
	
	my %exclusions = (
		execute  => ['sparql_file'],
		endpoint => [
			qw[ store dbi sqlite username password host port dbname database ],
			qw[ input input_spec input_format input_base ],
		],
		query_method => [
			qw[ store dbi sqlite username password host port dbname database ],
			qw[ input input_spec input_format input_base ],
		],
		map { ; $_ => [
			qw[ store dbi sqlite username password host port dbname database ],
			qw[ endpoint ],
		] } qw( input input_spec input_format input_base )
	);
	
	foreach my $k (keys %exclusions)
	{
		next unless exists $opt->{$k};
		foreach my $e (@{ $exclusions{$k} })
		{
			next unless exists $opt->{$e};
			$self->usage_error("Must not provide both '$k' and '$e' options.");

lib/App/perlrdf/Command/Query.pm  view on Meta::CPAN

	}
}

sub execute
{
	require RDF::Trine;
	my ($self, $opt, $arg) = @_;
	
	my $sparql = $self->_sparql($opt, $arg);

	if (exists $opt->{endpoint})
	{
		return $self->_process_sparql($opt, $arg, $sparql, $opt->{endpoint});
	}

	my $model = $self->_model($opt, $arg);
	$self->_process_sparql($opt, $arg, $sparql, $model);
}

1;


__END__

lib/App/perlrdf/Command/RDQL.pm  view on Meta::CPAN

use utf8;

BEGIN {
	$App::perlrdf::Command::RDQL::AUTHORITY = 'cpan:TOBYINK';
	$App::perlrdf::Command::RDQL::VERSION   = '0.004';
}

use base 'App::perlrdf::Command::Query';
use namespace::clean;

use constant abstract      => q (query stores, files or remote endpoints with RDQL);
use constant command_names => qw( rdql );
use constant description   => <<'DESCRIPTION';
Use RDQL to query:

	* an RDF::Trine::Store;
	* a remote SPARQL Protocol (1.0/1.1) endpoint; or
	* one or more input files;

But not a combination of the above.
DESCRIPTION

sub opt_spec
{
	map {
		$_->[0] =~ s/sparql/rdql/ if @$_;
		$_;



( run in 0.265 second using v1.01-cache-2.11-cpan-b61123c0432 )