Overview.pm

filter: Statementstmt 11.8% 19 / 161 Branchbran 0.0% 0 / 76 Conditioncond 0.0% 0 / 38 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 20.8% 5 / 24 Podpod 100% 16 / 16 totaltotal 11.8% 40 / 337 CC 66 SCAR 42.4
CC
66
Cov
7%
add_from_article
132.0
sort
132.0
thread
110.0
CRAP 69.4
↑ Summary Overview/Entry.pm »
1 1 $VERSION = "0.12";
2 package News::Overview;
3 1 our $VERSION = "0.12";
4  
5 # -*- Perl -*- # Fri Oct 10 11:29:51 CDT 2003
6 #############################################################################
7 # Written by Tim Skirvin <tskirvin@killfile.org>. Copyright 2003, Tim
8 # Skirvin. Redistribution terms are below.
9 #############################################################################
10  
11 =head1 NAME
12  
13 News::Overview - an object to store condensed information about Usenet posts
14  
15 =head1 SYNOPSIS
16  
17 use News::Overview;
18 use Net::NNTP;
19
20 my $overview = News::Overview->new();
21 my $nntp = new Net::NNTP;
22  
23 $nntp->group("killfile.test");
24 $overview->add_from_nntp($nntp->xover);
25  
26 foreach my $entry ( $overview->sort ('thread', $overview->entries) ) {
27 print $overview->print_entry($entry), "\n";
28 }
29  
30 =head1 DESCRIPTION
31  
32 News::Overview objects store combined information about many messages, as
33 generally done in INN's overview format and semi-codified in the XOVER
34 extentions to RFC1036. Each object is meant to store a single
35 newsgroup's worth of basic header information - by default the message
36 number, subject, poster, date of posting, message identifier, references
37 to the article's parents, size of the body, number of lines in the body,
38 and information on where this message is stored within the server.
39 This information is then used to offer summartes of messages in the group,
40 sort the messages, and so forth.
41  
42 The main unit of storage within News::Overview is the object
43 News::Overview::Entry; each one of these contains information on a single
44 article. News::Overview itself is dedicated to creating, storing, and
45 manipulating these Entries.
46  
47 =head1 USAGE
48  
49 All of this object's usage is contained within its functions.
50  
51 =cut
52  
53 ###############################################################################
54 ### main() ####################################################################
55 ###############################################################################
56  
57 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 ▶use News::Article;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 ▶use News::Overview::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 ▶use Net::NNTP::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 1 ▶use vars qw( @DEFAULT );
Subroutine BEGIN: called CC=1 SCAR=0.0
63 1 @DEFAULT = qw( Subject: From: Date: Message-ID: References:
64 Bytes: Lines: Xref:full );
65  
66 =head2 Basic Functions
67  
68 =over 4
69  
70 =item new ( [ DEFAULT_ARRAY_REF ] )
71  
72 Creates a new News::Overview object.
73  
74 If C<DEFAULT_ARRAY_REF> is offered, we will use this to define which
75 fields are stored in all the associated Entries; otherwise, we default to
76 the fields in C<@News::Overview::DEFAULT>. The 'Number:' field is added
77 as well, to store the "article number" that each entry is associated with.
78  
79 Returns the new blessed object, or undef if unsuccessful.
80  
81 =cut
82  
83 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
84 0 my ($proto, $default) = @_;
85 0 ▶ $default ||= "";
Condition0%0/2
$default ||= ""
l!l
00
MC/DC0%0/1
$default ||= ""
$default
Truth table0%0/2
A
A= $default
Aresult
11
00
86 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
87 my $self = {
88 0 ▶ Defaults => [ ref $default ? @{$default} : @DEFAULT ],
Branch: 1 branch
BranchTrueFalseTotal
ref $default ? : 0 0 0
89 # Count => 0, # Number of articles currently in here
90 Articles => {}, # Actual article information
91 Article_By_ID => {}, # Actual article information
92 };
93 0 unshift @{$$self{Defaults}}, "Number:";
94 0 $$self{'Fields'} = [ _fields($$self{'Defaults'}) ];
95 0 bless $self, $class;
96 0 $self;
97 }
98  
99 =item default ()
100  
101 In array context, returns the full list of default information associated
102 with each Entry. In scalar context, returns the same as an arrayref.
103  
104 =item defaults ( )
105  
106 Same as default(), except this information is instead based on
107 @News::Overview::DEFAULT (ie doesn't include Number:).
108  
109 =item fields ()
110  
111 In array context, returns the list of fields stored in each associated
112 Entry. In scalar context, returns this as an arrayref.
113  
114 This differs from default() only in as much as everything after the ':' is
115 trimmed; these are meant to be used as
116  
117 =cut
118  
119 0 ▶sub default { wantarray ? @{shift->{'Defaults'}} : shift->{'Defaults'} ; }
Subroutine default: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
120 0 ▶sub defaults { _fields(@DEFAULT) }
Subroutine defaults: not called CC=1 SCAR=6.9
Pod documented
121 0 ▶sub fields { wantarray ? @{shift->{'Fields'}} : shift->{'Fields'} ; }
Subroutine fields: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
122  
123 # =item value ( KEY [, VALUE ])
124 #
125 # Returns the ...hey, wait a second, we're not doing anything with this!
126 #
127 # =cut
128 #
129 # sub value {
130 # my ($self, $key, $value) = @_;
131 # return undef unless $key;
132 # $self->values->{$key} = $value if defined $value;
133 # $self->values->{$key};
134 # }
135 #
136 # =item values ( )
137 #
138 # =cut
139 #
140 # sub values { shift->{'Values'} }
141
142 =item entries ()
143  
144 Returns the (unsorted) array of News::Overview::Entry objects within the
145 object.
146  
147 =cut
148  
149 0 ▶sub entries { values %{shift->{Articles}} }
Subroutine entries: not called CC=1 SCAR=6.9
Pod documented
150  
151 =item count ()
152  
153 Returns the number of News::Overview::Entry objects associated with this
154 object.
155  
156 =cut
157  
158 0 ▶sub count { scalar values %{shift->{Articles}} || 0 }
Subroutine count: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
scalar values %{(shift())->{"Articles"};} or 0 0 0 0
159  
160 =back
161  
162 =head2 Adding Entries
163  
164 These functions add new News::Overview::Entry items to the object, as
165 parsed from several sources.
166  
167 =over 4
168  
169 =item insert_entry ( NUMBER, INFOARRAY )
170  
171 Actually does the work of inserting an Entry into the object. C<NUMBER>
172 is the article number, which is used as they key for this Entry;
173 C<INFOARRAY> is the list of information necessary for each Entry, sorted
174 by whatever function called this one.
175  
176 Returns undef if there's already an entry matching the given C<NUMBER>,
177 otherwise returns the new entry.
178  
179 =cut
180  
181 0 ▶sub insert_entry {
Subroutine insert_entry: not called CC=8 SCAR=42.8
Pod documented
182 0 my ($self, @info) = @_;
183 0 my %hash;
184 0 ▶ foreach ($self->fields) { $hash{$_} = shift @info || ""; }
Condition0%0/2
shift @info || ''
l!l
00
MC/DC0%0/1
shift @info || ''
shift @info
Truth table0%0/2
A
A= shift @info
Aresult
11
00
185 0 my $msgid = $hash{'Message-ID'};
186  
187 # Don't do anything more if there's already an entry for this
188 0 ▶ return undef if $self->{'Articles_By_ID'}->{$msgid};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Articles_By_ID"}{$msgid} 0 0 0
189  
190 0 ▶ my @refs = split(/\s+/, $hash{'References'} || "");
Condition0%0/2
$hash{'References'} || ''
l!l
00
MC/DC0%0/1
$hash{'References'} || ''
$hash{'References'}
Truth table0%0/2
A
A= $hash{'References'}
Aresult
11
00
191 0 my $item = new News::Overview::Entry($msgid, \@refs, %hash);
192 0 foreach (@refs) {
193 0 ▶ my $artbyid = $self->{'Article_By_ID'}->{$_} || undef;
Condition0%0/2
$self->{'Article_By_ID'}{$_} || undef
l!l
00
MC/DC0%0/1
$self->{'Article_By_ID'}{$_} || undef
$self->{'Article_By_ID'}{$_}
Truth table0%0/2
A
A= $self->{'Article_By_ID'}{$_}
Aresult
11
00
194 0 ▶ if ($artbyid) { $artbyid->add_child($item) }
Branch: 1 branch
BranchTrueFalseTotal
if ($artbyid) 0 0 0
195 }
196 0 $self->{'Article_By_ID'}->{$msgid} = $item;
197  
198 0 my $number = $hash{'Number'}; # Ought to abort if we don't have this
199 0 $self->{'Articles'}->{$number} = $item;
200 0 $item;
201 }
202  
203 =item add_xover ( LINES )
204  
205 Reads in raw xover C<LINES> (such as those created by print()) and creates
206 entries for each, using insert_entry(). Returns the number of Entries
207 that were succesfully added.
208  
209 =cut
210  
211 0 ▶sub add_xover {
Subroutine add_xover: not called CC=3 SCAR=24.8
Pod documented
212 0 my ($self, @lines) = @_;
213 0 my $count = 0;
214 0 foreach my $line (@lines) {
215 0 chomp; my ($art, @info) = split(/\t/, $line);
216 0 ▶ $self->insert_entry( $art, @info ) and $count++
Branch: 1 branch
BranchTrueFalseTotal
$self->insert_entry($art, @info) and ++$count 0 0 0
217 }
218 0 $$self{Count} += $count; $count;
219 }
220  
221 =item add_from_nntp ( LINEHASH )
222  
223 Reads in the information returned by Net::NNTP's xover() function, and and
224 creates entries for each, using insert_entry(). Returns the number of
225 Entries that were succesfully added.
226  
227 =cut
228  
229 0 ▶sub add_from_nntp {
Subroutine add_from_nntp: not called CC=4 SCAR=30.0
Pod documented
230 0 my ($self, %lines) = @_;
231 0 my $count = 0;
232 0 foreach my $art (keys %lines) {
233 0 ▶ next unless ref $lines{$art};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $lines{$art} 0 0 0
234 0 my @info = @{$lines{$art}};
235 0 ▶ $self->insert_entry( $art, @info ) and $count++
Branch: 1 branch
BranchTrueFalseTotal
$self->insert_entry($art, @info) and ++$count 0 0 0
236 }
237  
238 0 $$self{Count} += $count; $count;
239 }
240  
241 =item add_from_article ( NUMBER, ARTICLE )
242  
243 Takes C<ARTICLE>, a News::Article object, and generates the necessary
244 information to populate an Entry from it. C<NUMBER> is the key that will
245 be associated with the article; we need it separately because we can't
246 really get it from the article directly. Returns 1 if successful, 0 if
247 not (roughly the same as add_xover() and add_from_nntp()).
248  
249 =cut
250  
251 0 ▶sub add_from_article {
Subroutine add_from_article: not called CC=11 SCAR=48.8
Pod documented
252 0 my ($self, $num, $article) = @_;
253 0 ▶ return undef unless ($num && $article && ref $article);
Branch: 1 branch
BranchTrueFalseTotal
unless $num and $article and ref $article 0 0 0
Condition0%0/6
$num and $article and ref $article
!ll&&!rl&&r
000
$num and $article
!ll&&!rl&&r
000
MC/DC0%0/3
$num and $article and ref $article
$num $article ref $article
Truth table0%0/4
A and B and C
A= $numB= $articleC= ref $article
ABCresult
0XX0
10X0
1100
1111
254  
255 0 my @info;
256 0 ▶ my @defaults = ref $self ? $self->default : @DEFAULT;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
257 0 foreach my $field (@defaults) {
258 0 $field =~ s/:.*//;
259 0 ▶ next if $field eq 'Number';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "Number" 0 0 0
260 # next unless $field;
261 0 ▶ if (lc $field eq 'lines') { push @info, $article->lines; }
Branch: 3 branches
BranchTrueFalseTotal
if (lc $field eq 'lines') { } 0 0 0
elsif (lc $field eq 'bytes') { } 0 0 0
elsif ($article->header($field)) { } 0 0 0
262 0 elsif (lc $field eq 'bytes') { push @info, $article->bytes; }
263 elsif ($article->header($field)) {
264 0 push @info, $article->header($field);
265 0 } else { push @info, '' }
266 }
267 0 ▶ $self->insert_entry( $num, @info ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->insert_entry($num, @info) ? : 0 0 0
268 }
269  
270  
271 =head2 Sorting Functions
272  
273 These functions are used to sort the Entries within the News::Overview
274 object.
275  
276 =over 4
277  
278 =item sort ( SORTTYPE, ENTRIES )
279  
280 Sort array C<ENTRIES> based on C<SORTTYPE>. Possible sorting types (case
281 insensitive):
282
283 thread Uses thread() to sort the messages
284 date Sort (numerically) by the article time
285 time Sort (numerically) by the article time
286 lines Sort (numerically) by lines, then by time
287 (other) Sort (with 'cmp') based on the value of the specified
288 field, ie sort by 'From' or 'Subject', then by time
289
290 If C<SORTTYPE> is prefixed with a '-', then we will return the entries in
291 revere order.
292  
293 Returns the sorted array.
294  
295 =cut
296  
297 0 ▶sub sort {
Subroutine sort: not called CC=11 SCAR=48.8
Pod documented
298 0 ▶ my ($self, $sort, @entries) = @_; $sort ||= "";
Condition0%0/2
$sort ||= ""
l!l
00
MC/DC0%0/1
$sort ||= ""
$sort
Truth table0%0/2
A
A= $sort
Aresult
11
00
299 0 my ($reverse, $type) = $sort =~ m/^(\-?)(.*)$/;
300 0 ▶ $type ||= 'Number';
Condition0%0/2
$type ||= "Number"
l!l
00
MC/DC0%0/1
$type ||= "Number"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
301 0 my @return;
302 0 ▶ if (lc $type eq 'thread') { # thread them
Branch: 4 branches
BranchTrueFalseTotal
if (lc $type eq 'thread') { } 0 0 0
elsif (lc $type eq 'lines') { } 0 0 0
elsif (lc $type eq 'date' or lc $type eq 'time') { } 0 0 0
elsif (grep {lc $_ eq lc $type;} $self->fields) { } 0 0 0
303 0 @return = $self->thread(@entries);
304 } elsif (lc $type eq 'lines') {
305 @return = sort {
306 0 ▶ ( $a->values->{ucfirst lc $type} <=> $b->values->{ucfirst lc $type} )
Condition0%0/3
$a->values->{ucfirst lc $type} <=> $b->values->{ucfirst lc $type} || $a->time <=> $b->time
l!l&&r!l&&!r
000
MC/DC0%0/2
$a->values->{ucfirst lc $type} <=> $b->values->{ucfirst lc $type} || $a->time <=> $b->time
$a->values->{ucfirst lc $type} <=> $b->values->{ucfirst lc $type} $a->time <=> $b->time
Truth table0%0/3
A || B
A= $a->values->{ucfirst lc $type} <=> $b->values->{ucfirst lc $type}B= $a->time <=> $b->time
ABresult
1X1
011
000
307 || ( $a->time <=> $b->time ) } @entries;
308 ▶ } elsif ( lc $type eq 'date' || lc $type eq 'time' ) {
Condition0%0/3
lc $type eq "date" or lc $type eq "time"
l!l&&r!l&&!r
000
MC/DC0%0/2
lc $type eq "date" or lc $type eq "time"
lc $type eq "date" lc $type eq "time"
Truth table0%0/3
A or B
A= lc $type eq "date"B= lc $type eq "time"
ABresult
1X1
011
000
309 0 @return = sort { ( $a->time <=> $b->time ) } @entries;
310 0 } elsif ( grep { lc $_ eq lc $type } $self->fields ) {
311 @return = sort {
312 0 ▶ ( $a->values->{ucfirst lc $type} cmp $b->values->{ucfirst lc $type} )
Condition0%0/3
$a->values->{ucfirst lc $type} cmp $b->values->{ucfirst lc $type} || $a->time <=> $b->time
l!l&&r!l&&!r
000
MC/DC0%0/2
$a->values->{ucfirst lc $type} cmp $b->values->{ucfirst lc $type} || $a->time <=> $b->time
$a->values->{ucfirst lc $type} cmp $b->values->{ucfirst lc $type} $a->time <=> $b->time
Truth table0%0/3
A || B
A= $a->values->{ucfirst lc $type} cmp $b->values->{ucfirst lc $type}B= $a->time <=> $b->time
ABresult
1X1
011
000
313 || ( $a->time <=> $b->time ) } @entries;
314 } else {
315 0 @return = sort { $a->values->{Number} <=> $b->values->{Number} } @entries;
316 }
317 0 ▶ $reverse ? reverse @return : @return;
Branch: 1 branch
BranchTrueFalseTotal
$reverse ? : 0 0 0
318 }
319  
320 =item thread ( ENTRIES )
321  
322 Sort C<ENTRIES> by thread - that is, with articles that directly follow up
323 to a given article following the first article. The general algorithm:
324  
325 Sort ENTRIES by depth and time of posting.
326 For each entry, return the entry and its sorted children.
327 No article is returned twice.
328  
329 This doesn't quite work the way you'd expect it to; if the original parent
330 isn't there, any number of children may appear elsewhere, because there
331 was no common parent C<ENTRY> to hold things together. The only solution
332 I can see is to look at parents as well, sorting them but not printing
333 them, which isn't currently being done; I may do this in a future version
334 of this package.
335  
336 This function is fairly computationally intensive. It might be nice to
337 cache this information somehow in some applications; I suspect that this
338 would be a job for a different module, however. There's probably also
339 some computational cruft that I haven't looked for yet.
340  
341 =cut
342  
343 0 ▶sub thread {
Subroutine thread: not called CC=10 SCAR=47.0
Pod documented
344 0 my ($self, @entries) = @_;
345  
346 0 my %added;
347  
348 my @return;
349 0 foreach my $ent ( sort News::Overview::_bythread @entries ) {
350 0 ▶ next unless ref $ent;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ent 0 0 0
351 0 my $parent = $ent->id;
352 0 ▶ push @return, $ent unless ($added{$ent->id}++);
Branch: 1 branch
BranchTrueFalseTotal
unless $added{$ent->id}++ 0 0 0
353 0 my @children = $ent->children; my @tosort;
354 0 ▶ foreach (@children) { push @tosort, $_ unless $added{$_->id} }
Branch: 1 branch
BranchTrueFalseTotal
unless $added{$_->id} 0 0 0
355 0 ▶ next unless @tosort;
Branch: 1 branch
BranchTrueFalseTotal
unless @tosort 0 0 0
356 0 foreach my $item ( $self->thread(@tosort) ) {
357 0 ▶ next unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
358 # my $item = $$self{Article_By_ID}->{$_};
359 0 ▶ push @return, $item unless ($added{$item->id}++);
Branch: 1 branch
BranchTrueFalseTotal
unless $added{$item->id}++ 0 0 0
360 }
361 }
362
363 0 @return;
364 }
365  
366  
367 =back
368  
369 =head2 NNTP Functions
370  
371 These functions perform functions similar to those requested by Net::NNTP,
372 and are therefore useful for creating modules dedicated to getting this
373 information in other ways.
374  
375 =over 4
376  
377 =item overview_fmt ()
378  
379 Returns an array reference to the field names, in order, that are stored
380 in the Entries.
381  
382 =cut
383  
384 0 ▶sub overview_fmt { my ($self) = @_; ref $self ? $self->default : \@DEFAULT; }
Subroutine overview_fmt: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
385  
386 =item xover ( MESSAGESPEC [, FIELDS ] )
387  
388 Returns a hash reference where the keys are the message numbers and the
389 values are array references containing the overview fields for that
390 message. C<MESSAGESPEC> is parsed with B<Net::NNTP::Function>'s
391 messagespec() function to decide wich articles to get; C<FIELDS> is an
392 array of fields to retrieve, which (if not offered) will default to the
393 value of fields().
394  
395 We aren't currently dealing with the response if C<MESSAGESPEC> is a
396 message-ID (or empty); we're assuming that it's just numbers. This is
397 wrong.
398  
399 =cut
400  
401 0 ▶sub xover {
Subroutine xover: not called CC=10 SCAR=47.0
Pod documented
402 0 my ($self, $spec, @fields) = @_;
403 0 ▶ @fields = $self->fields unless scalar @fields;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @fields 0 0 0
404 0 my ($first, $last) = messagespec($spec);
405 # my ($first, $last) = split('-', $spec);
406 0 ▶ $first ||= 0;
Condition0%0/2
$first ||= 0
l!l
00
MC/DC0%0/1
$first ||= 0
$first
Truth table0%0/2
A
A= $first
Aresult
11
00
407 0 my %entries;
408 0 foreach my $key (keys %{$self->{Articles}}) {
409 0 ▶ next if $key < $first;
Branch: 1 branch
BranchTrueFalseTotal
if $key < $first 0 0 0
410 0 ▶ next unless ($last > 0 && $key <= $last);
Branch: 1 branch
BranchTrueFalseTotal
unless $last > 0 and $key <= $last 0 0 0
Condition0%0/3
$last > 0 and $key <= $last
!ll&&!rl&&r
000
MC/DC0%0/2
$last > 0 and $key <= $last
$last > 0 $key <= $last
Truth table0%0/3
A and B
A= $last > 0B= $key <= $last
ABresult
0X0
100
111
411  
412 0 my $entry = $$self{Articles}->{$key};
413 # Should be able to get the article by ID too
414 0 ▶ next unless $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry 0 0 0
415  
416 0 my @over;
417 0 foreach (@fields) {
418 0 ▶ next if $_ eq 'Number'; # Skip the 'Number' field
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "Number" 0 0 0
419 0 push @over, $entry->values->{$_}
420 }
421  
422 0 $entries{$key} = \@over;
423 }
424 0 \%entries;
425 }
426  
427 =back
428  
429 =head2 Printing Functions
430  
431 These functions offer printable versions of the overview information,
432 which can be used for long-term storage.
433  
434 =over 4
435  
436 =item print ( SORT [, FIELDS] )
437  
438 Makes a printable version of all of the Entries in the object. Sorts the
439 entries based on C<SORT>; C<FIELDS> describes which fields to output;
440 defaults to fields(). The saved fields are separated with tabs, with all
441 other whitespace trimmed. This is suitable for saving out to a file and
442 later reading back in with add_xover().
443  
444 Returns an array of lines of text containing the information in array
445 context, or in scalar context returns these lines joined with newlines.
446  
447 =cut
448  
449 0 ▶sub print {
Subroutine print: not called CC=4 SCAR=30.0
Pod documented
450 0 my ($self, $sort, @fields) = @_;
451 0 ▶ @fields = $self->fields unless scalar @fields;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @fields 0 0 0
452 0 my @return;
453 0 my @entries = $self->sort($sort, values %{$self->{Articles}});
454 0 foreach my $art (@entries) {
455 0 push @return, $self->print_entry($art, @fields);
456 }
457 0 ▶ wantarray ? @return : join("\n", @return);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
458 }
459  
460 =item print_entry ( ENTRY )
461  
462 Print a specific entry's worth of information, as described above.
463  
464 =cut
465  
466 0 ▶sub print_entry {
Subroutine print_entry: not called CC=5 SCAR=34.0
Pod documented
467 0 my ($self, $entry, @fields) = @_;
468 0 ▶ return "" unless ($entry && ref $entry);
Branch: 1 branch
BranchTrueFalseTotal
unless $entry and ref $entry 0 0 0
Condition0%0/3
$entry and ref $entry
!ll&&!rl&&r
000
MC/DC0%0/2
$entry and ref $entry
$entry ref $entry
Truth table0%0/3
A and B
A= $entryB= ref $entry
ABresult
0X0
100
111
469 0 ▶ @fields = $self->fields unless scalar @fields;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @fields 0 0 0
470 0 my @over;
471 0 foreach (@fields) { push @over, $entry->value($_) }
472 0 map { s/\s/ /g; } @over; # Trim all whitespace
473 0 join("\t", @over);
474 }
475  
476 =back
477  
478 =cut
479  
480 ###############################################################################
481 ### Internal Functions ########################################################
482 ###############################################################################
483  
484 ### _fields ( ${@heads} )
485 # Retuns canonical names for the fields header. Takes an arrayref,
486 # returns an array.
487 0 ▶sub _fields {
Subroutine _fields: not called CC=1 SCAR=6.9
488 0 my $heads = shift;
489 0 my @heads = @{$heads};
490 0 map { s/:.*//g; lc $_ } @heads;
491 0 @heads;
492 }
493  
494 ### _bythread ( $a, $b )
495 # Sort function, to do sorts by thread - this means depth first, then
496 # number. The actual "do children first" part is in thread().
497 0 ▶sub _bythread {
Subroutine _bythread: not called CC=2 SCAR=17.9
498 0 ▶ $a->depth <=> $b->depth
Branch: 1 branch
BranchTrueFalseTotal
$a->depth <=> $b->depth or $a->time <=> $b->time 0 0 0
499 ||
500 $a->time <=> $b->time
501 # $a->values->{Number} <=> $b->values->{Number}
502 }
503  
504 ### _bythread_basic ( $a, $b )
505 # More basic, depth-only search.
506 0 ▶sub _bythread_basic { $a->depth <=> $b->depth }
Subroutine _bythread_basic: not called CC=1 SCAR=6.9
507  
508 =head1 REQUIREMENTS
509  
510 News::Overview::Entry, News::Article, Net::NNTP::Functions
511  
512 =head1 SEE ALSO
513  
514 B<News::Overview::Entry>, B<News::Article>, B<Net::NNTP::Functions>
515  
516 =head1 NOTES
517  
518 This was originally designed to be used with News::Archive and kiboze.pl;
519 it eventually got dragged into News::Web as well, and so it became worth
520 making into a separate function. It also didn't quite fit into my newslib
521 project, since it might be worth optimizing this specifically in the
522 future. Aah, well.
523  
524 =head1 TODO
525  
526 We should build xhdr(), xpat(), and other Net::NNTP functions into here,
527 just like xover() and overview_fmt().
528  
529 It would be nice if there was a way to say "return 500 entries" in an
530 xover-type context, instead of "return 1 through 500"; sadly, since
531 Net::NNTP->xover() doesn't have this, so I'll have to work out some other
532 way to implement it.
533  
534 We should be able to limit what we're returning in some more logical
535 manner, ie with an SQL-type select() function - "return all entries posted
536 between x and y dates", or "return all entries posted by user z", or
537 whatever.
538  
539 =head1 AUTHOR
540  
541 Tim Skirvin <tskirvin@killfile.org>
542  
543 =head1 COPYRIGHT
544  
545 Copyright 2003 by Tim Skirvin <tskirvin@killfile.org>. This code may be
546 distributed under the same terms as Perl itself.
547  
548 =cut
549  
550 1 1;
551  
552 ###############################################################################
553 ### Version History ###########################################################
554 ###############################################################################
555 # v0.01b Fri Oct 10 11:32:39 CDT 2003
556 ### First commented version (above date indicates the start of the comments)
557 # v0.10b Fri Oct 10 15:25:43 CDT 2003
558 ### Took out some unnecessary code where necessary. Made a print_entry()
559 ### function.
560 # v0.11b Fri Oct 10 15:36:45 CDT 2003
561 ### Very minor documentation changes
562 # v0.12 Thu Apr 22 13:19:25 CDT 2004
563 ### No real changes; internal code layout.
↑ Summary Overview/Entry.pm »