File Coverage

blib/lib/Combine/XWI.pm
Criterion Covered Total %
statement 131 175 74.8
branch 13 20 65.0
condition 0 3 0.0
subroutine 26 34 76.4
pod 30 30 100.0
total 200 262 76.3


line stmt bran cond sub pod time code
1             # $Id: XWI.pm 226 2006-12-13 15:06:48Z anders $
2              
3             # Copyright (c) 1996-1998 LUB NetLab, 2002-2006 Anders Ardö
4             #
5             # See the file LICENCE included in the distribution.
6              
7             package Combine::XWI;
8              
9 4     4   10472 use strict;
  4         9  
  4         136  
10 4     4   4080 use HTML::Entities;
  4         29657  
  4         9287  
11              
12             sub new {
13 3     3 1 87 my ($class) = @_;
14 3         20 my $self = {};
15 3         24 bless $self, $class;
16 3         42 $self->url_reset;
17 3         34 $self->heading_reset;
18 3         21 $self->link_reset;
19 3         53 $self->meta_reset;
20 3         22 $self->robot_reset;
21 3         26 $self->topic_reset;
22 3         17 return $self;
23             }
24              
25 0     0   0 sub DESTROY {
26             # print "an XWI object is destroyed" if Combine::Config::GetLoglev() > 2;
27             }
28              
29             sub AUTOLOAD {
30 22     22   1467 my ($self, $value) = @_;
31 22         36 my $name = $Combine::XWI::AUTOLOAD;
32 22         119 $name =~ s/.*://;
33 22 100       60 if ($value) {
34 17         38 $self->{$name} = $value;
35 17         36 return undef;
36             }
37             else {
38 5         20 return $self->{$name};
39             }
40             }
41              
42             sub url_remove {
43 0     0 1 0 my ($self,$url) = @_;
44 0         0 my ($i,$next);
45 0         0 my $index = 1;
46 0         0 my $count = $self->{'url_count'};
47 0   0     0 while ( $index <= $count and $self->{"url_$index"} ne $url ) {
48 0         0 $index++;
49             }
50 0 0       0 return undef if $index > $count;
51 0         0 for ($i=$index; $i<$count; $i++) {
52 0         0 $next = $i + 1;
53 0         0 $self->{"url_$i"} = $self->{"url_$next"};
54             }
55 0         0 $self->{'url_count'}--;
56             }
57              
58             sub url_reset {
59 3     3 1 9 my ($self) = @_;
60 3         68 $self->{'url_point'} = 1;
61 3         13 $self->{'url_count'} = 0;
62             }
63              
64             sub url_rewind {
65 0     0 1 0 my ($self) = @_;
66 0         0 $self->{'url_point'} = 1;
67             }
68              
69             sub url_add {
70 5     5 1 35 my ($self, $url) = @_;
71 5         17 $self->{'url_count'}++;
72 5         19 my $point = $self->{'url_count'};
73 5         16 $self->{"url_$point"} = $url;
74 5         15 return $self->{'url_count'};
75             }
76              
77             sub url_get {
78 0     0 1 0 my ($self) = @_;
79 0         0 my $point = $self->{'url_point'};
80 0 0       0 return undef unless $point <= $self->{'url_count'};
81 0         0 $self->{'url_point'}++;
82 0         0 return $self->{"url_$point"};
83             }
84              
85             sub meta_reset {
86 3     3 1 12 my ($self) = @_;
87 3         15 $self->{'meta_point'} = 1;
88 3         16 $self->{'meta_count'} = 0;
89             }
90              
91             sub meta_rewind {
92 1     1 1 503 my ($self) = @_;
93 1         3 $self->{'meta_point'} = 1;
94             }
95              
96             sub meta_add {
97 9     9 1 37 my ($self, $meta_name, $meta_content) = @_;
98 9         16 $self->{'meta_count'}++;
99 9         15 my $point = $self->{'meta_count'};
100 9         30 $self->{"meta_" . $point . "_name"} = $meta_name;
101 9         44 $self->{"meta_" . $point . "_content" } =
102             HTML::Entities::decode_entities($meta_content);
103             # special for robots meta-tag
104 9 50       48 if ( $meta_name eq "robots" ) {
105 0         0 $self->{metarobots} = $meta_content;
106             }
107 9         27 return $self->{'meta_count'};
108             }
109              
110             sub meta_get {
111 4     4 1 3262 my ($self) = @_;
112 4         11 my $point = $self->{'meta_point'};
113 4 100       21 return undef unless $point <= $self->{'meta_count'};
114 3         6 $self->{'meta_point'}++;
115 3         13 my $meta_name = $self->{"meta_" . $point . "_name"};
116 3         12 my $meta_content = $self->{"meta_" . $point . "_content"};
117 3         12 return($meta_name, $meta_content);
118             }
119              
120             sub robot_reset {
121 3     3 1 6 my ($self) = @_;
122 3         15 $self->{'robot_point'} = 1;
123 3         17 $self->{'robot_count'} = 0;
124             }
125              
126             sub robot_rewind {
127 1     1 1 13 my ($self) = @_;
128 1         4 $self->{'robot_point'} = 1;
129             }
130              
131             sub robot_add {
132 6     6 1 29 my ($self, $robot_name, $robot_content) = @_;
133 6         11 $self->{'robot_count'}++;
134 6         10 my $point = $self->{'robot_count'};
135 6         19 $self->{"robot_" . $point . "_name"} = $robot_name;
136 6         14 $self->{"robot_" . $point . "_content" } = $robot_content;
137 6         12 return $self->{'robot_count'};
138             }
139              
140             sub robot_get {
141 3     3 1 1893 my ($self) = @_;
142 3         8 my $point = $self->{'robot_point'};
143 3 100       205 return undef unless $point <= $self->{'robot_count'};
144 2         3 $self->{'robot_point'}++;
145 2         9 my $robot_name = $self->{"robot_" . $point . "_name"};
146 2         6 my $robot_content = $self->{"robot_" . $point . "_content"};
147 2         9 return($robot_name, $robot_content);
148             }
149              
150              
151             sub topic_reset {
152 3     3 1 15 my ($self) = @_;
153 3         16 $self->{'topic_point'} = 1;
154 3         12 $self->{'topic_count'} = 0;
155             }
156              
157             sub topic_rewind {
158 1     1 1 10 my ($self) = @_;
159 1         4 $self->{'topic_point'} = 1;
160             }
161              
162             sub topic_add {
163 6     6 1 41 my ($self, $topic_cls, $topic_absscore, $topic_relscore, $terms, $algorithm) = @_;
164 6         11 $self->{'topic_count'}++;
165 6         9 my $point = $self->{'topic_count'};
166 6         17 $self->{"topic_" . $point . "_cls"} = $topic_cls;
167 6         21 $self->{"topic_" . $point . "_absscore" } = $topic_absscore;
168 6         18 $self->{"topic_" . $point . "_relscore" } = $topic_relscore;
169 6         18 $self->{"topic_" . $point . "_terms" } = $terms;
170 6         17 $self->{"topic_" . $point . "_algorithm" } = $algorithm;
171 6         13 return $self->{'topic_count'};
172             }
173              
174             sub topic_get {
175 3     3 1 2246 my ($self) = @_;
176 3         11 my $point = $self->{'topic_point'};
177 3 100       14 return undef unless $point <= $self->{'topic_count'};
178 2         3 $self->{'topic_point'}++;
179 2         10 my $topic_cls = $self->{"topic_" . $point . "_cls"};
180 2         7 my $topic_absscore = $self->{"topic_" . $point . "_absscore"};
181 2         7 my $topic_relscore = $self->{"topic_" . $point . "_relscore"};
182 2         6 my $terms = $self->{"topic_" . $point . "_terms"};
183 2         7 my $algorithm = $self->{"topic_" . $point . "_algorithm"};
184 2         10 return($topic_cls, $topic_absscore, $topic_relscore, $terms, $algorithm);
185             }
186              
187             sub xmeta_reset {
188 0     0 1 0 my ($self) = @_;
189 0         0 $self->{'xmeta_point'} = 1;
190 0         0 $self->{'xmeta_count'} = 0;
191             }
192              
193             sub xmeta_rewind {
194 0     0 1 0 my ($self) = @_;
195 0         0 $self->{'xmeta_point'} = 1;
196             }
197              
198             sub xmeta_add {
199 0     0 1 0 my ($self, $meta_name, $meta_content, $meta_scheme,
200             $meta_lang, $meta_group) = @_;
201 0         0 $self->{'xmeta_count'}++;
202 0         0 my $point = $self->{'xmeta_count'};
203 0         0 $self->{"xmeta_" . $point . "_name"} = $meta_name;
204 0         0 $self->{"xmeta_" . $point . "_content" } = $meta_content;
205 0         0 $self->{"xmeta_" . $point . "_scheme" } = $meta_scheme;
206 0         0 $self->{"xmeta_" . $point . "_lang" } = $meta_lang;
207 0         0 $self->{"xmeta_" . $point . "_group" } = $meta_group;
208 0         0 return $self->{'xmeta_count'};
209             }
210              
211             sub xmeta_get {
212 0     0 1 0 my ($self) = @_;
213 0         0 my $point = $self->{'xmeta_point'};
214 0 0       0 return undef unless $point <= $self->{'xmeta_count'};
215 0         0 $self->{'xmeta_point'}++;
216 0         0 my $meta_name = $self->{"meta_" . $point . "_name"};
217 0         0 my $meta_content = $self->{"meta_" . $point . "_content"};
218 0         0 my $meta_scheme = $self->{"xmeta_" . $point . "_scheme" };
219 0         0 my $meta_lang = $self->{"xmeta_" . $point . "_lang" };
220 0         0 my $meta_group = $self->{"xmeta_" . $point . "_group" };
221              
222 0         0 return ($meta_name, $meta_content, $meta_scheme,$meta_lang, $meta_group);
223             }
224              
225              
226             sub heading_reset {
227 3     3 1 10 my ($self) = @_;
228 3         18 $self->{'heading_point'} = 1;
229 3         17 $self->{'heading_count'} = 0;
230             }
231              
232             sub heading_rewind {
233 1     1 1 2 my ($self) = @_;
234 1         3 $self->{'heading_point'} = 1;
235             }
236              
237             sub heading_add {
238 6     6 1 53 my ($self, $heading) = @_;
239 6         12 $self->{'heading_count'}++;
240 6         10 my $point = $self->{'heading_count'};
241 6         83 $self->{"heading_$point"} = HTML::Entities::decode_entities($heading);
242 6         17 return $self->{'heading_count'};
243             }
244              
245             sub heading_get {
246 3     3 1 1086 my ($self) = @_;
247 3         16 my $point = $self->{'heading_point'};
248 3 100       11 return undef unless $point <= $self->{'heading_count'};
249 2         4 $self->{'heading_point'}++;
250 2         7 return $self->{"heading_$point"};
251             }
252              
253             sub link_reset {
254 3     3 1 9 my ($self) = @_;
255 3         13 $self->{'link_point'} = 1;
256 3         14 $self->{'link_count'} = 0;
257             }
258              
259             sub link_rewind {
260 1     1 1 5 my ($self) = @_;
261 1         3 $self->{'link_point'} = 1;
262             }
263              
264             sub link_add {
265 6     6 1 50 my ($self, $link_urlstr, $link_netlocid, $link_urlid, $link_text, $link_type) = @_;
266 6         14 $self->{'link_count'}++;
267 6         13 my $point = $self->{'link_count'};
268 6         45 $self->{"link_" . $point . "_text"} =
269             HTML::Entities::decode_entities($link_text);
270 6         34 $self->{"link_" . $point . "_urlstr" } = $link_urlstr;
271 6         24 $self->{"link_" . $point . "_netlocid" } = $link_netlocid;
272 6         25 $self->{"link_" . $point . "_urlid" } = $link_urlid;
273 6         42 $self->{"link_" . $point . "_type" } = $link_type;
274 6         18 return $self->{'link_count'};
275             }
276              
277             sub link_get {
278 3     3 1 1445 my ($self) = @_;
279 3         6 my $point = $self->{'link_point'};
280 3 100       12 return undef unless $point <= $self->{'link_count'};
281 2         3 $self->{'link_point'}++;
282 2         6 my $link_text = $self->{"link_" . $point . "_text"};
283 2         3 my $link_urlstr = $self->{"link_" . $point . "_urlstr"};
284 2         4 my $link_netlocid = $self->{"link_" . $point . "_netlocid"};
285 2         7 my $link_urlid = $self->{"link_" . $point . "_urlid"};
286 2         5 my $link_type = $self->{"link_" . $point . "_type"};
287 2         7 return($link_urlstr, $link_netlocid, $link_urlid, $link_text, $link_type);
288             }
289              
290             1;
291              
292             __END__