| 1 | 1 | $VERSION = "0.02"; | |||||||||||||||||||
| 2 | package News::Overview::Entry; | ||||||||||||||||||||
| 3 | 1 | our $VERSION = "0.02"; | |||||||||||||||||||
| 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::Entry - an object for storing specific overview information | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | use News::Overview::Entry; | ||||||||||||||||||||
| 18 | use News::Overview; | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | my $article = new News::Article; | ||||||||||||||||||||
| 21 | # Populate News::Article somehow; | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | # Create a new News::Overview::Entry object | ||||||||||||||||||||
| 24 | my $msgid = $article->header('message-id'); | ||||||||||||||||||||
| 25 | my @refs = split(/\s+/, $article->header('references') || ""); | ||||||||||||||||||||
| 26 | my %other; | ||||||||||||||||||||
| 27 | foreach ( News::Overview->defaults ) { | ||||||||||||||||||||
| 28 | $other{$_} = $article->header($_) || ""; | ||||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | my $entry = News::Overview::Entry->new($msgid, \@refs, %other); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | See below for more specific information about related functions. | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | News::Overview::Entry is an object meant to hold overview information | ||||||||||||||||||||
| 37 | about a single news article - that is, the minimal information necessary | ||||||||||||||||||||
| 38 | to sort the article with other articles, as used by XOVER in the NNTP | ||||||||||||||||||||
| 39 | specification. It is primarily a helper class for use with | ||||||||||||||||||||
| 40 | News::Overview; see that manual page for more information. | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | =head1 USAGE | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | All of this object's usage is contained within its functions. | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =cut | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | ############################################################################### | ||||||||||||||||||||
| 50 | ### main() #################################################################### | ||||||||||||||||||||
| 51 | ############################################################################### | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 54 | 1 | ▶ | use Date::Parse; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =head2 Basic functions | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =over 4 | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =item new ( MSGID [, REFERENCES, OTHER] ) | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | Creates a new News::Overview::Entry object. C<MSGID> is the Message-ID of | ||||||||||||||||||||
| 63 | the object, and is required (the function will return undef if it's not | ||||||||||||||||||||
| 64 | present). | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | C<REFERENCES> is an arrayref that contains the message-IDs of the entry's | ||||||||||||||||||||
| 67 | parents. C<OTHER> is a hash of other information about the article, which | ||||||||||||||||||||
| 68 | are stored in the entry. | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 73 | 0 | my ($proto, $msgid, $refs, %other) = @_; | |||||||||||||||||||
| 74 | 0 | ▶ | return undef unless $msgid; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 0 | ▶ | $refs ||= []; | ||||||||||||||||||
|
Condition0%0/2
$refs ||= []
MC/DC0%0/1
$refs ||= []
$refs
Truth table0%0/2
A
A= $refs
| |||||||||||||||||||||
| 76 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 77 | my $self = { | ||||||||||||||||||||
| 78 | ID => $msgid, | ||||||||||||||||||||
| 79 | Values => { | ||||||||||||||||||||
| 80 | 'Message-ID' => $msgid, | ||||||||||||||||||||
| 81 | 0 | ▶ | 'References' => join(" ", reverse @{$refs}), | ||||||||||||||||||
|
Condition0%0/2
(@{$refs;})[0] || undef
MC/DC0%0/1
(@{$refs;})[0] || undef
(@{$refs;})[0]
Truth table0%0/2
A
A= (@{$refs;})[0]
| |||||||||||||||||||||
| 82 | %other | ||||||||||||||||||||
| 83 | }, | ||||||||||||||||||||
| 84 | 0 | Parent => (@{$refs})[0] || undef, | |||||||||||||||||||
| 85 | Children => {}, | ||||||||||||||||||||
| 86 | References => $refs, | ||||||||||||||||||||
| 87 | }; | ||||||||||||||||||||
| 88 | 0 | bless $self, $class; | |||||||||||||||||||
| 89 | 0 | $$self{Values}->{Newsgroups} = join(',', $self->newsgroups); | |||||||||||||||||||
| 90 | 0 | $self; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | =item id () | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | Returns the associated message-ID of the Entry. | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | ▶ | sub id { shift->{ID} || "" } | ||||||||||||||||||
|
Subroutine
id: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =item parent () | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | Returns the Entry's parent's message-ID, or undef if there isn't one. | ||||||||||||||||||||
| 104 | This is currently defined as "the last item in References". This isn't | ||||||||||||||||||||
| 105 | currently being used, and may change to something else. | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | ▶ | sub parent { shift->{Parent} || undef } | ||||||||||||||||||
|
Subroutine
parent: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | =item children () | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | Returns all of the children of the current Entry; each returned item is | ||||||||||||||||||||
| 114 | another News::Article::Entry object. Note that no children exist until | ||||||||||||||||||||
| 115 | they are added with add_child(). | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 0 | ▶ | sub children { | ||||||||||||||||||
|
Subroutine
children: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 120 | 0 | my @array = values %{shift->{Children}}; | |||||||||||||||||||
| 121 | 0 | ▶ | wantarray ? @array : \@array; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =item value ( FIELD ) | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | Returns the value of the information stired in C<FIELD> within the Entry. | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 0 | ▶ | sub value { my ($self, $field) = @_; $self->values->{$field} || ""; } | ||||||||||||||||||
|
Subroutine
value: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =item values ( ) | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | Returns a hashref containing all of the keys and values of the information | ||||||||||||||||||||
| 135 | associated with the Entry. | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | =cut | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 0 | ▶ | sub values { shift->{Values} } | ||||||||||||||||||
|
Subroutine
values: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | =back | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | =head2 Additional Information | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | These functions offer additional information about the Entry, generally by | ||||||||||||||||||||
| 146 | parsing the above information. | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =over 4 | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | =item depth () | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | Returns the "depth" of the Entry, ie the number references above the | ||||||||||||||||||||
| 153 | article. A parent article (one with no References) is depth 0. | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | =cut | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 0 | ▶ | sub depth { ( scalar @{shift->{References}} ) || 0 } | ||||||||||||||||||
|
Subroutine
depth: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =item time ( ) | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | Returns the time, in seconds since the epoch, that the Entry says it was | ||||||||||||||||||||
| 162 | posted at (generated by parsing the Date header; will default to 0). | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | This information is cached for later use within the item. | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =cut | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | 0 | ▶ | sub time { | ||||||||||||||||||
|
Subroutine
time: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 169 | 0 | my $self = shift; | |||||||||||||||||||
| 170 | 0 | ▶ | unless ($$self{Time}) { $$self{Time} = str2time($self->values->{Date}) } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 171 | 0 | $$self{Time}; | |||||||||||||||||||
| 172 | } | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | =item newsgroups () | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | Returns the newsgroups associated with the entry, either by parsing the | ||||||||||||||||||||
| 177 | Newsgroups field or Xref. Returns an array of associated newsgroups. | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | =cut | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | 0 | ▶ | sub newsgroups { | ||||||||||||||||||
|
Subroutine
newsgroups: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 182 | 0 | my ($self) = @_; | |||||||||||||||||||
| 183 | 0 | ▶ | if (my $groups = $self->value('Newsgroups') ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 184 | 0 | my (@groups) = split(/\s+/, $groups); | |||||||||||||||||||
| 185 | 0 | return @groups; | |||||||||||||||||||
| 186 | } elsif ( my $xref = $self->value('Xref') ) { | ||||||||||||||||||||
| 187 | 0 | my ($server, @groups) = split(/\s+/, $xref); | |||||||||||||||||||
| 188 | 0 | map { s/:.*//g } @groups; | |||||||||||||||||||
| 189 | 0 | return @groups; | |||||||||||||||||||
| 190 | } else { | ||||||||||||||||||||
| 191 | 0 | return (); | |||||||||||||||||||
| 192 | } | ||||||||||||||||||||
| 193 | } | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | =back | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | =head2 Manipulation Functions | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | Besides new(), these functions are the only ones that actually modify the | ||||||||||||||||||||
| 200 | Entry in a notable way. | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | =over 4 | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | =item add_child ( CHILDREN ) | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | Add children to the given item, each of which is a News::Overview::Entry | ||||||||||||||||||||
| 207 | object. These are later accessed with children(). This is useful for | ||||||||||||||||||||
| 208 | threading. | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | Returns the number of children that were successfully added. | ||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | =cut | ||||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | 0 | ▶ | sub add_child { | ||||||||||||||||||
|
Subroutine
add_child: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 215 | 0 | my ($self, @children) = @_; | |||||||||||||||||||
| 216 | 0 | my $start = scalar $self->children; | |||||||||||||||||||
| 217 | 0 | foreach (@children) { $$self{Children}->{$_->id} = $_; } | |||||||||||||||||||
| 218 | 0 | ( scalar $self->children ) - $start; | |||||||||||||||||||
| 219 | } | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | =head1 REQUIREMENTS | ||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | News::Overview, Date::Parse | ||||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | =head1 SEE ALSO | ||||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | B<News::Overview> | ||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | =head1 TODO | ||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | Use the parent() bit effectively. Make "pseudo-Entries", to make entries | ||||||||||||||||||||
| 232 | for articles that don't exist, to make threading more accurate. | ||||||||||||||||||||
| 233 | |||||||||||||||||||||
| 234 | =head1 AUTHOR | ||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | Tim Skirvin <tskirvin@killfile.org> | ||||||||||||||||||||
| 237 | |||||||||||||||||||||
| 238 | =head1 COPYRIGHT | ||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | Copyright 2003 by Tim Skirvin <tskirvin@killfile.org>. This code may be | ||||||||||||||||||||
| 241 | distributed under the same terms as Perl itself. | ||||||||||||||||||||
| 242 | |||||||||||||||||||||
| 243 | =cut | ||||||||||||||||||||
| 244 | |||||||||||||||||||||
| 245 | 1 | 1; | |||||||||||||||||||
| 246 | |||||||||||||||||||||
| 247 | ############################################################################### | ||||||||||||||||||||
| 248 | ### Version History ########################################################### | ||||||||||||||||||||
| 249 | ############################################################################### | ||||||||||||||||||||
| 250 | # v0.01b Fri Oct 10 11:29:51 CDT 2003 | ||||||||||||||||||||
| 251 | ### First commented version (above date indicates the start of the comments). | ||||||||||||||||||||
| 252 | # v0.12 Thu Apr 22 13:19:25 CDT 2004 | ||||||||||||||||||||
| 253 | ### No real changes; internal code layout. | ||||||||||||||||||||