line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Trine::Parser::RDFa |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Trine::Parser::RDFa - RDFa Parser |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Trine::Parser::RDFa version 1.017 |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use RDF::Trine::Parser; |
15
|
|
|
|
|
|
|
my $parser = RDF::Trine::Parser->new( 'rdfa' ); |
16
|
|
|
|
|
|
|
$parser->parse_into_model( $base_uri, $data, $model ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
... |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 METHODS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
25
|
|
|
|
|
|
|
L<RDF::Trine::Parser> class. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over 4 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package RDF::Trine::Parser::RDFa; |
32
|
|
|
|
|
|
|
|
33
|
68
|
|
|
68
|
|
453
|
use strict; |
|
68
|
|
|
|
|
161
|
|
|
68
|
|
|
|
|
1776
|
|
34
|
68
|
|
|
68
|
|
334
|
use warnings; |
|
68
|
|
|
|
|
188
|
|
|
68
|
|
|
|
|
1664
|
|
35
|
|
|
|
|
|
|
|
36
|
68
|
|
|
68
|
|
335
|
use base qw(RDF::Trine::Parser); |
|
68
|
|
|
|
|
152
|
|
|
68
|
|
|
|
|
6124
|
|
37
|
|
|
|
|
|
|
|
38
|
68
|
|
|
68
|
|
441
|
use Carp; |
|
68
|
|
|
|
|
151
|
|
|
68
|
|
|
|
|
4624
|
|
39
|
68
|
|
|
68
|
|
433
|
use Data::Dumper; |
|
68
|
|
|
|
|
163
|
|
|
68
|
|
|
|
|
2393
|
|
40
|
68
|
|
|
68
|
|
362
|
use Log::Log4perl; |
|
68
|
|
|
|
|
167
|
|
|
68
|
|
|
|
|
536
|
|
41
|
68
|
|
|
68
|
|
3807
|
use Scalar::Util qw(blessed reftype); |
|
68
|
|
|
|
|
154
|
|
|
68
|
|
|
|
|
3130
|
|
42
|
68
|
|
|
68
|
|
410
|
use Module::Load::Conditional qw[can_load]; |
|
68
|
|
|
|
|
154
|
|
|
68
|
|
|
|
|
2768
|
|
43
|
|
|
|
|
|
|
|
44
|
68
|
|
|
68
|
|
407
|
use RDF::Trine qw(literal); |
|
68
|
|
|
|
|
172
|
|
|
68
|
|
|
|
|
2255
|
|
45
|
68
|
|
|
68
|
|
390
|
use RDF::Trine::Node; |
|
68
|
|
|
|
|
159
|
|
|
68
|
|
|
|
|
2040
|
|
46
|
68
|
|
|
68
|
|
361
|
use RDF::Trine::Statement; |
|
68
|
|
|
|
|
143
|
|
|
68
|
|
|
|
|
1484
|
|
47
|
68
|
|
|
68
|
|
342
|
use RDF::Trine::Error qw(:try); |
|
68
|
|
|
|
|
154
|
|
|
68
|
|
|
|
|
391
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
###################################################################### |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
our ($VERSION, $HAVE_RDFA_PARSER); |
52
|
|
|
|
|
|
|
BEGIN { |
53
|
68
|
|
|
68
|
|
14634
|
$VERSION = '1.017'; |
54
|
68
|
50
|
|
|
|
414
|
if (can_load( modules => { 'RDF::RDFa::Parser' => 0.30 })) { |
55
|
0
|
|
|
|
|
|
$HAVE_RDFA_PARSER = 1; |
56
|
0
|
|
|
|
|
|
$RDF::Trine::Parser::parser_names{ 'rdfa' } = __PACKAGE__; |
57
|
0
|
|
|
|
|
|
foreach my $ext (qw(html xhtml htm)) { |
58
|
0
|
|
|
|
|
|
$RDF::Trine::Parser::file_extensions{ $ext } = __PACKAGE__; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
my $class = __PACKAGE__; |
61
|
0
|
|
|
|
|
|
$RDF::Trine::Parser::canonical_media_types{ $class } = 'application/xhtml+xml'; |
62
|
0
|
|
|
|
|
|
foreach my $type (qw(application/xhtml+xml text/html)) { |
63
|
0
|
|
|
|
|
|
$RDF::Trine::Parser::media_types{ $type } = __PACKAGE__; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
$RDF::Trine::Parser::format_uris{ 'http://www.w3.org/ns/formats/RDFa' } = __PACKAGE__; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
###################################################################### |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item C<< new ( options => \%options ) >> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Returns a new RDFa parser object with the supplied options. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub new { |
78
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
79
|
0
|
|
|
|
|
|
my %args = @_; |
80
|
0
|
0
|
|
|
|
|
unless ($HAVE_RDFA_PARSER) { |
81
|
0
|
|
|
|
|
|
throw RDF::Trine::Error -text => "Failed to load RDF::RDFa::Parser >= 0.30"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $self = bless( { %args }, $class); |
85
|
0
|
|
|
|
|
|
return $self; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item C<< parse_into_model ( $base_uri, $data, $model [, context => $context] ) >> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Parses the bytes in C<< $data >>, using the given C<< $base_uri >>. For each RDF |
91
|
|
|
|
|
|
|
statement parsed, will call C<< $model->add_statement( $statement ) >>. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item C<< parse ( $base_uri, $rdf, \&handler ) >> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub parse { |
100
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
101
|
0
|
|
|
|
|
|
my $base = shift; |
102
|
0
|
|
|
|
|
|
my $string = shift; |
103
|
0
|
|
|
|
|
|
my $handler = shift; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $parser = RDF::RDFa::Parser->new($string, $base, $self->{'options'}); |
106
|
|
|
|
|
|
|
$parser->set_callbacks({ |
107
|
|
|
|
|
|
|
ontriple => sub { |
108
|
0
|
|
|
0
|
|
|
my ($p, $el, $st) = @_; |
109
|
0
|
0
|
|
|
|
|
if (reftype($handler) eq 'CODE') { |
110
|
0
|
0
|
|
|
|
|
if ($self->{canonicalize}) { |
111
|
0
|
|
|
|
|
|
my $o = $st->object; |
112
|
0
|
0
|
0
|
|
|
|
if ($o->isa('RDF::Trine::Node::Literal') and $o->has_datatype) { |
113
|
0
|
|
|
|
|
|
my $value = $o->literal_value; |
114
|
0
|
|
|
|
|
|
my $dt = $o->literal_datatype; |
115
|
0
|
|
|
|
|
|
my $canon = RDF::Trine::Node::Literal->canonicalize_literal_value( $value, $dt, 1 ); |
116
|
0
|
|
|
|
|
|
$o = literal( $canon, undef, $dt ); |
117
|
0
|
|
|
|
|
|
$st->object( $o ); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
0
|
|
|
|
|
|
$handler->( $st ); |
121
|
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
|
return 1; |
123
|
|
|
|
|
|
|
} |
124
|
0
|
|
|
|
|
|
}); |
125
|
0
|
|
|
|
|
|
$parser->consume; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=back |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 BUGS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Please report any bugs or feature requests to through the GitHub web interface |
138
|
|
|
|
|
|
|
at L<https://github.com/kasei/perlrdf/issues>. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHOR |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Gregory Todd Williams C<< <gwilliams@cpan.org> >> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 COPYRIGHT |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Copyright (c) 2006-2012 Gregory Todd Williams. This |
147
|
|
|
|
|
|
|
program is free software; you can redistribute it and/or modify it under |
148
|
|
|
|
|
|
|
the same terms as Perl itself. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |