RDDL.pm

filter: Statementstmt 100% 59 / 59 Branchbran 71.4% 10 / 14 Conditioncond 52.1% 12 / 23 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 100% 11 / 11 Podpod 14.2% 1 / 7 totaltotal 74.6% 94 / 126 CC 20 SCAR 24.7
CC
20
Cov
84%
start_element
20.7
get_last_defined
3.0
new
2.0
CRAP 11.9
↑ Summary RDDL/Directory.pm »
1  
2 ###
3 # XML::RDDL - Interface to RDDL (http://www.rddl.org/)
4 # Robin Berjon <robin@knowscape.com>
5 # 17/10/2001 - v.0.01
6 ###
7  
8 package XML::RDDL;
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use XML::RDDL::Directory qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use XML::RDDL::Resource qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use vars qw($VERSION $NS_RDDL $NS_XML $NS_XLINK);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 $VERSION = '1.02';
15 2 $NS_XML = 'http://www.w3.org/XML/1998/namespace';
16 2 $NS_RDDL = 'http://www.rddl.org/';
17 2 $NS_XLINK = 'http://www.w3.org/1999/xlink';
18  
19  
20  
21 #-------------------------------------------------------------------#
22 # constructor
23 #-------------------------------------------------------------------#
24 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
25 1 ▶ my $class = ref($_[0]) ? ref(shift) : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 1 1
26 1 my %opt = @_;
27  
28 my $self = {
29 xLangStack => [$opt{default_lang}],
30 1 xBaseStack => [$opt{default_base_uri}],
31 directory => XML::RDDL::Directory->new,
32 };
33 1 return bless $self, $class;
34 }
35 #-------------------------------------------------------------------#
36  
37  
38 #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
39 #`,`, SAX2 Handler ,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,#
40 #```````````````````````````````````````````````````````````````````#
41  
42 #-------------------------------------------------------------------#
43 # start_document & end_document
44 #-------------------------------------------------------------------#
45 1 ▶sub start_document { $_[0]->{directory} = XML::RDDL::Directory->new; }
Subroutine start_document: called CC=1 SCAR=0.0
Pod undocumented
46 1 ▶sub end_document { return $_[0]->{directory}; }
Subroutine end_document: called CC=1 SCAR=0.0
Pod undocumented
47 #-------------------------------------------------------------------#
48  
49 #-------------------------------------------------------------------#
50 # start_element
51 #-------------------------------------------------------------------#
52 7 ▶sub start_element {
Subroutine start_element: called CC=16 SCAR=30.3
Pod undocumented
53 7 my $self = shift;
54 7 my $e = shift;
55  
56 # xml:lang and xml:base stacks
57 7 push @{$self->{xLangStack}}, get_attribute($e, $NS_XML, 'lang');
58 7 push @{$self->{xBaseStack}}, get_attribute($e, $NS_XML, 'base');
59  
60 #deal with rddl:resource
61 7 ▶ return unless $e->{NamespaceURI} eq $NS_RDDL and $e->{LocalName} eq 'resource';
Branch: 1 branch
BranchTrueFalseTotal
unless $e->{"NamespaceURI"} eq $XML::RDDL::NS_RDDL and $e->{"LocalName"} eq "resource" 4 3 7
Condition66%2/3
$e->{"NamespaceURI"} eq $XML::RDDL::NS_RDDL and $e->{"LocalName"} eq "resource"
!ll&&!rl&&r
403
MC/DC50%1/2
$e->{"NamespaceURI"} eq $XML::RDDL::NS_RDDL and $e->{"LocalName"} eq "resource"
$e->{"NamespaceURI"} eq $XML::RDDL::NS_RDDL $e->{"LocalName"} eq "resource"
Truth table66%2/3
A and B
A= $e->{"NamespaceURI"} eq $XML::RDDL::NS_RDDLB= $e->{"LocalName"} eq "resource"
ABresult
0X0
100
111
62  
63 3 ▶ my $type = get_attribute($e, $NS_XLINK, 'type') || 'simple';
Condition50%1/2
get_attribute($e, $XML::RDDL::NS_XLINK, 'type') || 'simple'
l!l
03
MC/DC0%0/1
get_attribute($e, $XML::RDDL::NS_XLINK, 'type') || 'simple'
get_attribute($e, $XML::RDDL::NS_XLINK, 'type')
Truth table50%1/2
A
A= get_attribute($e, $XML::RDDL::NS_XLINK, 'type')
Aresult
11
00
64 3 ▶ my $embed = get_attribute($e, $NS_XLINK, 'embed') || 'none';
Condition50%1/2
get_attribute($e, $XML::RDDL::NS_XLINK, 'embed') || 'none'
l!l
03
MC/DC0%0/1
get_attribute($e, $XML::RDDL::NS_XLINK, 'embed') || 'none'
get_attribute($e, $XML::RDDL::NS_XLINK, 'embed')
Truth table50%1/2
A
A= get_attribute($e, $XML::RDDL::NS_XLINK, 'embed')
Aresult
11
00
65 3 ▶ my $actu = get_attribute($e, $NS_XLINK, 'actuate') || 'none';
Condition50%1/2
get_attribute($e, $XML::RDDL::NS_XLINK, 'actuate') || 'none'
l!l
03
MC/DC0%0/1
get_attribute($e, $XML::RDDL::NS_XLINK, 'actuate') || 'none'
get_attribute($e, $XML::RDDL::NS_XLINK, 'actuate')
Truth table50%1/2
A
A= get_attribute($e, $XML::RDDL::NS_XLINK, 'actuate')
Aresult
11
00
66 3 ▶ die "[RDDL] xlink:type can only be set to 'simple'" if $type ne 'simple';
Branch: 1 branch
BranchTrueFalseTotal
if $type ne "simple" 0 3 3
67 3 ▶ die "[RDDL] xlink:embed can only be set to 'none'" if $embed ne 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $embed ne "none" 0 3 3
68 3 ▶ die "[RDDL] xlink:actuate can only be set to 'none'" if $actu ne 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $actu ne "none" 0 3 3
69  
70 3 ▶ my $id = get_attribute($e, '', 'id') || '';
Condition50%1/2
get_attribute($e, '', 'id') || ''
l!l
30
MC/DC0%0/1
get_attribute($e, '', 'id') || ''
get_attribute($e, '', 'id')
Truth table50%1/2
A
A= get_attribute($e, '', 'id')
Aresult
11
00
71 3 ▶ my $role = get_attribute($e, $NS_XLINK, 'role') || 'http://www.rddl.org/#resource';
Condition50%1/2
get_attribute($e, $XML::RDDL::NS_XLINK, 'role') || 'http://www.rddl.org/#resource'
l!l
30
MC/DC0%0/1
get_attribute($e, $XML::RDDL::NS_XLINK, 'role') || 'http://www.rddl.org/#resource'
get_attribute($e, $XML::RDDL::NS_XLINK, 'role')
Truth table50%1/2
A
A= get_attribute($e, $XML::RDDL::NS_XLINK, 'role')
Aresult
11
00
72 3 ▶ my $arcrole = get_attribute($e, $NS_XLINK, 'arcrole') || '';
Condition50%1/2
get_attribute($e, $XML::RDDL::NS_XLINK, 'arcrole') || ''
l!l
30
MC/DC0%0/1
get_attribute($e, $XML::RDDL::NS_XLINK, 'arcrole') || ''
get_attribute($e, $XML::RDDL::NS_XLINK, 'arcrole')
Truth table50%1/2
A
A= get_attribute($e, $XML::RDDL::NS_XLINK, 'arcrole')
Aresult
11
00
73 3 ▶ my $href = get_attribute($e, $NS_XLINK, 'href') || '';
Condition50%1/2
get_attribute($e, $XML::RDDL::NS_XLINK, 'href') || ''
l!l
30
MC/DC0%0/1
get_attribute($e, $XML::RDDL::NS_XLINK, 'href') || ''
get_attribute($e, $XML::RDDL::NS_XLINK, 'href')
Truth table50%1/2
A
A= get_attribute($e, $XML::RDDL::NS_XLINK, 'href')
Aresult
11
00
74 3 ▶ my $title = get_attribute($e, $NS_XLINK, 'title') || '';
Condition50%1/2
get_attribute($e, $XML::RDDL::NS_XLINK, 'title') || ''
l!l
30
MC/DC0%0/1
get_attribute($e, $XML::RDDL::NS_XLINK, 'title') || ''
get_attribute($e, $XML::RDDL::NS_XLINK, 'title')
Truth table50%1/2
A
A= get_attribute($e, $XML::RDDL::NS_XLINK, 'title')
Aresult
11
00
75  
76 3 ▶ my $xlang = get_last_defined($self->{xLangStack}) || '';
Condition50%1/2
get_last_defined($self->{'xLangStack'}) || ''
l!l
30
MC/DC0%0/1
get_last_defined($self->{'xLangStack'}) || ''
get_last_defined($self->{'xLangStack'})
Truth table50%1/2
A
A= get_last_defined($self->{'xLangStack'})
Aresult
11
00
77 3 ▶ my $xbase = get_last_defined($self->{xBaseStack}) || '';
Condition50%1/2
get_last_defined($self->{'xBaseStack'}) || ''
l!l
30
MC/DC0%0/1
get_last_defined($self->{'xBaseStack'}) || ''
get_last_defined($self->{'xBaseStack'})
Truth table50%1/2
A
A= get_last_defined($self->{'xBaseStack'})
Aresult
11
00
78  
79 3 my $res = XML::RDDL::Resource->new(
80 id => $id,
81 base_uri => $xbase,
82 href => $href,
83 nature => $role,
84 purpose => $arcrole,
85 title => $title,
86 lang => $xlang,
87 );
88 3 $self->{directory}->add_resource($res);
89 }
90 #-------------------------------------------------------------------#
91  
92 #-------------------------------------------------------------------#
93 # end_element
94 #-------------------------------------------------------------------#
95 7 ▶sub end_element {
Subroutine end_element: called CC=1 SCAR=0.0
Pod undocumented
96 7 my $self = shift;
97 7 pop @{$self->{xLangStack}};
98 7 pop @{$self->{xBaseStack}};
99 }
100 #-------------------------------------------------------------------#
101  
102  
103 #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
104 #`,`, Misc. Helpers `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,#
105 #```````````````````````````````````````````````````````````````````#
106  
107 #-------------------------------------------------------------------#
108 # get_last_defined
109 #-------------------------------------------------------------------#
110 6 ▶sub get_last_defined {
Subroutine get_last_defined: called CC=3 SCAR=11.0
Pod undocumented
111 6 my $arr = shift;
112 6 for my $el (reverse @$arr) {
113 10 ▶ return $el if defined $el;
Branch: 1 branch
BranchTrueFalseTotal
if defined $el 6 4 10
114 }
115 }
116 #-------------------------------------------------------------------#
117  
118 #-------------------------------------------------------------------#
119 # get_attribute
120 #-------------------------------------------------------------------#
121 38 ▶sub get_attribute {
Subroutine get_attribute: called CC=2 SCAR=6.9
Pod undocumented
122 38 my $e = shift;
123 38 my $ns = shift;
124 38 my $ln = shift;
125  
126 38 ▶ if (exists $e->{Attributes}->{"{$ns}$ln"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $e->{"Attributes"}{"{$ns}$ln"}) 21 17 38
127 21 return $e->{Attributes}->{"{$ns}$ln"}->{Value};
128 }
129 17 return undef;
130 }
131 #-------------------------------------------------------------------#
132  
133  
134  
135 2 1;
136 #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
137 #`,`, Documentation `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,#
138 #```````````````````````````````````````````````````````````````````#
139  
140 =pod
141  
142 =head1 NAME
143  
144 XML::RDDL - Interface to RDDL (http://www.rddl.org/)
145  
146 =head1 SYNOPSIS
147  
148 use XML::RDDL;
149 use MySAX2Driver;
150  
151 my $handler = XML::RDDL->new(
152 default_lang => 'en',
153 default_base_uri => 'http://foo/doc.xml',
154 );
155 my $driver = MySAX2Driver->new(Handler => $handler);
156 my $rddl = $driver->parse($some_rddl);
157  
158 =head1 DESCRIPTION
159  
160 RDDL (Resource Directory Description Language) is an XML vocabulary
161 used to described resources associated with a namespace. It can be
162 embedded inside other XML vocabularies (most frequently XHTML).
163  
164 This module is meant to be used as a SAX2 handler that will return a
165 Directory instance containing all resource descriptions at the end of
166 the parse.
167  
168 =head1 METHODS
169  
170 =over 4
171  
172 =item XML::RDDL->new(%options)
173  
174 Creates an XML::RDDL instance which is a SAX2 handler. The options
175 are:
176  
177 - default_lang
178 the default language (as described in an xml:lang attribute) to
179 be used. It is recommended that this be used if you want to have
180 multilingual resources and your document doesn't contain
181 sufficient xml:lang attributes.
182  
183 - default_base_uri
184 the default base URI (as described in an xml:base attribute) to
185 be used (principally in xlink:href resolution). It is recommended
186 that this be used if you want to resolve the xlink:hrefs and the
187 document doesn't contain the appropriate xml:base attributes.
188  
189 =back
190  
191 =head1 AUTHOR
192  
193 Robin Berjon, robin@knowscape.com
194  
195 =head1 COPYRIGHT
196  
197 Copyright (c) 2001-2002 Robin Berjon. All rights reserved. This program
198 is free software; you can redistribute it and/or modify it under the
199 same terms as Perl itself.
200  
201 =head1 SEE ALSO
202  
203 http://www.rddl.org/, XML::RDDL::Directory, XML::RDDL::Resource,
204 XML::RDDL::Driver
205  
206 =cut
207  
↑ Summary RDDL/Directory.pm »