Apache-SPARQL

 view release on metacpan or  search on metacpan

lib/Apache/SPARQL.pm  view on Meta::CPAN

		close($fh);
		return $content;
	} else {
		return $class->_wget( $ap, $file_or_uri );
		};
	};

# does HTTP GET of given URI
sub _wget {
	my ($class, $ap, $uri, $accept) = @_;

	my $ua = LWP::UserAgent->new( timeout => 60 );

	my $server = $ap->server;
	my %headers = ( "User-Agent" => "sparqlserver\@".$server->server_hostname."/".$Apache::SPARQL::VERSION );

	if( $accept ) {
        	$headers{'Accept'} = $accept;
	} else {
		#otherwise try any
        	$headers{'Accept'} = 'application/rdf+xml,application/xml,text/xml,application/x-turtle,application/turtle,text/rdf+n3;q=0.9,*/*;q=0.5';
		};

        my $response = $ua->get( $uri, %headers );

	return
		unless($response->is_success);

	return $response->content;
	};

sub _mp2 {
	return MP2;
	};

sub _param {
	my ($class, $ap, $field) = @_;

	if ( $class->_mp2 ) {
		if($field) {
			return CGI::param($field);
		} else {
			my @params = CGI::param();
			return @params;	
			};
		};

	my $request = Apache::Request->new($ap);

	if($field) {
		return $request->param($field);
	} else {
		my @params = $request->param;
		return @params;	
		};
	};

sub _nometh {
	my ($class, $ap, $field) = @_;

	my $caller = (caller(1))[3];
	$caller =~ s/.*:://;

	$ap->log()->error(sprintf("package %s does not define a '%s' method", $class, $caller));

	return 0;
	};

sub _header_in {
	my ($class, $ap, $field) = @_;

	return ( $class->_mp2 ) ? $ap->headers_in()->{$field} : $ap->header_in($field);
	};

sub _header_out {
	my ($class, $ap, $field, $value) = @_;

	( $class->_mp2 ) ? $ap->headers_out()->{$field} = $value: $ap->header_out($field,$value);
	};

=cut

=head1 NAME

Apache::SPARQL - mod_perl handler base class to implement a SPARQL query service using HTTP bindings.

=head1 SYNOPSIS

 <Location /rdfstore>

   SetHandler	perl-script
   PerlHandler	Apache::SPARQL

 </Location>

 #

 my $ua  = LWP::UserAgent->new();
 my $req = HTTP::Request->new(GET => "http://pim.example/rdfstore?query=PREFIX+foaf%3A+%3Chttp%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F%3E%0D%0ASELECT+%3Fpg%0D%0AWHERE%0D%0A++%28%3Fwho+foaf%3Aname+%22Norm+Walsh%22%29%0D%0A++%28%3Fwho+foaf%3Aweblog+%3Fpg%29%...

 my $res = $ua->request($req);

=head1 DESCRIPTION

Apache::SPARQL is a mod_perl handler base class to implement a SPARQL query service using HTTP bindings.

=head1 IMPORTANT

This package is a base class and not expected to be invoked
directly. Please use one of the backends handlers instead.

=head1 SUPPPORTED BACKENDS

 Apache::SPARQL::RDFStore

=head1 MOD_PERL COMPATIBILITY

This handler will work with both mod_perl 1.x and mod_perl 2.x.

=head1 AUTHOR



( run in 2.503 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )