konstantin baierer > MooseX-Semantic > MooseX::Semantic::Role::RdfImport

Download:
MooseX-Semantic-0.006.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Source  

NAME ^

MooseX::Semantic::Role::RdfImport - Role for classes instantiable from RDF

SYNOPSIS ^

    package My::Model::Person;
    use Moose;
    with qw(MooseX::Semantic::Role::RdfImport);
    has name => (
        traits => ['Semantic'],
        is => 'rw',
        isa => 'Str',
        uri => 'http://xmlns.com/foaf/0.1/name',
        uri_reader => ['http://myont.org/onto#name'],
    );

    package main;
    my $base_uri = 'http://myont.org/data/';
    my $rdf_in_turtle = '
        <http://myont.org/data/Lenny> <http://xmlns.com/foaf/0.1/name> "Lenny" .
        <http://myont.org/data/Carl> <http://myont.org/onto#name> "Carl" .
    ';
    my $model = RDF::Trine::Model->temporary_model;
    RDF::Trine::Parser::Turtle->parse_into_model($base_uri, $rdf_in_turtle, $model);
    my $lenny = My::Model::Person->new_from_model($model, 'http://myont.org/data/Lenny');
    my $carl = My::Model::Person->new_from_model($model, 'http://myont.org/data/Carl');
    print $lenny->name;     # 'Lenny'
    print $carl->name;      # 'Carl'

METHODS ^

new_from_model( $model, $uri )

Creates a new object from resource $uri in $model.

This loops through all attributes with trait MooseX::Semantic::Meta::Attribute::Trait and searches $model for all statements about $uri with the attribute's uri or any of the uri_reader attributes as property. For every match, the appropriate key in the instantiation hash is set to the value found.

When the object of a statement represents a resource ... TODO

When all attributes have been walked, the class is instantiated with the instantiation hash and the newly-created object is returned.

get_instance_hash

Creates a hash of attribute/value pairs that can be passed to $cls->new

new_from_web( $uri )

Retrieves the remote graph $uri using RDF::Trine::Parser's parse_url_into_model method and tries to create a new instance from the statements found.

AUTHOR ^

Konstantin Baierer (<kba@cpan.org>)

SEE ALSO ^

MooseX::Semantic

LICENCE AND COPYRIGHT ^

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perldoc perlartistic.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

syntax highlighting: