AtteanX-Serializer-RDFa
view release on metacpan or search on metacpan
lib/AtteanX/Serializer/RDFa.pm view on Meta::CPAN
my $self = shift;
my $base = defined($self->base) ? $self->base->abs : undef;
my %opts = (
style => $self->style,
namespacemap => $self->namespaces,
base => $base
);
return \%opts;
}
sub media_types {
return [qw(application/xhtml+xml text/html)];
}
sub file_extensions { return [qw(html xhtml)] };
sub _make_document {
my ($self, $iter) = @_;
my $store = Attean->get_store('Memory')->new();
$store->add_iter($iter->as_quads(iri('http://graph.invalid/')));
my $model = Attean::QuadModel->new( store => $store );
return RDF::RDFa::Generator->new(%{$self->_opts})->create_document($model, %{$self->generator_options});
}
sub serialize_iter_to_io {
my ($self, $io, $iter) = @_;
my $document = $self->_make_document($iter);
return $document->toFH($io);
}
sub serialize_iter_to_bytes {
my ($self, $iter) = @_;
my $document = $self->_make_document($iter);
return $document->toString;
}
1;
__END__
=pod
=encoding utf-8
=head1 NAME
AtteanX::Serializer::RDFa - RDFa Serializer for Attean
=head1 SYNOPSIS
use Attean;
use Attean::RDF qw(iri);
use URI::NamespaceMap;
my $ser = Attean->get_serializer('RDFa')->new;
my $string = $ser->serialize_iter_to_bytes($iter);
my $ns = URI::NamespaceMap->new( { ex => iri('http://example.org/') });
$ns->guess_and_add('foaf');
my $note = RDF::RDFa::Generator::HTML::Pretty::Note->new(iri('http://example.org/foo'), 'This is a Note');
my $ser = Attean->get_serializer('RDFa')->new(base => iri('http://example.org/'),
namespaces => $ns,
style => 'HTML::Pretty',
generator_options => { notes => [$note]});
$ser->serialize_iter_to_io($fh, $iter);
=head1 DESCRIPTION
This module can be used to serialize RDFa with several different
styles. It is implemented using L<Attean> to wrap around
L<RDF::RDFa::Generator>, which does the heavy lifting. It composes
L<Attean::API::TripleSerializer> and
L<Attean::API::AbbreviatingSerializer>.
=head1 METHODS AND ATTRIBUTES
=head2 Attributes
In addition to attributes required by L<Attean::API::TripleSerializer>
that should not be a concern to users, the following attributes can be
set:
=over
=item C<< style >>
This attribute sets the serialization style used by
L<RDF::RDFa::Generator>, see its documentation for details.
=item C<< namespaces >>
A HASH reference mapping prefix strings to L<URI::NamespaceMap>
objects. L<RDF::RDFa::Generator> will help manage this map, see its
documentation for details.
=item C<< base >>
An L<Attean::API::IRI> object representing the base against which
relative IRIs in the serialized data should be resolved. There is some
support in L<RDF::RDFa::Generator>, but currently, it doesn't do much.
=item C<< generator_options >>
A HASH reference that will be passed as options to
L<RDF::RDFa::Generator>'s C<create_document> method. This is typically
options that are specific to different styles, see synopsis for
example.
=back
=head2 Methods
This implements four required methods:
=over
( run in 2.248 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )