/usr/share/perl5/HTML/Microformats/Format/hReview.pm is in libhtml-microformats-perl 0.105-4.
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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | =head1 NAME
HTML::Microformats::Format::hReview - the hReview and xFolk microformats
=head1 SYNOPSIS
use HTML::Microformats::DocumentContext;
use HTML::Microformats::Format::hReview;
my $context = HTML::Microformats::DocumentContext->new($dom, $uri);
my @reviews = HTML::Microformats::Format::hReview->extract_all(
$dom->documentElement, $context);
foreach my $review (@reviews)
{
print $review->get_reviewer->get_fn . "\n";
}
=head1 DESCRIPTION
HTML::Microformats::Format::hReview inherits from HTML::Microformats::Format. See the
base class definition for a description of property getter/setter methods,
constructors, etc.
=cut
package HTML::Microformats::Format::hReview;
use base qw(HTML::Microformats::Format HTML::Microformats::Mixin::Parser);
use strict qw(subs vars); no warnings;
use 5.010;
use HTML::Microformats::Utilities qw(stringify searchClass);
use HTML::Microformats::Format::hReview::rating;
use Object::AUTHORITY;
BEGIN {
$HTML::Microformats::Format::hReview::AUTHORITY = 'cpan:TOBYINK';
$HTML::Microformats::Format::hReview::VERSION = '0.105';
}
sub new
{
my ($class, $element, $context, %options) = @_;
my $cache = $context->cache;
return $cache->get($context, $element, $class)
if defined $cache && $cache->get($context, $element, $class);
my $self = {
'element' => $element ,
'context' => $context ,
'cache' => $cache ,
'id' => $context->make_bnode($element) ,
'id.holder' => $context->make_bnode ,
};
bless $self, $class;
my $clone = $element->cloneNode(1);
$self->_expand_patterns($clone);
$self->_xfolk_stuff($clone);
$self->_simple_parse($clone);
$self->{'DATA'}->{'version'} ||= '0.3'
if $element->getAttribute('class') =~ /\b(hreview)\b/;
##TODO post-0.001
# If no "reviewer" is found inside the hReview, parsers should look
# outside the hReview, in the context of the page, for the "reviewer".
# If there is no "reviewer" outside either, then parsers should use the
# author defined by the containing document language, e.g. for HTML
# documents, the <address> contact info for the page (which is ideally
# marked up as an hCard as well)
$self->_fallback_item($clone)->_auto_detect_type;
$self->{'DATA'}->{'rating'} =
[ HTML::Microformats::Format::hReview::rating->extract_all($clone, $context) ];
$cache->set($context, $element, $class, $self)
if defined $cache;
return $self;
}
sub _xfolk_stuff
{
my ($self, $element) = @_;
# Handle xFolk.
if ($element->getAttribute('class') =~ /\b(xfolkentry)\b/)
{
my @tl = searchClass('taggedlink', $element);
return unless @tl;
my ($item_url, $item_img);
if ($tl[0]->localname eq 'a' || $tl[0]->localname eq 'area')
{ $item_url = $self->context->uri($tl[0]->getAttribute('href')); }
elsif ($tl[0]->localname eq 'img')
{ $item_img = $self->context->uri($tl[0]->getAttribute('src')); }
elsif ($tl[0]->localname eq 'object')
{ $item_url = $self->context->uri($tl[0]->getAttribute('data')); }
$self->{'DATA'}->{'item'}->{'fn'} = stringify($tl[0], 'value');
$self->{'DATA'}->{'item'}->{'url'} = [$item_url];
$self->{'DATA'}->{'item'}->{'photo'} = [$item_img];
$self->{'DATA'}->{'type'} = 'url';
}
return $self;
}
sub _fallback_item
{
my ($self, $element) = @_;
my @items = searchClass('item', $element);
return $self unless @items;
my $item = $items[0];
my @fns = searchClass('fn', $item);
unless (@fns)
{
my ($item_url, $item_img);
if ($item->localname eq 'a' || $item->localname eq 'area')
{ $item_url = $self->context->uri($item->getAttribute('href')); }
elsif ($item->localname eq 'img')
{ $item_img = $self->context->uri($item->getAttribute('src')); }
elsif ($item->localname eq 'object')
{ $item_url = $self->context->uri($item->getAttribute('data')); }
$self->{'DATA'}->{'item'}->{'fn'} = stringify($item, 'value');
$self->{'DATA'}->{'item'}->{'url'} = [$item_url];
$self->{'DATA'}->{'item'}->{'photo'} = [$item_img];
return $self;
}
$self->{'DATA'}->{'item'}->{'fn'} = stringify($fns[0], 'value');
foreach my $property (qw(url photo))
{
my @urls = searchClass($property, $item);
foreach my $url (@urls)
{
if ($item->localname eq 'a' || $item->localname eq 'area')
{
push @{$self->{'DATA'}->{'item'}->{$property}},
$self->context->uri($item->getAttribute('href'));
}
elsif ($item->localname eq 'img')
{
push @{$self->{'DATA'}->{'item'}->{$property}},
$self->context->uri($item->getAttribute('src'));
}
elsif ($item->localname eq 'object')
{
push @{$self->{'DATA'}->{'item'}->{$property}},
$self->context->uri($item->getAttribute('data'));
}
}
}
return $self;
}
sub _auto_detect_type
{
my $self = shift;
if ($self->_isa($self->{'DATA'}->{'item'}, 'HTML::Microformats::Format::hCard')
&& !defined $self->{'DATA'}->{'type'})
{
my $item_type = $self->{'DATA'}->{'item'}->get_kind . '';
if (lc $item_type eq 'individual')
{
$self->{'DATA'}->{'type'} = 'person';
}
elsif ($item_type =~ m'^(group|org)$'i)
{
$self->{'DATA'}->{'type'} = 'business';
}
elsif (lc $item_type eq 'location')
{
$self->{'DATA'}->{'type'} = 'place';
}
else
{
$self->{'DATA'}->{'type'} = $item_type;
}
}
elsif ($self->_isa($self->{'DATA'}->{'item'}, 'HTML::Microformats::Format::hAudio')
&& !defined $self->{'DATA'}->{'type'})
{
$self->{'DATA'}->{'type'} = 'product';
}
elsif ($self->_isa($self->{'DATA'}->{'item'}, 'HTML::Microformats::Format::hEvent')
&& !defined $self->{'DATA'}->{'type'})
{
$self->{'DATA'}->{'type'} = 'event';
}
return $self;
}
sub format_signature
{
my $self = shift;
my $rev = 'http://www.purl.org/stuff/rev#';
my $hreview = 'http://ontologi.es/hreview#';
my $rv = {
'root' => [qw(hreview xfolkentry)],
'classes' => [
['reviewer', 'M*', {'embedded'=>'hCard !person'}],
# Note: for item we try hAudio first, as it will likely contain an hCard,
# Then hEvent, as it may contain an hCard. Lastly try hCard, as it's unlikely
# to contain anything else.
['item', 'm1', {'embedded'=>'hProduct hAudio hEvent hCard'}], # lowercase 'm' = don't try plain string.
['version', 'n?'],
['summary', '1'],
['type', '?'],
['bookmark', 'ru?', {'use-key'=>'permalink'}],
['description', 'H*'],
['dtreviewed', 'd?'],
['rating', '*#'],
],
'options' => {
'rel-tag' => 'tag',
'rel-license' => 'license',
},
'rdf:type' => ["${rev}Review"] ,
'rdf:property' => {
'description' => { 'literal' => ["${rev}text"] },
'type' => { 'literal' => ["${rev}type"] },
'summary' => { 'literal' => ["${rev}title", "http://www.w3.org/2000/01/rdf-schema#label"] },
'rating' => { 'resource' => ["${hreview}rating"] },
'version' => { 'literal' => ["${hreview}version"], 'literal_datatype'=>'decimal' },
'tag' => { 'resource' => ['http://www.holygoat.co.uk/owl/redwood/0.1/tags/taggedWithTag'] },
'license' => { 'resource' => ["http://www.iana.org/assignments/relation/license", "http://creativecommons.org/ns#license"] },
'permalink' => { 'resource' => ["http://www.iana.org/assignments/relation/self"] },
'dtreviewed' => { 'literal' => ["http://purl.org/dc/terms/created"] },
},
};
return $rv;
}
sub add_to_model
{
my $self = shift;
my $model = shift;
my $rev = 'http://www.purl.org/stuff/rev#';
$self->_simple_rdf($model);
foreach my $reviewer (@{$self->{'DATA'}->{'reviewer'}})
{
if ($self->_isa($reviewer, 'HTML::Microformats::Format::hCard'))
{
$model->add_statement(RDF::Trine::Statement->new(
$self->id(1),
RDF::Trine::Node::Resource->new("${rev}reviewer"),
$reviewer->id(1, 'holder'),
));
}
}
if ($self->_isa($self->{'DATA'}->{'item'}, 'HTML::Microformats::Format::hCard'))
{
$model->add_statement(RDF::Trine::Statement->new(
$self->{'DATA'}->{'item'}->id(1, 'holder'),
RDF::Trine::Node::Resource->new("${rev}hasReview"),
$self->id(1),
));
}
elsif ($self->_isa($self->{'DATA'}->{'item'}, 'HTML::Microformats::Format::hEvent'))
{
$model->add_statement(RDF::Trine::Statement->new(
$self->{'DATA'}->{'item'}->id(1, 'event'),
RDF::Trine::Node::Resource->new("${rev}hasReview"),
$self->id(1),
));
}
elsif ($self->_isa($self->{'DATA'}->{'item'}, 'HTML::Microformats::Format::hAudio'))
{
$model->add_statement(RDF::Trine::Statement->new(
$self->{'DATA'}->{'item'}->id(1),
RDF::Trine::Node::Resource->new("${rev}hasReview"),
$self->id(1),
));
}
else
{
$model->add_statement(RDF::Trine::Statement->new(
$self->id(1, 'item'),
RDF::Trine::Node::Resource->new("${rev}hasReview"),
$self->id(1),
));
$model->add_statement(RDF::Trine::Statement->new(
$self->id(1, 'item'),
RDF::Trine::Node::Resource->new("http://www.w3.org/2000/01/rdf-schema#label"),
$self->_make_literal($self->{'DATA'}->{'item'}->{'fn'}),
))
if defined $self->{'DATA'}->{'item'}->{'fn'};
foreach my $url (@{$self->{'DATA'}->{'item'}->{'url'}})
{
$model->add_statement(RDF::Trine::Statement->new(
$self->id(1, 'item'),
RDF::Trine::Node::Resource->new("http://xmlns.com/foaf/0.1/page"),
RDF::Trine::Node::Resource->new($url),
));
}
foreach my $photo (@{$self->{'DATA'}->{'item'}->{'photo'}})
{
$model->add_statement(RDF::Trine::Statement->new(
$self->id(1, 'item'),
RDF::Trine::Node::Resource->new("http://xmlns.com/foaf/0.1/depiction"),
RDF::Trine::Node::Resource->new($photo),
));
}
}
foreach my $rating (@{$self->{'DATA'}->{'rating'}})
{
if ($rating->get_best==5.0 && $rating->get_worst==0.0)
{
$model->add_statement(RDF::Trine::Statement->new(
$self->id(1),
RDF::Trine::Node::Resource->new("${rev}rating"),
$self->_make_literal($rating->get_value, 'decimal'),
));
}
}
return $self;
}
sub profiles
{
my $class = shift;
return qw(http://microformats.org/profile/hreview
http://ufs.cc/x/hreview
http://microformats.org/profile/xfolk
http://ufs.cc/x/xfolk
http://www.purl.org/stuff/rev#
http://microformats.org/wiki/xfolk-profile);
}
1;
=head1 MICROFORMAT
HTML::Microformats::Format::hReview supports hReview 0.3 and xFolk as described at
L<http://microformats.org/wiki/hreview> and L<http://microformats.org/wiki/xfolk>,
with the following differences:
=over 4
=item * hAudio
hAudio microformats can be used as the reviewed item.
(At the time of writing this documentation however, HTML::Microformats didn't
support hAudio!)
=item * Jumbled-up
Support for xFolk and hReview are bundled together, so properties are usually
supported in both, even if only defined by one microformat spec. (e.g. reviewer
is defined by hReview, but this module supports it in xFolk entries.)
=back
=head1 RDF OUTPUT
L<http://www.purl.org/stuff/rev#>, L<http://ontologi.es/hreview#>.
=head1 BUGS
Please report any bugs to L<http://rt.cpan.org/>.
Known limitations:
=over 4
=item * If no "reviewer" is found inside the hReview, parsers should look
outside the hReview, in the context of the page, for the "reviewer".
If there is no "reviewer" outside either, then parsers should use the
author defined by the containing document language, e.g. for HTML
documents, the E<lt>addressE<gt> contact info for the page (which is ideally
marked up as an hCard as well).
=back
=head1 SEE ALSO
L<HTML::Microformats::Format>,
L<HTML::Microformats>.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
Copyright 2008-2012 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
|