Commits

Konstantin Baierer committed 9a7afbf

added rdfimport method, Changes file, version bump to 0.002

  • Participants
  • Parent commits d43adc5

Comments (0)

Files changed (8)

 t/temp.t
 t/test.pl
 *.tmp
+Makefile.PL
+MooseX-Semantic*
+0.002 Wed Feb 22 17:53:04 CET 2012
+    * added 'get_instance_hash' to RdfImport (usecase: Config singletons)

File lib/MooseX/Semantic.pm

 package MooseX::Semantic;
 BEGIN { $MooseX::Semantic::AUTHORITY = 'cpan:KBA'; }
-BEGIN { $MooseX::Semantic::VERSION = '0.001'; }
+BEGIN { $MooseX::Semantic::VERSION = '0.002'; }
 
 1;
 

File lib/MooseX/Semantic/Role/RdfImport.pm

     return $resource_obj;
 }
 
+=head2 get_instance_hash
+
+Creates a hash of attribute/value pairs that can be passed to $cls->new
+
+=cut
+
+sub get_instance_hash {
+    my ( $cls, $model, $uri, $unfinished_resources ) = @_;
+
+    my $resource = TrineResource->coerce( $uri );
+    $unfinished_resources = Set::Object->new unless $unfinished_resources;
+    $unfinished_resources->insert( $resource );
+    my $inst_hash        = $cls->_build_instance_hash($resource, $model, $unfinished_resources);
+    $inst_hash->{rdf_about} = $resource;
+
+    return $inst_hash;
+}
+
 sub _build_instance_hash {
     my $cls = shift;
     my ($resource, $model, $unfinished_resources) = @_;

File t/data/blank_node_01.ttl

 _:b1
     a foaf:Person ;
     foaf:name "Bob" .
+
+<alice-inline>
+    a foaf:person ;
+    foaf:name "Alice Inline" ;
+    foaf:knows [
+        a foaf:person ;
+        foaf:name "Bob Inline" 
+    ] .

File t/rdf_import/blank_node.t

-use Test::More tests=>4;
+use Test::More tests=>8;
 use RDF::Trine;
 use Data::Dumper;
 use MooseX::Semantic::Test::Person;
 # warn Dumper $serializer->serialize_model_to_string($model);
 ok( my $alice = MooseX::Semantic::Test::Person->new_from_model($model, 'http://example.com/alice'), 'Alice is detected');
 ok( $alice->has_friends, 'Alice has a friend' );
-TODO: {
-    local $TODO = "recursive import NIH";
-    is( $alice->friends->[0]->name, Bob, "Alice's friend's name is Bob" );
-}
+is( $alice->friends->[0]->name, Bob, "Alice's friend's name is Bob" );
 ok( $alice->friends->[0]->is_blank, "Bob is a blank node" );
+ok( my $alice_inline = MooseX::Semantic::Test::Person->new_from_model($model, 'http://example.com/alice-inline'), 'Alice is detected');
+ok( $alice_inline->has_friends, "Alice has a friend Inline" );
+is( $alice_inline->friends->[0]->name, "Bob Inline", "Alice's friend's name is Bob Inline" );
+ok( $alice_inline->friends->[0]->is_blank, "Bob is a blank node Inline" );
+
+
 # warn Dumper $alice;

File t/rdf_import/rdf_import.t

     # warn Dumper $alice_model_str;
 }
 
+sub import_instance_hash {
+    my $base_uri = 'http://tobyinkster.co.uk/#i';
+    my $test_model = RDF::Trine::Model->temporary_model;
+    RDF::Trine::Parser::Turtle->parse_file_into_model(
+        $base_uri,
+        't/data/toby_inkster.ttl',
+        $test_model,
+    );
+    my $hash = MooseX::Semantic::Test::Person->get_instance_hash( $test_model, $base_uri );
+    is(keys %{$hash}, 7, 'correct number of keys');
+    # warn Dumper $hash;
+}
+
 &import_from_ttl;
 &symmetrical_property;
+&import_instance_hash;
 # &import_from_web;
 done_testing;

File t/util/util_walker.t

 }
 
 
-&simple_type_walker
+&simple_type_walker;
 &class_name_finder;