Glossary/XBEL.pm

filter: Statementstmt 100% 44 / 44 Branchbran 96.4% 27 / 28 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 7 / 7 totaltotal 98.9% 92 / 93 CC 16 SCAR 14.5
CC
16
Cov
99%
start_element
7.0
characters
5.0
end_element
4.0
CRAP 4.3
« Glossary.pm ↑ Summary
1 =head1 NAME
2  
3 XML::Filter::Glossary::XBEL - Implements an XBEL-based glossary system.
4  
5 =head1 SYNOPSIS
6  
7 You should really be using I<XML::Filter::Glossary> proper, but since you're here :
8  
9 use XML::Filter::Glossary::XBEL;
10  
11 my $glossary = XML::Filter::Glossary::XBEL->new();
12 my $parser = XML::SAX::ParserFactory->parser(Handler=>$glossary);
13  
14 $glossary->set_keyword("aaronland");
15 $parser->parse_uri("/path/to/glossary.xbel");
16  
17 print $glossary->result();
18  
19 =head1 DESCRIPTION
20  
21 Perform a glossary lookup via an XBEL files.
22  
23 =cut
24  
25 package XML::Filter::Glossary::XBEL;
26 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 $XML::Filter::Glossary::XBEL::VERSION = '0.1';
29 2 ▶use base qw (XML::SAX::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 =head1 PACKAGE METHODS
32  
33 =head2 __PACKAGE__->new(%args)
34  
35 Inherits from I<XML::SAX::Base>
36  
37 =head1 OBJECT METHODS
38  
39 =head2 $pkg->set_keyword($text)
40  
41 Set the keyword to lookup in the glossary.
42  
43 I<$text> will be compared against :
44  
45 # No, the package doesn't use XPath.
46 # I just find the syntax handy, sometime.
47 /xbel//bookmark[title='$text']
48  
49 =cut
50  
51 11 ▶sub set_keyword {
Subroutine set_keyword: called CC=1 SCAR=0.0
Pod documented
52 11 my $self = shift;
53 11 $self->{'__keyword'} = $_[0];
54 }
55  
56 =head2 $pkg->result()
57  
58 Returns a string, formatted as an HTML anchor element.
59  
60 If no match was found, returns undef.
61  
62 =cut
63  
64 11 ▶sub result {
Subroutine result: called CC=2 SCAR=6.9
Pod documented
65 11 my $self = shift;
66 11 ▶ return undef if (! $self->{'__link'});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"__link"} 2 9 11
67 9 return "<a href = \"".$self->{'__link'}."\">".$self->{'__keyword'}."</a>";
68 }
69  
70 11 ▶sub start_document {
Subroutine start_document: called CC=1 SCAR=0.0
Pod documented
71 11 my $self = shift;
72  
73 11 $self->{'__bookmark'} = 0;
74 11 $self->{'__title'} = 0;
75 11 $self->{'__match'} = 0;
76 11 $self->{'__link'} = undef;
77 }
78  
79 11 ▶sub end_document {
Subroutine end_document: called CC=2 SCAR=6.9
Pod documented
80 11 my $self = shift;
81  
82 11 ▶ if (! $self->{'__match'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"__match"}) 2 9 11
83 2 $self->{'__link'} = undef;
84 }
85 }
86  
87 11022 ▶sub start_element {
Subroutine start_element: called CC=7 SCAR=19.5
Pod documented
88 11022 my $self = shift;
89 11022 my $data = shift;
90  
91 11022 ▶ return if ($self->{'__match'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__match"} 4756 6266 11022
92  
93 6266 ▶ if ((! $self->{'__bookmark'}) && ($data->{Name} eq "bookmark")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"__bookmark"} and $data->{"Name"} eq "bookmark") 2444 3822 6266
Condition100%3/3
not $self->{"__bookmark"} and $data->{"Name"} eq "bookmark"
!ll&&!rl&&r
244413782444
MC/DC100%2/2
not $self->{"__bookmark"} and $data->{"Name"} eq "bookmark"
not $self->{"__bookmark"} $data->{"Name"} eq "bookmark"
Truth table100%3/3
not(A) and B
A= not $self->{"__bookmark"}B= $data->{"Name"} eq "bookmark"
ABresult
0X0
100
111
94 2444 $self->{'__bookmark'} = 1;
95 }
96  
97 6266 ▶ return if (! $self->{'__bookmark'});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"__bookmark"} 1378 4888 6266
98  
99 4888 ▶ if ($data->{Name} eq "bookmark") {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"Name"} eq "bookmark") 2444 2444 4888
100 2444 $self->{'__link'} = $data->{Attributes}->{'{}href'}->{Value};
101 # print $self->{'__link'}."\n";
102 }
103  
104 4888 ▶ $self->{'__title'} = 1 if ($data->{Name} eq "title");
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"Name"} eq "title" 2444 2444 4888
105 }
106  
107 11022 ▶sub end_element {
Subroutine end_element: called CC=4 SCAR=13.9
Pod documented
108 11022 my $self = shift;
109 11022 my $data = shift;
110  
111 11022 ▶ return if ($self->{'__match'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__match"} 4804 6218 11022
112  
113 6218 ▶ if ($data->{Name} eq "title") {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"Name"} eq "title") 3113 3105 6218
114 3113 $self->{'__title'} = 0;
115 }
116  
117 6218 ▶ if ($data->{Name} eq "bookmark") {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"Name"} eq "bookmark") 2435 3783 6218
118 2435 $self->{'__bookmark'} = 0;
119 }
120  
121 }
122  
123 12199 ▶sub characters {
Subroutine characters: called CC=5 SCAR=16.1
Pod documented
124 12199 my $self = shift;
125 12199 my $data = shift;
126  
127 12199 ▶ return if ($self->{'__match'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__match"} 5244 6955 12199
128 6955 ▶ return if (! $self->{'__bookmark'});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"__bookmark"} 4479 2476 6955
129 2476 ▶ return if (! $self->{'__title'});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"__title"} 0 2476 2476
130  
131 2476 ▶ if ($data->{Data} eq $self->{'__keyword'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"Data"} eq $self->{"__keyword"}) 9 2467 2476
132 9 $self->{'__match'} = 1;
133 }
134 }
135  
136 =head1 VERSION
137  
138 0.1
139  
140 =head1 DATE
141  
142 September 10, 2002
143  
144 =head1 AUTHOR
145  
146 Aaron Straup Cope
147  
148 =head1 SEE ALSO
149  
150 L<XML::Filter::Glossary>
151  
152 =head1 LICENSE
153  
154 Copyright (c) 2002, Aaron Straup Cope. All Rights Reserved.
155  
156 This is free software, you may use it and distribute it under the same terms as Perl itself.
157  
158 =cut
159  
160 2 return 1;
« Glossary.pm ↑ Summary