Attean
view release on metacpan or search on metacpan
lib/AtteanX/Serializer/RDFXML.pm view on Meta::CPAN
=head1 NAME
AtteanX::Serializer::RDFXML - RDF/XML Serializer
=head1 VERSION
This document describes AtteanX::Serializer::RDFXML version 0.038
=head1 SYNOPSIS
use Attean;
my $s = Attean->get_serializer('RDFXML')->new();
$s->serialize_iter_to_io( $fh, $iter );
=head1 DESCRIPTION
...
=head1 ATTRIBUTES
=over 4
=item C<< canonical_media_type >>
=item C<< scoped_namespaces >>
=item C<< file_extensions >>
=item C<< file_extensions >>
=item C<< blank_nodes >>
=back
=head1 METHODS
=over 4
=cut
use v5.14;
use warnings;
package AtteanX::Serializer::RDFXML 0.038 {
use Moo;
use Types::Standard qw(Bool HashRef ArrayRef HashRef Str Maybe InstanceOf ConsumerOf);
use Encode qw(encode);
use Scalar::Util qw(blessed);
use Attean::API::Iterator;
use Attean::ListIterator;
use List::Util qw(any);
use namespace::clean;
has 'canonical_media_type' => (is => 'ro', isa => Str, init_arg => undef, default => 'application/rdf+xml');
has '_rev' => (is => 'rw', isa => HashRef, init_arg => undef, default => sub { +{} });
has 'scoped_namespaces' => (is => 'rw', init_arg => undef);
has 'blank_nodes' => (is => 'ro', isa => HashRef[ConsumerOf['Attean::API::Blank']], default => sub { +{} });
=item C<< file_extensions >>
Returns a list of file extensions associated with the serialized format.
=cut
sub file_extensions { return [qw(rdf xml)] }
=item C<< media_types >>
Returns a list of media types that identify the format produced by this serializer.
=cut
sub media_types {
return [qw(application/rdf+xml)];
}
=item C<< serialize_iter_to_io( $fh, $iterator ) >>
Serializes the L<Attean::API::Triple> objects from C<< $iterator >> to the
L<IO::Handle> object C<< $fh >> (which SHOULD be open with the UTF-8 encoding).
=cut
sub serialize_iter_to_io {
my $self = shift;
my $io = shift;
my $iter = shift;
my $ns = $self->_top_xmlns();
my $base_uri = '';
if ($self->{base_uri}) {
$base_uri = "xml:base=\"$self->{base_uri}\" ";
}
print {$io} qq[<?xml version="1.0" encoding="utf-8"?>\n<rdf:RDF ${base_uri}xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"$ns>\n];
my $st = $iter->next;
my @statements;
push(@statements, $st) if blessed($st);
while (@statements) {
my $st = shift(@statements);
my @samesubj;
push(@samesubj, $st);
my $subj = $st->subject;
while (my $row = $iter->next) {
if ($row->subject->equals( $subj )) {
push(@samesubj, $row);
} else {
push(@statements, $row);
last;
}
}
print {$io} $self->_statements_same_subject_as_string( @samesubj );
}
print {$io} qq[</rdf:RDF>\n];
return;
( run in 1.039 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )