Active.pm

filter: Statementstmt 17.5% 26 / 148 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 37.5% 6 / 16 Podpod 0.0% 0 / 7 totaltotal 12.7% 32 / 251 CC 36 SCAR 54.1
CC
36
Cov
12%
accept_article
506.0
_read_active
20.0
_write_active
20.0
CRAP 224.6
↑ Summary Server.pm »
1 # -*- Mode: Perl -*-
2 # Active.pm --
3 # ITIID : $ITI$ $Header $__Header$
4 # Author : Ulrich Pfeifer
5 # Created On : Sat Sep 28 14:15:22 1996
6 # Last Modified By: Ulrich Pfeifer
7 # Last Modified On: Thu Feb 27 16:31:03 1997
8 # Language : CPerl
9 # Update Count : 86
10 # Status : Unknown, Use with caution!
11 #
12 # (C) Copyright 1996, Universität Dortmund, all rights reserved.
13 #
14  
15 package NNML::Active;
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use vars qw($VERSION @ISA @EXPORT_OK $ACTIVE);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 require Exporter;
20 1 @ISA = qw(Exporter);
21 1 @EXPORT_OK = qw($ACTIVE);
22  
23 1 ▶use NNML::Config qw($Config);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use NNML::Group;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 $VERSION = '0.01';
29 1 $ACTIVE = bless {}, 'NNML::Active';
30  
31 1 my %GROUP;
32 1 my $TIME = 0;
33  
34 0 ▶sub last_change { $TIME }
Subroutine last_change: not called CC=1 SCAR=6.9
Pod undocumented
35  
36 0 ▶sub _read_active {
Subroutine _read_active: not called CC=4 SCAR=30.0
37 0 %GROUP = ();
38 0 $TIME = time;
39  
40 0 my $fh = new IO::File "<" . $Config->active;
41 0 ▶ die "Could not read active file" unless defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 0 0
42 0 my $line;
43 0 ▶ while (defined ($line = <$fh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $fh)) 0 0 0
44 0 chomp($line);
45 0 my ($group, $max, $min, $post) = split ' ', $line;
46 0 my $dir = $group;
47 0 $dir =~ s:\.:/:g;
48 0 $dir = $Config->base . '/' . $dir;
49 0 ▶ if (-e $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $dir) 0 0 0
50 0 my $ctime = (stat($dir))[10];
51 0 $GROUP{$group} = NNML::Group->new(name => $group,
52 dir => $dir,
53 min => $min,
54 max => $max,
55 post => $post,
56 ctime => $ctime,
57 );
58 }
59 }
60 }
61  
62 0 ▶sub _write_active {
Subroutine _write_active: not called CC=4 SCAR=30.0
63 0 my $active = $Config->active;
64  
65 0 ▶ unless (rename $active, "$active~") {
Branch: 1 branch
BranchTrueFalseTotal
unless (rename $active, "$active~") 0 0 0
66 0 print "Could not backup '$active': $!\n";
67 0 return 0;
68 }
69 0 my $fh = new IO::File ">" . $active;
70 0 ▶ unless (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 0 0
71 0 print "Could not write active file\n";
72 0 return 0;
73 }
74 0 for (sort keys %GROUP) {
75 $fh->printf("%s %d %d %s\n", $_,
76 0 $GROUP{$_}->max, $GROUP{$_}->min, $GROUP{$_}->post,
77 )
78 }
79 0 $fh->close;
80 0 $TIME = time;
81 }
82  
83 0 ▶sub _update {
Subroutine _update: not called CC=2 SCAR=17.9
84 0 my $mtime = (stat($Config->active))[9];
85 0 ▶ _read_active if $mtime > $TIME;
Branch: 1 branch
BranchTrueFalseTotal
if $mtime > $TIME 0 0 0
86 }
87  
88 0 ▶sub group {
Subroutine group: not called CC=2 SCAR=17.9
Pod undocumented
89 0 my ($self, $group) = @_;
90  
91 0 _update;
92 0 ▶ if (exists $GROUP{$group}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GROUP{$group}) 0 0 0
93 0 return $GROUP{$group};
94 }
95 }
96  
97 0 ▶sub delete_group {
Subroutine delete_group: not called CC=2 SCAR=17.9
Pod undocumented
98 0 my ($self, $group) = @_;
99 0 my $dir;
100  
101 0 _update;
102 0 ▶ unless (exists $GROUP{$group}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GROUP{$group}) { } 0 0 0
103 0 return;
104 } else {
105 0 $dir = $GROUP{$group}->dir;
106 0 delete $GROUP{$group};
107 }
108 0 _write_active;
109 0 rmtree($dir,1,1);
110 }
111 0 ▶sub groups {
Subroutine groups: not called CC=1 SCAR=6.9
Pod undocumented
112 0 _update;
113 0 values %GROUP;
114 }
115  
116 0 ▶sub newgroups {
Subroutine newgroups: not called CC=3 SCAR=24.8
Pod undocumented
117 0 my ($self, $time) = @_;
118 0 my @result;
119  
120 0 _update;
121 0 for (keys %GROUP) {
122 # printf "%s %d %d\n", $_, $GROUP{$_}->ctime, $time;
123 0 ▶ if ($GROUP{$_}->ctime > $time) {
Branch: 1 branch
BranchTrueFalseTotal
if ($GROUP{$_}->ctime > $time) 0 0 0
124 0 unshift @result, $_;
125 }
126 }
127 0 @result;
128 }
129  
130 0 ▶sub list_match {
Subroutine list_match: not called CC=4 SCAR=30.0
Pod undocumented
131 0 my ($self, $expr) = @_;
132  
133 0 $expr =~ s/\./\\./g;
134 0 $expr =~ s/\*/.*/g;
135 0 my (@expr) = split /,/, $expr;
136  
137 0 _update;
138  
139 0 my $neg = join '|', grep s/^!//, @expr;
140 0 my $pos = join '|', grep /^[^!]/, @expr;
141  
142 #print "pos = $pos\n";
143 #print "neg = $neg\n";
144  
145 0 my @result;
146 0 for (sort keys %GROUP) {
147 0 ▶ next unless /^$pos$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^$pos$/ 0 0 0
148 0 ▶ next if /^$neg$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$neg$/ 0 0 0
149 0 push @result, $GROUP{$_};
150 }
151  
152 0 @result;
153 }
154  
155 0 ▶sub accept_article {
Subroutine accept_article: not called CC=22 SCAR=62.3
Pod undocumented
156 0 my ($self, $header, $head, $body, $create,
157 $afile, $extra_group, @groups) = @_;
158 0 my $group;
159 0 my $any_group = 0;
160 0 my $overwrite_file = $afile;
161 0 my %seen;
162
163 0 $self->_update;
164  
165 0 ▶ if ($afile and -e $afile) { # xaccept overwrites
Branch: 1 branch
BranchTrueFalseTotal
if ($afile and -e $afile) 0 0 0
Condition0%0/3
$afile and -e $afile
!ll&&!rl&&r
000
MC/DC0%0/2
$afile and -e $afile
$afile -e $afile
Truth table0%0/3
A and B
A= $afileB= -e $afile
ABresult
0X0
100
111
166 0 my $fh = new IO::File "> $afile";
167 0 ▶ unless (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 0 0
168 0 print "Could not write '$afile': $!\n";
169 0 return 0;
170 }
171 0 $fh->print($head, "\n", $body);
172 0 $fh->close;
173 }
174 0 for $group (@groups) {
175 0 ▶ next if $seen{$group}++; # do not insert twice
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$group}++ 0 0 0
176 0 ▶ unless (exists $GROUP{$group}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $GROUP{$group}) 0 0 0
177 0 ▶ next unless $create; # no permission to create group
Branch: 1 branch
BranchTrueFalseTotal
unless $create 0 0 0
178 0 my $dir = $group;
179 0 $dir =~ s:\.:/:g;
180 0 $dir = $Config->base . '/' . $dir;
181 0 ▶ unless (-d $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 0 0
182 0 ▶ unless (mkpath($dir,1,0700)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (mkpath($dir, 1, 448)) 0 0 0
183 0 print "Could not mkpath($dir).\n";
184 0 return 0;
185 }
186 }
187 0 $GROUP{$group} = NNML::Group->new(name => $group,
188 dir => $dir,
189 min => 1,
190 max => 0,
191 post => 'y',
192 ctime => time,
193 );
194 }
195 0 my $ov = $GROUP{$group}->overview;
196  
197 0 my $oano = $GROUP{$group}->article_by_id($header->{'message-id'});
198 0 ▶ my $ano = $oano || $GROUP{$group}->add($header->{'message-id'});
Condition0%0/3
$oano || $GROUP{$group}->add($header->{'message-id'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$oano || $GROUP{$group}->add($header->{'message-id'})
$oano $GROUP{$group}->add($header->{'message-id'})
Truth table0%0/3
A || B
A= $oanoB= $GROUP{$group}->add($header->{'message-id'})
ABresult
1X1
011
000
199 0 my $dir = $GROUP{$group}->dir;
200 0 my $file = "$dir/$ano";
201
202 0 ▶ if ($ano and $group eq $extra_group) { # force a copy
Branch: 1 branch
BranchTrueFalseTotal
if ($ano and $group eq $extra_group) { } 0 0 0
Condition0%0/3
$ano and $group eq $extra_group
!ll&&!rl&&r
000
MC/DC0%0/2
$ano and $group eq $extra_group
$ano $group eq $extra_group
Truth table0%0/3
A and B
A= $anoB= $group eq $extra_group
ABresult
0X0
100
111
203 0 $ano = $GROUP{$group}->add($header->{'message-id'});
204 0 $file = "$dir/$ano";
205 0 $oano = undef;
206 } else {
207 0 ▶ if (!$oano and -e $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $oano and -e $file) 0 0 0
Condition0%0/3
not $oano and -e $file
!ll&&!rl&&r
000
MC/DC0%0/2
not $oano and -e $file
not $oano -e $file
Truth table0%0/3
not(A) and B
A= not $oanoB= -e $file
ABresult
0X0
100
111
208 0 print "File '$file' already exists\n";
209 0 return 0;
210 }
211 }
212
213 # add overview entry if new article number
214 0 ▶ unless ($oano) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($oano) 0 0 0
215 0 my $fh = new IO::File ">> $ov";
216 0 ▶ unless (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 0 0
217 0 print "Could not write '$ov': $!\n";
218 0 return 0;
219 }
220 0 $header->{subject} =~ s/\s/ /;
221 $fh->printf("%d\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t\n",
222 $ano,
223 $header->{subject},
224 $header->{from},
225 $header->{date},
226 $header->{'message-id'},
227 $header->{references},
228 length($body),
229 $header->{lines},
230 0 $header->{xref});
231 0 $fh->close;
232 }
233 # add the article ...
234 0 ▶ if (defined $afile) { # as link
Branch: 1 branch
BranchTrueFalseTotal
if (defined $afile) { } 0 0 0
235 0 ▶ unless ($oano or link($afile, $file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($oano or link $afile, $file) 0 0 0
Condition0%0/3
$oano or link $afile, $file
l!l&&r!l&&!r
000
MC/DC0%0/2
$oano or link $afile, $file
$oano link $afile, $file
Truth table0%0/3
A or B
A= $oanoB= link $afile, $file
ABresult
1X1
011
000
236 0 print "Could not link '$file' to '$afile': $!\n";
237 0 return 0;
238 }
239 } else { # as copy
240 0 $afile = $file;
241 0 my $fh = new IO::File "> $file";
242 0 ▶ unless (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 0 0
243 0 print "Could not write '$file': $!\n";
244 0 return 0;
245 }
246 0 $fh->print($head, "\n", $body);
247 0 $fh->close;
248 }
249 0 $any_group++; # we posted to one group atleast
250 }
251 0 ▶ return $self->_write_active || $any_group;
Condition0%0/3
$self->_write_active || $any_group
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_write_active || $any_group
$self->_write_active $any_group
Truth table0%0/3
A || B
A= $self->_write_activeB= $any_group
ABresult
1X1
011
000
252 }
253  
254 1 1;
↑ Summary Server.pm »