/usr/share/perl5/HTML/Microformats/Mixin/RDF.pm is in libhtml-microformats-perl 0.104-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | package HTML::Microformats::Mixin::RDF;
use common::sense;
use 5.010;
use Encode qw(encode);
use RDF::Trine;
use Scalar::Util qw();
use Object::AUTHORITY;
BEGIN {
$HTML::Microformats::Mixin::RDF::AUTHORITY = 'cpan:TOBYINK';
$HTML::Microformats::Mixin::RDF::VERSION = '0.104';
}
sub _simple_rdf
{
my $self = shift;
my $model = shift;
my $id = $self->id(1);
return if $self->{'already_added'}->{"$model"};
$self->{'already_added'}->{"$model"}++;
foreach my $rdftype (@{ $self->format_signature->{'rdf:type'} })
{
$model->add_statement(RDF::Trine::Statement->new(
$id,
RDF::Trine::Node::Resource->new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
RDF::Trine::Node::Resource->new($rdftype),
));
}
KEY: foreach my $key (sort keys %{ $self->format_signature->{'rdf:property'} })
{
my $rdf = $self->format_signature->{'rdf:property'}->{$key};
next KEY unless defined $self->data->{$key};
my $vals = $self->data->{$key};
$vals = [$vals] unless ref $vals eq 'ARRAY';
foreach my $val (@$vals)
{
my $can_id = Scalar::Util::blessed($val) && $val->can('id');
my $seems_bnode = ($val =~ /^_:\S+$/);
my $seems_uri = ($val =~ /^[a-z0-9\.\+\-]{1,20}:\S+$/);
if ((defined $rdf->{'resource'}||defined $rdf->{'rev'})
&& ($can_id || $seems_uri || $seems_bnode))
{
my $val_node = undef;
if ($can_id)
{
$val_node = $val->id(1);
}
else
{
$val_node = ($val =~ /^_:(.*)$/) ?
RDF::Trine::Node::Blank->new($1) :
RDF::Trine::Node::Resource->new($val);
}
foreach my $prop (@{ $rdf->{'resource'} })
{
$model->add_statement(RDF::Trine::Statement->new(
$id,
RDF::Trine::Node::Resource->new($prop),
$val_node
));
}
foreach my $prop (@{ $rdf->{'rev'} })
{
$model->add_statement(RDF::Trine::Statement->new(
$val_node,
RDF::Trine::Node::Resource->new($prop),
$id
));
}
if ($can_id and Scalar::Util::blessed($val) and $val->can('add_to_model'))
{
$val->add_to_model($model);
}
}
elsif (defined $rdf->{'literal'} and !$can_id)
{
foreach my $prop (@{ $rdf->{'literal'} })
{
$model->add_statement(RDF::Trine::Statement->new(
$id,
RDF::Trine::Node::Resource->new($prop),
$self->_make_literal($val, $rdf->{'literal_datatype'}),
));
}
}
}
}
}
sub _make_literal
{
my ($self, $val, $dt) = @_;
if (Scalar::Util::blessed($val)
and $val->can('to_string')
and $val->can('datatype'))
{
return RDF::Trine::Node::Literal->new(
encode('utf8', $val->to_string), undef, $val->datatype);
}
elsif (Scalar::Util::blessed($val)
and $val->can('to_string')
and $val->can('lang'))
{
return RDF::Trine::Node::Literal->new(
encode('utf8', $val->to_string), $val->lang);
}
else
{
if (defined $dt and length $dt and $dt !~ /:/)
{
$dt = 'http://www.w3.org/2001/XMLSchema#'.$dt;
}
if ($dt eq 'http://www.w3.org/2001/XMLSchema#integer')
{
$val = int $val;
}
return RDF::Trine::Node::Literal->new(encode('utf8', $val), undef, $dt);
}
}
1;
__END__
=head1 NAME
HTML::Microformats::Mixin::RDF - RDF output mixin
=head1 DESCRIPTION
HTML::Microformats::Mixin::RDF provides some utility code for microformat
modules to more easily output RDF. It includes methods C<_simple_rdf> which
takes an RDF::Trine model as a parameter and adds some basic triples to it
based on the object's format signature; and C<_make_literal> taking either
a string plus datatype as parameters, or any of the HTML::Microformats::Datatype
objects, returning an RDF::Trine::Node::Literal.
HTML::Microformats::Format inherits from this module, so by extension, all the
microformat modules do too.
=head1 BUGS
Please report any bugs to L<http://rt.cpan.org/>.
=head1 SEE ALSO
L<HTML::Microformats>
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT
Copyright 2008-2010 Toby Inkster
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=head1 DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
=cut
|