This file is indexed.

/usr/share/perl5/RDF/TrineX/Parser/RDFa.pm is in librdf-rdfa-parser-perl 1.097-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
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
package RDF::TrineX::Parser::RDFa;

use 5.010;
use strict qw(subs vars);

use RDF::Trine;
use RDF::RDFa::Parser;
use Scalar::Util qw(blessed reftype);

use base qw(RDF::Trine::Parser);

our (%file_extensions, %media_types, %parser_names, %format_uris);
our ($AUTHORITY, $VERSION);

%parser_names = (rdfa => __PACKAGE__);

BEGIN
{
	$AUTHORITY = 'cpan:TOBYINK';
	$VERSION   = '1.097';
	
	my @flavours = qw(XHTML HTML32 HTML4 HTML5 XHTML5 Atom DataRSS SVG XML OpenDocument);
	my @versions = qw(1.0 1.1);
	
	foreach my $flavour (@flavours)
	{
		foreach my $version (@versions)
		{
			no strict 'refs';
			no warnings;
			(my $digits = $version) =~ s/\D//g;
			my $class = sprintf 'RDF::TrineX::Parser::%s_RDFa%s', $flavour, $digits;
			$parser_names{ lc sprintf('%srdfa%s', $flavour, $digits) } = $class;
			$parser_names{ lc sprintf('%srdfa', $flavour) } = $class;
			$INC{ sprintf('RDF/TrineX/Parser/%s_RDFa%s', $flavour, $digits) } = $class;
			@{join q(::), $class, q(ISA)}       = __PACKAGE__;
			${join q(::), $class, q(AUTHORITY)} = $AUTHORITY;
			${join q(::), $class, q(VERSION)}   = $VERSION;
			*{join q(::), $class, q(new)} = sub
			{
				my ($klass, %opts) = @_;
				@opts{qw[flavour version]} = map {;lc} ($flavour, $version);
				new($klass, %opts);
			}
		}
	}
	
	%file_extensions = (
		html     => 'RDF::TrineX::Parser::HTML5_RDFa11',
		shtml    => 'RDF::TrineX::Parser::HTML5_RDFa11',
		htm      => 'RDF::TrineX::Parser::HTML5_RDFa11',
		xhtml    => 'RDF::TrineX::Parser::XHTML_RDFa11',
		xhtm     => 'RDF::TrineX::Parser::XHTML_RDFa11',
		svg      => 'RDF::TrineX::Parser::SVG_RDFa11',
		atom     => 'RDF::TrineX::Parser::Atom_RDFa11',
		(map {$_ => 'RDF::TrineX::Parser::OpenDocument_RDFa11';} qw[odt ods odp odg]),
		rdfa     => 'RDF::TrineX::Parser::XML_RDFa11',
	);
	
	%media_types = (
		'text/html'             => 'RDF::TrineX::Parser::HTML5_RDFa11',
		'application/xhtml+xml' => 'RDF::TrineX::Parser::XHTML_RDFa11',
		'image/svg'             => 'RDF::TrineX::Parser::SVG_RDFa11',
		'application/atom+xml'  => 'RDF::TrineX::Parser::Atom_RDFa11',	
		'application/vnd.oasis.opendocument.text'         => 'RDF::TrineX::Parser::OpenDocument_RDFa11',
		'application/vnd.oasis.opendocument.spreadsheet'  => 'RDF::TrineX::Parser::OpenDocument_RDFa11',
		'application/vnd.oasis.opendocument.presentation' => 'RDF::TrineX::Parser::OpenDocument_RDFa11',
		'application/vnd.oasis.opendocument.graphics'     => 'RDF::TrineX::Parser::OpenDocument_RDFa11',
	);
	
	%format_uris = (
		q<http://www.w3.org/ns/formats/RDFa> => 'RDF::TrineX::Parser::XHTML_RDFa10',
	);
	
	sub _merge_hashes
	{
		my ($src, $dest) = (shift, shift);
		$dest->{$_} //= $src->{$_} for keys %$src;
		goto \&_merge_hashes if @_;
	}
	
	_merge_hashes(
		\%parser_names    => \%RDF::Trine::Parser::parser_names,
		\%file_extensions => \%RDF::Trine::Parser::file_extensions,
		\%media_types     => \%RDF::Trine::Parser::media_types,
		\%format_uris     => \%RDF::Trine::Parser::format_uris,
	);
}

sub new
{
	my ($class, %opts) = @_;
	
	my $flavour      = lc(delete($opts{flavour})   // 'xhtml');
	my $version      = lc(delete($opts{version})   // '1.1');
	my $canonicalize = delete($opts{canonicalize}) // '';
	
	$flavour = 'xhtml' if lc($flavour) eq 'xhtml1';
	$flavour = 'opendocument-zip' if lc($flavour) eq 'opendocument';
	
	my $config  = RDF::RDFa::Parser::Config->new($flavour, $version, %opts);
	
	bless +{
		flavour      => $flavour,
		version      => $version,
		config       => $config,
		canonicalize => $canonicalize,
	} => $class;
}

sub rdfa_flavour { shift->{flavour} }
sub rdfa_version { shift->{version} }

sub parse
{
	my ($self, $base, $string, $handler) = @_;
	
	my $parser = RDF::RDFa::Parser->new(
		$string,
		$base,
		$self->{config},
	);
	
	return $self->__parser_handler($parser, $handler);
}

sub parse_url_into_model
{
	my ($proto, $url, $model, %args) = @_;
	
	my $context = delete $args{context};
	my $self    = blessed($proto) ? $proto : $proto->new(%args);
	
	my $parser = RDF::RDFa::Parser->new_from_url(
		$url,
		$self->{config},
	);
	
	my $handler = sub
	{
		my $st = shift;
		$st = RDF::Trine::Statement::Quad->new($st->nodes, $context)
			if $context;
		$model->add_statement($st);
	};
	
	$model->begin_bulk_ops;
	my $r = $self->__parser_handler($parser, $handler);
	$model->end_bulk_ops;
	return $r;
}

sub __parser_handler
{
	my ($self, $parser, $handler) = @_;
	
	$parser->set_callbacks({
		ontriple => sub {
			my ($p, $el, $st) = @_;
			if (reftype($handler) eq 'CODE')
			{
				if ($self->{canonicalize})
				{
					my $o = $st->object;
					if ($o->isa('RDF::Trine::Node::Literal') and $o->has_datatype)
					{
						my $dt    = $o->literal_datatype;
						my $canon = RDF::Trine::Node::Literal
							-> canonicalize_literal_value($o->literal_value, $dt, 1);
						
						$st->object(RDF::Trine::Node::Literal->new($canon, undef, $dt));
					}
				}
				$handler->($st);
			}
			return 1;
		}
	});
	
	$parser->consume;
}

__PACKAGE__
__END__

=head1 NAME

RDF::TrineX::Parser::RDFa - RDF::Trine::Parser-compatible interface for RDF::RDFa::Parser

=head1 DESCRIPTION

While RDF::RDFa::Parser is a good RDFa parser, its interface is a tad...
shall we say... crufty.

RDF::TrineX::Parser::RDFa provides a much nicer interface, and is a
subclass of L<RDF::Trine::Parser>, so you get super-polymorphic benefits.
Yay!

=head2 Class Method

=over

=item C<< parse_url_into_model($url, $model, %args) >>

As per the method of the same name in L<RDF::Trine::Parser>, this retrieves
the URL and parses it into a model.

Unlike L<RDF::Trine::Parser>, this method always assumes you're trying to
parse some variety of RDFa.

=back

=head2 Constructor

=over

=item C<< new(%options) >>

Constructs a new RDF::TrineX::Parser::RDFa parser.

The two important options are flavour (which defaults to 'xhtml') and
version (which defaults to '1.1'). Other options are documented in
L<RDF::RDFa::Parser::Config>.

Let's imagine that you want to parse RDFa 1.1 in HTML5, and you want
to also parse the C<role>, C<longdesc> and C<cite> attibutes (which are
not strictly part of RDFa, but nevertheless often interesting). Then
you'd use:

  my $parser = RDF::TrineX::Parser::RDFa->new(
    flavour        => 'html5',
    version        => '1.1',
    role_attr      => 1,
    longdesc_attr  => 1,
    cite_attr      => 1,
  );

=back

=head2 Object Methods

The following methods are supported, as documented in L<RDF::Trine::Parser>.

=over

=item C<< parse_into_model($base_uri, $data, $model [,context => $context]) >>

=item C<< parse($base_uri, $data, \&handler) >>

=item C<< parse_file_into_model($base_uri, $fh, $model [,context => $context]) >>

=item C<< parse_file($base_uri, $fh, \&handler) >>

=back

The following additional methods are supported:

=over

=item C<< rdfa_flavour >>

Returns the RDFa host language being used.

=item C<< rdfa_version >>

Returns the RDFa version number being used.

=back


=head2 Subclasses

The following subclasses of RDF::TrineX::Parser::RDFa exist:

=over

=item RDF::TrineX::Parser::XHTML_RDFa10

=item RDF::TrineX::Parser::HTML32_RDFa10

=item RDF::TrineX::Parser::HTML4_RDFa10

=item RDF::TrineX::Parser::HTML5_RDFa10

=item RDF::TrineX::Parser::XHTML5_RDFa10

=item RDF::TrineX::Parser::Atom_RDFa10

=item RDF::TrineX::Parser::DataRSS_RDFa10

=item RDF::TrineX::Parser::SVG_RDFa10

=item RDF::TrineX::Parser::XML_RDFa10

=item RDF::TrineX::Parser::OpenDocument_RDFa10

=item RDF::TrineX::Parser::XHTML_RDFa11

=item RDF::TrineX::Parser::HTML32_RDFa11

=item RDF::TrineX::Parser::HTML4_RDFa11

=item RDF::TrineX::Parser::HTML5_RDFa11

=item RDF::TrineX::Parser::XHTML5_RDFa11

=item RDF::TrineX::Parser::Atom_RDFa11

=item RDF::TrineX::Parser::DataRSS_RDFa11

=item RDF::TrineX::Parser::SVG_RDFa11

=item RDF::TrineX::Parser::XML_RDFa11

=item RDF::TrineX::Parser::OpenDocument_RDFa11

=back

By using these classes, you can skip the need to pass the 'flavour' and
'version' options to the constructor. For example:

  my $parser = RDF::TrineX::Parser::HTML5_RDFa11->new(
    role_attr      => 1,
    longdesc_attr  => 1,
    cite_attr      => 1,
  );

Note that these are classes, but they are not modules. You should not
attempt to load them with C<require> or C<use>.

=head1 SEE ALSO

L<RDF::Trine::Parser>,
L<RDF::RDFa::Parser>,
L<RDF::RDFa::Parser::Config>.

L<http://www.perlrdf.org/>, L<http://rdfa.info/>.

=head1 AUTHOR

Toby Inkster E<lt>tobyink@cpan.orgE<gt>.

=head1 COPYRIGHT AND LICENCE

Copyright 2012 Toby Inkster

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system 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.