Created
September 6, 2011 13:15
-
-
Save nichtich/1197502 to your computer and use it in GitHub Desktop.
RDF::Trine::Exporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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