RDF::AllegroGraph::Server3 - AllegroGraph server handle for the AGv3 series


RDF-AllegroGraph-Easy documentation Contained in the RDF-AllegroGraph-Easy distribution.

Index


Code Index:

NAME

Top

RDF::AllegroGraph::Server3 - AllegroGraph server handle for the AGv3 series

SYNOPSIS

Top

# same interface as RDF::AllegroGraph::Server

INTERFACE

Top

Methods

AUTHOR

Top

Robert Barta, <rho at devc.at>

COPYRIGHT & LICENSE

Top


RDF-AllegroGraph-Easy documentation Contained in the RDF-AllegroGraph-Easy distribution.
package RDF::AllegroGraph::Server3;

use strict;
use warnings;

use base qw(RDF::AllegroGraph::Server);

use JSON;
use Data::Dumper;

use RDF::AllegroGraph::Catalog3;

sub catalogs {
    my $self = shift;
    my $resp = $self->{ua}->get ($self->{ADDRESS} . '/catalogs');
    die "protocol error: ".$resp->status_line unless $resp->is_success;
    my $cats = from_json ($resp->content);
#    warn Dumper $cats;
    return 
	map { $_ => RDF::AllegroGraph::Catalog3->new (NAME => $_, SERVER => $self) }
        map { s|^/catalogs|| && $_ }   
        @$cats;
}

sub ping {
    my $self = shift;
    $self->catalogs and return 1;                                    # even if there are no catalogs, we survived the call
}

sub models {
    my $self = shift;
    my %cats = $self->catalogs;                                      # find all catalogs
    return
	map { $_->id => $_ }                                         # generate a hash, because the id is a good key
	map { $_->repositories }                                     # generate from the catalog all its repos
        values %cats;          
}

sub model {
    my $self = shift;
    my $id   = shift;
    my %options = @_;

    my ($catid, $repoid) = ($id =~ q|(/.+?)(/.+)|) or die "id must be of the form /something/else";

    my %catalogs = $self->catalogs;
    die "no catalog '$catid'" unless $catalogs{$catid};

    return $catalogs{$catid}->repository ($id, $options{mode});
}

our $VERSION  = '0.02';

1;

__END__

#sub protocol {
#    my $self = shift;
#    my $resp = $self->{ua}->get ($self->{ADDRESS} . '/protocol');
#    die "protocol error: ".$resp->status_line unless $resp->is_success;
#    return $resp->content;
#}