RDF/Trine/Parser/RDFa.pm

filter: Statementstmt 54.0% 40 / 74 Branchbran 10.0% 1 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.2% 13 / 16 Podpod 100% 2 / 2 totaltotal 52.3% 56 / 107 CC 9 SCAR 22.2
CC
9
Cov
47%
__ANON__
30.0
BEGIN
11.3
new
6.0
CRAP 9.2
« RDF/Trine/Pattern.pm ↑ Summary RDF/Trine/Parser/Turtle.pm »
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.019
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 68 ▶use base qw(RDF::Trine::Parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 68 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 68 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 68 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 68 ▶use Scalar::Util qw(blessed reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 68 ▶use Module::Load::Conditional qw[can_load];
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 68 ▶use RDF::Trine qw(literal);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 68 ▶use RDF::Trine::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 68 ▶use RDF::Trine::Statement;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 68 ▶use RDF::Trine::Error qw(:try);
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 ######################################################################
50  
51 68 our ($VERSION, $HAVE_RDFA_PARSER);
52 68 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=24.2
53 68 $VERSION = '1.019';
54 68 ▶ if (can_load( modules => { 'RDF::RDFa::Parser' => 0.30 })) {
Branch: 1 branch
BranchTrueFalseTotal
if (can_load("modules", {"RDF::RDFa::Parser", "0.3"})) 0 68 68
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 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
78 0 my $class = shift;
79 0 my %args = @_;
80 0 ▶ unless ($HAVE_RDFA_PARSER) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($RDF::Trine::Parser::RDFa::HAVE_RDFA_PARSER) 0 0 0
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 0 ▶sub parse {
Subroutine parse: not called CC=1 SCAR=6.9
Pod documented
100 0 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 0 ▶ ontriple => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
108 0 my ($p, $el, $st) = @_;
109 0 ▶ if (reftype($handler) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($handler) eq "CODE") 0 0 0
110 0 ▶ if ($self->{canonicalize}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"canonicalize"}) 0 0 0
111 0 my $o = $st->object;
112 0 ▶ if ($o->isa('RDF::Trine::Node::Literal') and $o->has_datatype) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->isa("RDF::Trine::Node::Literal") and $o->has_datatype) 0 0 0
Condition0%0/3
$o->isa("RDF::Trine::Node::Literal") and $o->has_datatype
!ll&&!rl&&r
000
MC/DC0%0/2
$o->isa("RDF::Trine::Node::Literal") and $o->has_datatype
$o->isa("RDF::Trine::Node::Literal") $o->has_datatype
Truth table0%0/3
A and B
A= $o->isa("RDF::Trine::Node::Literal")B= $o->has_datatype
ABresult
0X0
100
111
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 68 1;
130  
131 __END__
« RDF/Trine/Pattern.pm ↑ Summary RDF/Trine/Parser/Turtle.pm »