Commits

Toby Inkster committed e29d223 Draft

non-named graphs

Comments (0)

Files changed (2)

lib/Vido/Dataset/Graph.pm

+package Vido::Dataset::Graph;
+
+use Vido::Syntax -role;
+BEGIN {
+	our $AUTHORITY = 'cpan:TOBYINK';
+	our $VERSION   = '0.001';
+}
+
+use RDF::TrineX::Functions qw( parse );
+
+lazy_builder source     => ( result_type => 'object' );
+
+with qw(Vido::Dataset::HasPrimarySource);
+
+has graph => (
+	is         => read_only,
+	isa        => class_type('RDF::Trine::Model'),
+	lazy_build => true,
+);
+
+sub extra_options
+{
+	qw();
+}
+
+sub _build_graph {
+	my $self   = shift;
+	my $source = $self->source;
+	
+	if (does($source, 'Vido::Dataset::FormattedContent')
+	and does($source, 'Vido::Dataset::ReadFileHandle'))
+	{
+		return parse(
+			$source->content . "\n\n",
+			as    => $source->media_type,
+			base  => $source->identifier,
+			$self->extra_options($source),
+		);
+	}
+
+	if (does($source, 'Vido::Dataset::FormattedContent')
+	and $source->can('content'))
+	{
+		return parse(
+			$source->content,
+			as    => $source->media_type,
+			base  => $source->identifier,
+			$self->extra_options($source),
+		);
+	}
+	
+	Vido::Exception::UnknownDataset->throw(
+		"do not know how to build a graph from source ".$source->dataset_string,
+	);
+}

lib/Vido/Dataset/NamedGraph.pm

 use RDF::TrineX::Functions qw( parse );
 
 lazy_builder graph_name => ( result_type => 'string' );
-lazy_builder source     => ( result_type => 'object' );
 
-with qw(Vido::Dataset::HasPrimarySource);
+with qw(Vido::Dataset::Graph);
 
 has graph_name => (
 	is         => read_only,
 	lazy_build => true,
 );
 
-has graph => (
-	is         => read_only,
-	isa        => class_type('RDF::Trine::Model'),
-	lazy_build => true,
-);
+around extra_options => sub
+{
+	my ($orig, $self, $source) = @_;
+	graph => $self->graph_name;
+};
 
-sub _build_graph {
-	my $self   = shift;
-	my $source = $self->source;
-	
-	if (does($source, 'Vido::Dataset::FormattedContent')
-	and does($source, 'Vido::Dataset::ReadFileHandle'))
-	{
-		return parse(
-			$source->content . "\n\n",
-			as    => $source->media_type,
-			base  => $source->identifier,
-			graph => $self->graph_name,
-		);
-	}
-
-	if (does($source, 'Vido::Dataset::FormattedContent')
-	and $source->can('content'))
-	{
-		return parse(
-			$source->content,
-			as    => $source->media_type,
-			base  => $source->identifier,
-			graph => $self->graph_name,
-		);
-	}
-	
-	Vido::Exception::UnknownDataset->throw(
-		"do not know how to build a named graph from source $source",
-	);
-}