Skip to content

Instantly share code, notes, and snippets.

@nichtich
Created September 6, 2011 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nichtich/1197502 to your computer and use it in GitHub Desktop.
Save nichtich/1197502 to your computer and use it in GitHub Desktop.
RDF::Trine::Exporter
package RDF::Trine::Exporter;
use strict;
use warnings;
sub serialize_iterator_to_file {
my ($self, $file, $iterator) = @_;
if ( $self->can('_iterator_to_file') ) {
$self->_iterator_to_file( $file, $iterator );
} elsif ( $self->can('_model_to_file') ) {
my $model = RDF::Trine::Model->temporary_model;
$model->begin_bulk_ops;
while (my $stm = $iterator->next) {
$model->add_statement( $stm );
}
$model->end_bulk_ops;
$self->_model_to_file( $file, $model );
} else {
croak __PACKAGE__ . ' must implement at least one serialization method';
}
}
sub serialize_model_to_file {
my ($self, $file, $model) = @_;
if ( $self->can('_model_to_file') ) {
$self->_model_to_file( $file, $model );
} elsif ( $self->can('_iterator_to_file') ) {
$self->_iterator_to_file( $file, $model->as_stream );
} else {
croak __PACKAGE__ . ' must implement at least one serialization method';
}
}
=head1 DESCRIPTION
Derived classes must implement at least C<_model_to_file> or C<_iterator_to_file>.
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment