MooseX::Semantic::Role::RdfImport - Role for classes instantiable from RDF
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'
Creates a new object from resource
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.
Creates a hash of attribute/value pairs that can be passed to $cls->new
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.
Konstantin Baierer (<email@example.com>)
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.