AtteanX-Serializer-RDFa
view release on metacpan or search on metacpan
lib/AtteanX/Serializer/RDFa.pm view on Meta::CPAN
package AtteanX::Serializer::RDFa;
use 5.010001;
use strict;
use warnings;
our $AUTHORITY = 'cpan:KJETILK';
our $VERSION = '0.110';
use Moo;
use Types::Standard qw(Str Maybe HashRef ConsumerOf);
use Encode qw(encode);
use Scalar::Util qw(blessed);
use Attean;
use Attean::ListIterator;
use namespace::clean;
use Attean::RDF qw(iri);
use RDF::RDFa::Generator;
has 'canonical_media_type' => (is => 'ro', isa => Str, init_arg => undef, default => 'application/xhtml+xml');
with 'Attean::API::TripleSerializer';
with 'Attean::API::AbbreviatingSerializer';
has 'style' => (is => 'ro', isa => Maybe[Str]); # TODO: might be improved with OptList?
has 'generator_options' => (is => 'ro', isa => HashRef, default => sub { return {} });
has _opts => (is => 'rw', isa => HashRef, lazy => 1, builder => '_build_opts');
sub _build_opts {
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;
( run in 0.548 second using v1.01-cache-2.11-cpan-39bf76dae61 )