| 1 | package App::perlrdf::Command::RDQL; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use utf8; | ||
| 7 | |||
| 8 | BEGIN { | ||
| 9 | $App::perlrdf::Command::RDQL::AUTHORITY = 'cpan:TOBYINK'; | ||
| 10 | $App::perlrdf::Command::RDQL::VERSION = '0.004'; | ||
| 11 | } | ||
| 12 | |||
| 13 | use base 'App::perlrdf::Command::Query'; | ||
| 14 | use namespace::clean; | ||
| 15 | |||
| 16 | use constant abstract => q (query stores, files or remote endpoints with RDQL); | ||
| 17 | use constant command_names => qw( rdql ); | ||
| 18 | use constant description => <<'DESCRIPTION'; | ||
| 19 | Use RDQL to query: | ||
| 20 | |||
| 21 | * an RDF::Trine::Store; | ||
| 22 | * a remote SPARQL Protocol (1.0/1.1) endpoint; or | ||
| 23 | * one or more input files; | ||
| 24 | |||
| 25 | But not a combination of the above. | ||
| 26 | DESCRIPTION | ||
| 27 | |||
| 28 | sub opt_spec | ||
| 29 | { | ||
| 30 | map { | ||
| 31 | $_->[0] =~ s/sparql/rdql/ if @$_; | ||
| 32 | $_; | ||
| 33 | } shift->SUPER::opt_spec | ||
| 34 | } | ||
| 35 | |||
| 36 | sub validate_args | ||
| 37 | { | ||
| 38 | my ($self, $opt, $arg) = @_; | ||
| 39 | $self->usage_error("Must not provide both 'rdql_file' and 'execute' options.") | ||
| 40 | if exists $opt->{rdql_file} && exists $opt->{execute}; | ||
| 41 | $self->SUPER::validate_args($opt, $arg); | ||
| 42 | } | ||
| 43 | |||
| 44 | sub _sparql | ||
| 45 | { | ||
| 46 | require RDF::Query; | ||
| 47 | my ($self, $opt, $arg) = @_; | ||
| 48 | my $rdql = $self->SUPER::_sparql($opt, $arg); | ||
| 49 | my $query = RDF::Query::->new($rdql, { lang => 'rdql' }) | ||
| 50 | or die RDF::Query->error; | ||
| 51 | return $query->as_sparql; | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; | ||
| 55 |