lib/News/Active/Entry.pm

filter: Statementstmt 20.6% 6 / 29 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 8.3% 1 / 12 Podpod 100% 11 / 11 totaltotal 17.1% 18 / 105 CC 20 SCAR 32.5
CC
20
Cov
9%
new
72.0
first
12.0
final
12.0
CRAP 25.8
« lib/News/GroupInfo.pm ↑ Summary lib/News/GroupInfo/Entry.pm »
1 1 $VERSION = "0.10";
2 package News::Active::Entry;
3 1 our $VERSION = "0.10";
4  
5 # -*- Perl -*- # Wed Apr 28 08:59:14 CDT 2004
6 ###############################################################################
7 # Written by Tim Skirvin <tskirvin@killfile.org>. Copyright 2003-2004,
8 # Tim Skirvin. Redistribution terms are below.
9 ###############################################################################
10  
11 =head1 NAME
12  
13 News::Active::Entry - an object for storing specific active file information
14  
15 =head1 SYNOPSIS
16  
17 use News::Active::Entry;
18 use News::Active;
19  
20 my $item = new News::Active::Entry("humanities.philosophy.objectivism");
21 $item->add_article(1);
22 my $string = $item->output;
23  
24 See below for more specific information about related functions.
25  
26 =head1 DESCRIPTION
27  
28 News::Active::Entry contains the actual active file entries for
29 News::Active. Each entry consists of a group name, flags, and information
30 about the article numbers in the group. Within that, it is a very simple
31 module (significantly more lines dedicated to documentation than actual
32 code).
33  
34 =head1 USAGE
35  
36 News::Active::Entry is accessed through the following functions:
37  
38 =cut
39  
40 ###############################################################################
41 ### main() ####################################################################
42 ###############################################################################
43  
44 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 =head2 Functions
47  
48 =over 4
49  
50 =item new ( STRING )
51  
52 Creates and returns a new News::Active::Entry object. C<STRING> is a
53 scalar containing the group name, first article, final article, group
54 flags, and article count for the given group, separated by '::'.
55  
56 Only the group name is really required; the rest will be worked on on
57 their own. Therefore, just passing in the group name will work fine.
58  
59 =cut
60  
61 0 ▶sub new {
Subroutine new: not called CC=8 SCAR=42.8
Pod documented
62 0 my ($proto, $string) = @_;
63 0 my ($group, $first, $final, $flags, $count) = split('::', $string);
64 0 ▶ return undef unless $group;
Branch: 1 branch
BranchTrueFalseTotal
unless $group 0 0 0
65 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
66 0 ▶ my $self = {
Condition0%0/10
$count || 0
l!l
00
$first || 0
l!l
00
$final || 0
l!l
00
$flags || 'y'
l!l
00
$group || ''
l!l
00
MC/DC0%0/1
$count || 0
$count
MC/DC0%0/1
$first || 0
$first
MC/DC0%0/1
$final || 0
$final
MC/DC0%0/1
$flags || 'y'
$flags
MC/DC0%0/1
$group || ''
$group
Truth table0%0/2
A
A= $count
Aresult
11
00
Truth table0%0/2
A
A= $first
Aresult
11
00
Truth table0%0/2
A
A= $final
Aresult
11
00
Truth table0%0/2
A
A= $flags
Aresult
11
00
Truth table0%0/2
A
A= $group
Aresult
11
00
67 'count' => $count || 0,
68 'first' => $first || 0,
69 'final' => $final || 0,
70 'flags' => $flags || 'y',
71 'name' => $group || '',
72 };
73 0 bless $self, $class;
74 }
75  
76 =item first ( [NUMBER] )
77  
78 =item final ( [NUMBER] )
79  
80 =item count ( [NUMBER] )
81  
82 =item name ( [STRING] )
83  
84 =item flags ( [STRING] )
85  
86 Returns the relevant information from the object, as indicated above. If
87 an argument is passed to these functions, then the value is set to that
88 value; otherwise, we just return the existing value.
89  
90 =cut
91  
92 0 ▶sub first { defined $_[1] ? $_[0]->{first} = $_[1] : $_[0]->{first} || 0 }
Subroutine first: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
Condition0%0/2
$_[0]{"first"} or 0
l!l
00
MC/DC0%0/1
$_[0]{"first"} or 0
$_[0]{"first"}
Truth table0%0/2
A
A= $_[0]{"first"}
Aresult
11
00
93 0 ▶sub final { defined $_[1] ? $_[0]->{final} = $_[1] : $_[0]->{final} || 0 }
Subroutine final: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
Condition0%0/2
$_[0]{"final"} or 0
l!l
00
MC/DC0%0/1
$_[0]{"final"} or 0
$_[0]{"final"}
Truth table0%0/2
A
A= $_[0]{"final"}
Aresult
11
00
94 0 ▶sub count { defined $_[1] ? $_[0]->{count} = $_[1] : $_[0]->{count} || 0 }
Subroutine count: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
Condition0%0/2
$_[0]{"count"} or 0
l!l
00
MC/DC0%0/1
$_[0]{"count"} or 0
$_[0]{"count"}
Truth table0%0/2
A
A= $_[0]{"count"}
Aresult
11
00
95 0 ▶sub name { defined $_[1] ? $_[0]->{name} = $_[1] : $_[0]->{name} || "" }
Subroutine name: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
Condition0%0/2
$_[0]{"name"} or ""
l!l
00
MC/DC0%0/1
$_[0]{"name"} or ""
$_[0]{"name"}
Truth table0%0/2
A
A= $_[0]{"name"}
Aresult
11
00
96 0 ▶sub flags { defined $_[1] ? $_[0]->{flags} = $_[1] : $_[0]->{flags} || "" }
Subroutine flags: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
Condition0%0/2
$_[0]{"flags"} or ""
l!l
00
MC/DC0%0/1
$_[0]{"flags"} or ""
$_[0]{"flags"}
Truth table0%0/2
A
A= $_[0]{"flags"}
Aresult
11
00
97  
98 =item arrayref ()
99  
100 Returns an array reference containing C<final()>, C<first()>, and
101 C<flags()> (the same information stored by INN's active file).
102  
103 =cut
104  
105 0 ▶sub arrayref {
Subroutine arrayref: not called CC=1 SCAR=6.9
Pod documented
106 0 my ($self) = @_;
107 0 [ $self->final, $self->first, $self->flags ];
108 }
109  
110 =item print ()
111  
112 Makes a human-readable string containing the information from name(),
113 first(), final(), flags(), and count().
114  
115 =cut
116  
117 0 ▶sub print {
Subroutine print: not called CC=1 SCAR=6.9
Pod documented
118 0 my ($self) = @_;
119 0 sprintf("%-41s %010d %010d %5s %010d",
120 $self->name, $self->first, $self->final, $self->flags, $self->count);
121 }
122  
123 =item add_article ( [COUNT] )
124  
125 Indicates that we've added a single article to the given newsgroup, by
126 incrementing both final() and count() by C<COUNT> (defaults to 1).
127 first() is set to one if it was not set. Returns the number of articles
128 we added.
129  
130 =cut
131  
132 0 ▶sub add_article {
Subroutine add_article: not called CC=3 SCAR=24.8
Pod documented
133 0 ▶ my ($self, $count) = @_; $count ||= 1;
Condition0%0/2
$count ||= 1
l!l
00
MC/DC0%0/1
$count ||= 1
$count
Truth table0%0/2
A
A= $count
Aresult
11
00
134 0 $$self{final} += $count; $$self{count} += $count;
135 0 ▶ $$self{first} ||= 1;
Condition0%0/2
$self->{"first"} ||= 1
l!l
00
MC/DC0%0/1
$self->{"first"} ||= 1
$self->{"first"}
Truth table0%0/2
A
A= $self->{"first"}
Aresult
11
00
136 0 $count;
137 }
138  
139 =item next_number ()
140  
141 Returns the next article number that we will be saving to.
142  
143 =cut
144  
145 0 ▶sub next_number { shift->{final} + 1 }
Subroutine next_number: not called CC=1 SCAR=6.9
Pod documented
146  
147 =item output ()
148  
149 Returns the string that is needed by new() - ie, a string containing
150 name(), first(), final(), flags(), and count() separated by '::'.
151  
152 =cut
153  
154 0 ▶sub output { join("::", $_[0]->name, $_[0]->first, $_[0]->final,
Subroutine output: not called CC=1 SCAR=6.9
Pod documented
155 $_[0]->flags, $_[0]->count ); }
156  
157 =back
158  
159 =cut
160  
161 1 1;
162  
163 =head1 REQUIREMENTS
164  
165 B<News::Active>
166  
167 =head1 SEE ALSO
168  
169 B<News::Active>
170  
171 =head1 AUTHOR
172  
173 Tim Skirvin <tskirvin@killfile.org>
174  
175 =head1 HOMEPAGE
176  
177 B<http://www.killfile.org/~tskirvin/software/news-archive/>
178  
179 B<http://www.killfile.org/~tskirvin/software/newslib/>
180  
181 =head1 LICENSE
182  
183 This code may be redistributed under the same terms as Perl itself.
184  
185 =head1 COPYRIGHT
186  
187 Copyright 2003-2004, Tim Skirvin.
188  
189 =cut
190  
191 ###############################################################################
192 ##### Version History #########################################################
193 ###############################################################################
194 # v0.10 Wed Apr 28 09:03:05 CDT 2004
195 ### First documented version; it's been working since last year, though.
« lib/News/GroupInfo.pm ↑ Summary lib/News/GroupInfo/Entry.pm »