diff --git a/README b/README index 0538837..8253952 100644 --- a/README +++ b/README @@ -5,9 +5,9 @@ SYNOPSIS my $mrdf = MongoDB::RDF->new( database => MongoDB::Connection->new(host => 'localhost', port => 27017)->test_rdf ); - + my $graph = $mrdf->default_graph; - + my $r = MongoDB::RDF::Resource->new('http://example.org/0'); $r->dc_title('my title'); $graph->save($r); diff --git a/lib/MongoDB/RDF.pm b/lib/MongoDB/RDF.pm index 21d2a48..34a9660 100644 --- a/lib/MongoDB/RDF.pm +++ b/lib/MongoDB/RDF.pm @@ -18,9 +18,9 @@ MongoDB::RDF - Stores RDF-JSON documents in MongoDB. my $mrdf = MongoDB::RDF->new( database => MongoDB::Connection->new(host => 'localhost', port => 27017)->test_rdf ); - + my $graph = $mrdf->default_graph; - + my $r = MongoDB::RDF::Resource->new('http://example.org/0'); $r->dc_title('my title'); $graph->save($r); diff --git a/lib/MongoDB/RDF/Cursor.pm b/lib/MongoDB/RDF/Cursor.pm index 893414a..9832310 100644 --- a/lib/MongoDB/RDF/Cursor.pm +++ b/lib/MongoDB/RDF/Cursor.pm @@ -28,7 +28,7 @@ sub cursor { $_[0]->{cursor} } =cut sub next { - my $self = shift; + my $self = shift; my $doc = $self->cursor->next; return unless $doc; return MongoDB::RDF::Resource->_new_from_document($doc); @@ -104,7 +104,7 @@ TODO explain why it sort by the first value of the predicate. =cut -sub sort { +sub sort { my $self = shift; my ($order) = @_; diff --git a/lib/MongoDB/RDF/Graph.pm b/lib/MongoDB/RDF/Graph.pm index 6b87ea5..db9cbb2 100644 --- a/lib/MongoDB/RDF/Graph.pm +++ b/lib/MongoDB/RDF/Graph.pm @@ -28,11 +28,11 @@ sub _new { my %args = @_; my $self = bless {}, $class; for (qw(name mrdf)) { - die "$_ required" unless $args{$_}; + die "$_ required" unless $args{$_}; $self->{$_} = $args{$_}; } # TODO maintain a global cache of the ensured indexes - # the cost of ensure_index may not be negligable + # the cost of ensure_index may not be negligable $self->collection->ensure_index({ _subject => 1 }, { unique => 1 }); $self->ensure_index({ rdf_type => 1 }); return $self; @@ -53,7 +53,7 @@ sub name { $_[0]->{name} } =head2 $self->load( $uri ) Loads a resource from the graph. -If this resource has a registered rdf_type, then this resource +If this resource has a registered rdf_type, then this resource will be reblessed to the corresponding class. (See MongoDB::RDF::Resource->register_rdf_type) diff --git a/lib/MongoDB/RDF/Namespace.pm b/lib/MongoDB/RDF/Namespace.pm index c64e36f..c814887 100644 --- a/lib/MongoDB/RDF/Namespace.pm +++ b/lib/MongoDB/RDF/Namespace.pm @@ -30,7 +30,7 @@ sub resolve { return $uri.$name; } } - return $local; + return $local; } =head2 register diff --git a/lib/MongoDB/RDF/Resource.pm b/lib/MongoDB/RDF/Resource.pm index f3fb2aa..1e23bc3 100644 --- a/lib/MongoDB/RDF/Resource.pm +++ b/lib/MongoDB/RDF/Resource.pm @@ -43,7 +43,7 @@ sub new { $self->set_subject($subject); if (my $type = $Class2rdf_type{$class}) { - $self->set(rdf_type => $type); + $self->set(rdf_type => $type); } $self->init if $self->can('init'); @@ -59,7 +59,7 @@ Set the subject, if $uri is undef a blank node URI is created. =cut sub set_subject { - my $self = shift; + my $self = shift; my ($uri) = @_; unless ($uri) { my $oid = MongoDB::OID->new; @@ -76,7 +76,7 @@ Returns the subject. =cut sub subject { - my $self = shift; + my $self = shift; return $self->{document}{_subject}; } @@ -128,11 +128,11 @@ sub properties { # for this reason, if the property has only one element, # don't create the array. sub _property { - my $self = shift; + my $self = shift; my ($uri, $values) = @_; if ($values) { - die 'must be an arrayref' unless ref $values eq 'ARRAY'; + die 'must be an arrayref' unless ref $values eq 'ARRAY'; if (@$values == 0) { delete $self->{document}{$uri}; } @@ -149,7 +149,7 @@ sub _property { # object in the "subject predicate object" sense sub _value2object { - my $self = shift; + my $self = shift; my ($value) = @_; if (looks_like_uri($value)) { return { type => 'uri', value => canonical_uri($value) }; @@ -160,7 +160,7 @@ sub _value2object { } sub _object2value { - my $self = shift; + my $self = shift; my ($object, $opts) = @_; if (my $graph = $opts->{instanciate}) { die '['.$self->mongodb_id.'] type is not uri, value: '.$object->{value} @@ -190,7 +190,7 @@ Example: =cut sub get { - my $self = shift; + my $self = shift; my ($predicate) = @_; my $uri = fencode(resolve($predicate)); my @values = map { @@ -204,7 +204,7 @@ sub get { =cut sub add { - my $self = shift; + my $self = shift; my ($predicate, $value) = @_; my $uri = fencode(resolve($predicate)); my $props = $self->_property($uri); @@ -218,7 +218,7 @@ sub add { =cut sub del { - my $self = shift; + my $self = shift; my ($predicate, $value) = @_; my $uri = fencode(resolve($predicate)); my $props = $self->_property($uri); @@ -237,7 +237,7 @@ or $self->set( $predicate ); to remove all the values. =cut sub set { - my $self = shift; + my $self = shift; my $predicate = shift; my $values = \@_; my $uri = fencode(resolve($predicate)); @@ -284,11 +284,11 @@ Returns a RDF/JSON document. See subject => $self->properties }; - my $j = JSON::Any->new; + my $j = JSON::Any->new; return $j->objToJson($obj); } @@ -297,8 +297,8 @@ sub as_rdf_json { =cut sub as_rdf_xml { - my $self = shift; - # TODO + my $self = shift; + # TODO } =head2 $self->as_ntriples @@ -351,7 +351,7 @@ MongoDB::RDF::Resource can be subsclassed like this: $graph->save($r); ... - + my $r = $graph->load('http://myinstance'); # $r is a MyClass diff --git a/lib/MongoDB/RDF/Serializer.pm b/lib/MongoDB/RDF/Serializer.pm index e933e19..d7995e2 100644 --- a/lib/MongoDB/RDF/Serializer.pm +++ b/lib/MongoDB/RDF/Serializer.pm @@ -4,7 +4,7 @@ use warnings; =head2 $class->dump( resource => ... ) -or +or $class->dump( graph => ... ) $class->dump( graph => ..., filename => ... ) @@ -38,7 +38,7 @@ sub dump { } else { - die "graph or resource required"; + die "graph or resource required"; } $fh->close if $fh; @@ -66,8 +66,8 @@ sub serialize_resource { die 'to be overwritten' } =head2 $class->load( graph => ..., filename => ... ) -or - $class->load( graph => ... ); # read STDIN +or + $class->load( graph => ... ); # read STDIN =cut diff --git a/lib/MongoDB/RDF/Serializer/NTriples.pm b/lib/MongoDB/RDF/Serializer/NTriples.pm index a1ebb3d..b548f48 100644 --- a/lib/MongoDB/RDF/Serializer/NTriples.pm +++ b/lib/MongoDB/RDF/Serializer/NTriples.pm @@ -8,7 +8,7 @@ use Encode; =head1 DESCRIPTION -NTriples serialization +NTriples serialization =cut @@ -32,7 +32,7 @@ sub _encode_literal { $l =~ s/\r/\\r/g; $l =~ s/\t/\\t/g; $l =~ s/\"/\\"/g; - return $l; + return $l; } =head2 serialize_resource @@ -60,7 +60,7 @@ sub _save_triplet { my ($graph, $s, $p, $o) = @_; my $resource = $graph->load($s) || MongoDB::RDF::Resource->new($s); $resource->add($p => $o); - $graph->save($resource); + $graph->save($resource); } sub _clean_line { @@ -72,7 +72,7 @@ sub _clean_line { $line = Encode::decode_utf8($line); $line =~ s/^\s+//; $line =~ s/\s+$//; - return $line; + return $line; } sub _decode_literal { diff --git a/lib/MongoDB/RDF/Util.pm b/lib/MongoDB/RDF/Util.pm index 38aa464..7e48843 100644 --- a/lib/MongoDB/RDF/Util.pm +++ b/lib/MongoDB/RDF/Util.pm @@ -33,8 +33,8 @@ sub looks_like_uri { # XXX we may want to not guess, and assume that the value =head2 fencode -MongoDB doesn't allow '.' in the field names. -As the fields names here are URIs, we just encode the '.' to '%2E' +MongoDB doesn't allow '.' in the field names. +As the fields names here are URIs, we just encode the '.' to '%2E' =cut @@ -66,7 +66,7 @@ sub convert_query { $convert_q = sub { my ($query) = @_; for my $key (keys %$query) { - # make this recursive in this case + # make this recursive in this case if ($key eq '$or') { $convert_q->($_) for @{ $query->{$key} }; } diff --git a/t/02-resource-query.t b/t/02-resource-query.t index ac6d1f5..f185ad6 100644 --- a/t/02-resource-query.t +++ b/t/02-resource-query.t @@ -45,11 +45,11 @@ isa_ok($graph, 'MongoDB::RDF::Graph'); my $cursor2 = $graph->find({ dc_title => 'my title' }); isa_ok($cursor2, 'MongoDB::RDF::Cursor'); cmp_ok($cursor2->count, '==', 1, 'one result'); - + # check that no index is used $cursor = $graph->find({ dc_title => 'my title' }); ok $cursor->explain->{cursor} =~ /BasicCursor/, 'no index used'; - + # add an index on dc_title $graph->ensure_index({ dc_title => 1}, { name => 'test_index', safe => 1 }); $cursor = $graph->find({ dc_title => 'my title' }); @@ -90,7 +90,7 @@ isa_ok($graph, 'MongoDB::RDF::Graph'); $cursor->reset; @subset = $cursor->limit(2)->skip(3)->all; cmp_ok(scalar(@subset), '==', 2, '2 results'); - + # or my $query = { '$or' => [ { dc_description => 1 }, diff --git a/t/06-util.t b/t/06-util.t index a893ebb..78943b1 100644 --- a/t/06-util.t +++ b/t/06-util.t @@ -43,6 +43,6 @@ my %canonicals = ( for (keys %canonicals) { my $expected = $canonicals{$_}; - cmp_ok( canonical_uri($_), 'eq', $expected); + cmp_ok( canonical_uri($_), 'eq', $expected); }