use LWP::UserAgent;
use Data::Dumper;
use JSON::XS;

sub wdSparqlQuery(@args) {
  my $agent = shift;
  my $query = shift;
  my $format = shift;
  my $endpointURL = "{ENDPOINT_URL}";
  my $queryURL = "${endpointURL}?query=${query}&format=${format}";
  my $ua = LWP::UserAgent -> new;
  $ua -> agent($agent);
  my $req = HTTP::Request -> new(GET => $queryURL);
  my $res = $ua -> request($req);
  my $str = $res -> content;
  return $str;
}

$agent = "MyApp/0.1 ";
$query = {SPARQL_QUERY}
$format = "json";
$data = JSON::XS::decode_json(wdSparqlQuery($agent, $query, $format));

print "Retrieved data:\n";
print Dumper($data);
