Commits

Konstantin Baierer  committed 3826063

More documentation, some enhancements to RdfBackend

  • Participants
  • Parent commits 2fd7cb3

Comments (0)

Files changed (15)

 **/*.sqlite
 t/temp.t
 t/test.pl
+*.tmp
     Schema introspection without at least RDFS reasoning can only get you so
     far.
 
+    Recursive import is buggy.
+
 AUTHOR
     Konstantin Baierer (<kba@cpan.org>)
     Toby Inkster (<tobyink@cpan.org>)
 
 Schema introspection without at least RDFS reasoning can only get you so far.
 
+Recursive import is buggy.
+
 =head1 AUTHOR
 
 =over 4

File lib/MooseX/Semantic.pm

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

File lib/MooseX/Semantic/Meta/Attribute/Trait.pm

 RDF language for this resource. 
 
 Makes sense only when the attribute in question is of a literal type, i.e.
-C<Str>, C<Num> or descendants thereof.
+C<Str>, C<Bool>, C<Num> or descendants thereof.
 
 =cut
 
 # );
 
 1;
+=head1 AUTHOR
+
+Konstantin Baierer (<kba@cpan.org>)
+
+=head1 SEE ALSO
+
+=over 4
+
+=item L<MooseX::Semantic|MooseX::Semantic>
+
+=back
+
+=cut
+
+=head1 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.
+

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

 package MooseX::Semantic::Role::RdfBackend;
 use  Moose::Role;
 use MooseX::ClassAttribute;
-use MooseX::Semantic::Types qw(ArrayOfTrineResources);
+use MooseX::Semantic::Types qw(ArrayOfTrineResources TrineStore);
 use Data::Dumper;
 # use MooseX::Role::Parameterized;
 
 with (
     # Class role
     'MooseX::Semantic::Role::WithRdfType',
+    'MooseX::Semantic::Role::Resource',
 );
 
-our %RDF_TRINE_STORE_OPTS = (
-    # storetype => 'DBI',
-    # name => 'filerdf_store',
-    # dsn => 'dbi:SQLite:dbname=/media/DB/file_rdf.sqlite',
-    # username => 'FAKE',
-    # password => 'FAKE',
-);
-sub _trine_store_opts {
-    my ($cls, %opts) = @_;
-    %RDF_TRINE_STORE_OPTS = %opts;
-}
+
+=head1 NAME
+
+MooseX::Semantic::Role::RdfBackend - Associate a class with a RDF::Trine::Store
+
+=head1 SYNOPSIS
+
+    # My/Model/Person.pm
+    package My::Model::Person;
+    use Moose;
+    with qw(MooseX::Semantic::Role::RdfBackend);
+    __PACKAGE__->rdf_store({
+        storetype => 'DBI',
+        name => 'semantic_moose',
+        dsn => 'dbi:SQLite:dbname=t/data/semantic_moose.sqlite',
+        username => 'FAKE',
+        password => 'FAKE',
+    });
+    ...
+
+    # your script
+    my $p = My::Model::Person->new( rdf_about => 'http://mydomain.org/data/John' );
+    $p->store();
+    my $x = My::Model::Person->new_from_store( 'http://mydomain.org/data/John' );
+    print $x->rdf_about     # prints "<http://mydomain.org/data/John>"
+
+
+=head1 DESCRIPTION
+
+=cut
+
+=head1 CLASS ATTRIBUTES
+
+=head2 rdf_store
+
+Reference to a lazily built RDF::Trine::Store object. Can be instantiated with everything
+that L<RDF::Trine::Store's|RDF::Trine::Store> C<new> method accepts, i.e. a DSN-like string,
+a hash reference of options or a blessed object.
+
+=cut
 
 class_has rdf_store => (
     is => 'rw',
     lazy => 1,
-    isa => 'RDF::Trine::Store',
-    default => sub {
-        RDF::Trine::Store->new_with_config( \%RDF_TRINE_STORE_OPTS )
-    },
+    coerce => 1,
+    isa => TrineStore,
+    default => sub { TrineStore->coerce; }, # XXX is this really what we want by default - a volatile store?
 );
 
+=head1 METHODS
+
+=head2 C<new_from_store( $uri )>
+
+Searches the RDF store for a resource C<$uri> and tries to instantiate an object
+using the C<new_from_model> method of L<MooseX::Semantic::Role::RdfImport>.
+
+=cut
+
 sub new_from_store {
     my ($cls, $uri) = @_;
     my $model = RDF::Trine::Model->new( $cls->rdf_store );
     return $cls->new_from_model( $model, $uri );
 }
 
+=head2 C<store()>
+
+Exports an instance to RDF into the model underlying the RDF store.
+
+=cut
+
 sub store {
     my ($inst) = @_;
     my $model = RDF::Trine::Model->new( $inst->rdf_store );
     $inst->export_to_model( $model );
 }
 
+=head1 CONSUMED ROLES
+
+=over 4
+
+=item L<MooseX::Semantic::Role::Resource>
+
+=item L<MooseX::Semantic::Role::WithRdfType>
+
+=item L<MooseX::Semantic::Role::RdfImport>
+
+=item L<MooseX::Semantic::Role::RdfExport>
+
+=back
+
+=cut
+
 1;
+
+=head1 AUTHOR
+
+Konstantin Baierer (<kba@cpan.org>)
+
+=head1 SEE ALSO
+
+=over 4
+
+=item L<MooseX::Semantic|MooseX::Semantic>
+
+=item L<RDF::Trine::Store|RDF::Trine::Store>
+
+=back
+
+=cut
+
+=head1 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.
+

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

 
 
 1;
+=head1 AUTHOR
+
+Konstantin Baierer (<kba@cpan.org>)
+
+=head1 SEE ALSO
+
+=over 4
+
+=item L<MooseX::Semantic|MooseX::Semantic>
+
+=back
+
+=cut
+
+=head1 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.
+

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

 }
 
 1;
+=head1 AUTHOR
+
+Konstantin Baierer (<kba@cpan.org>)
+
+=head1 SEE ALSO
+
+=over 4
+
+=item L<MooseX::Semantic|MooseX::Semantic>
+
+=back
+
+=cut
+
+=head1 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.
+

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

 
 =back
 
+=head1 AUTHOR
+
+Konstantin Baierer (<kba@cpan.org>)
+
+=head1 SEE ALSO
+
+=over 4
+
+=item L<MooseX::Semantic|MooseX::Semantic>
+
+=back
+
+=cut
+
+=head1 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.
+

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

 };
 
 1;
+=head1 AUTHOR
+
+Konstantin Baierer (<kba@cpan.org>)
+
+=head1 SEE ALSO
+
+=over 4
+
+=item L<MooseX::Semantic|MooseX::Semantic>
+
+=back
+
+=cut
+
+=head1 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.
+

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

 };
 
 1;
+
+=head1 AUTHOR
+
+Konstantin Baierer (<kba@cpan.org>)
+
+=head1 SEE ALSO
+
+=over 4
+
+=item L<MooseX::Semantic|MooseX::Semantic>
+
+=back
+
+=cut
+
+=head1 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.
+

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

 
 =cut
 
+=head1 ATTRIBUTES
+
+=cut
+
+=head2 C<rdf_about>
+
+The URI of the resource this object represents. When not specified, this defaults to a
+random urn:UUID URI.
+
+=cut
 
 has rdf_about => (
     is => 'rw',
 }
 
 1;
+
+=head1 METHODS
+
+=head2 C<is_blank>
+
+Delegation to C<RDF::Trine::Node>. Returns a true value if the C<rdf_about> node is a blank node.
+
+=cut
+
+=head2 C<is_resource>
+
+Delegation to C<RDF::Trine::Node>. Returns a true value if the C<rdf_about> node is a resource node.
+
+=cut
+
+=head1 AUTHOR
+
+Konstantin Baierer (<kba@cpan.org>)
+
+=head1 SEE ALSO
+
+=over 4
+
+=item L<MooseX::Semantic|MooseX::Semantic>
+
+=back
+
+=cut
+
+=head1 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.
+

File lib/MooseX/Semantic/Test/BackendPerson.pm

     'MooseX::Semantic::Role::RdfExport',
     'MooseX::Semantic::Role::RdfObsolescence',
     # 'MooseX::Semantic::Role::WithRdfType',
-    'MooseX::Semantic::Role::Resource',
+    # 'MooseX::Semantic::Role::Resource',
 );
 
 # extends 'MooseX::Semantic::Test::Person';

File lib/MooseX/Semantic/Types.pm

     CPAN_URI
     UriStr
     TrineModel
+    TrineStore
     )];
 use MooseX::Types::URI Uri => { -as => 'MooseX__Types__URI__Uri' };
 use MooseX::Types::Moose qw{:all};
 subtype ArrayOfTrineNodes, as ArrayRef[TrineNode];
 subtype UriStr, as Str;
 class_type TrineModel, { class => 'RDF::Trine::Model' };
+class_type TrineStore, { class => 'RDF::Trine::Store' };
 
 
 class_type CPAN_URI, { class => 'URI' };
     },
 );
 
+coerce( TrineStore,
+    from Undef, via { RDF::Trine::Store->temporary_store },
+    from Defined, via { RDF::Trine::Store->new ( $_ ) },
+);
+
 
 1;

File t/rdf_backend/role_rdfbackend.t

 use MooseX::Semantic::Test::BackendPerson;
 
 
-MooseX::Semantic::Test::BackendPerson->_trine_store_opts(
+MooseX::Semantic::Test::BackendPerson->rdf_store({
     storetype => 'DBI',
     name => 'semantic_moose',
     dsn => 'dbi:SQLite:dbname=t/data/semantic_moose.sqlite',
     username => 'FAKE',
     password => 'FAKE',
-);
+});
 
 isa_ok( MooseX::Semantic::Test::BackendPerson->rdf_store, 'RDF::Trine::Store');
 is( MooseX::Semantic::Test::BackendPerson->rdf_store->model_name, 'semantic_moose');