| 1 | # -*- Mode: Perl -*- | ||||||||||||||||||||||||||||
| 2 | # Group.pm -- | ||||||||||||||||||||||||||||
| 3 | # ITIID : $ITI$ $Header $__Header$ | ||||||||||||||||||||||||||||
| 4 | # Author : Ulrich Pfeifer | ||||||||||||||||||||||||||||
| 5 | # Created On : Sat Sep 28 16:33:51 1996 | ||||||||||||||||||||||||||||
| 6 | # Last Modified By: Ulrich Pfeifer | ||||||||||||||||||||||||||||
| 7 | # Last Modified On: Sat Mar 15 13:44:15 1997 | ||||||||||||||||||||||||||||
| 8 | # Language : CPerl | ||||||||||||||||||||||||||||
| 9 | # Update Count : 58 | ||||||||||||||||||||||||||||
| 10 | # Status : Unknown, Use with caution! | ||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||
| 12 | # (C) Copyright 1996, Universität Dortmund, all rights reserved. | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | package NNML::Group; | ||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use IO::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 0 | my $type = shift; | |||||||||||||||||||||||||||
| 21 | 0 | my %parm = @_; | |||||||||||||||||||||||||||
| 22 | 0 | my $self = {}; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | for (qw(name dir min max post ctime)) { | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | $self->{'_'.$_} = $parm{$_} if exists $parm{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 0 | $self->{_time} = 0; | |||||||||||||||||||||||||||
| 28 | 0 | bless $self, $type; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub max { $_[0]->{_max}}; | ||||||||||||||||||||||||||
|
Subroutine
max: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub min { $_[0]->{_min}}; | ||||||||||||||||||||||||||
|
Subroutine
min: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub name { $_[0]->{_name}}; | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub post { $_[0]->{_post}}; | ||||||||||||||||||||||||||
|
Subroutine
post: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub ctime { $_[0]->{_ctime}}; | ||||||||||||||||||||||||||
|
Subroutine
ctime: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub dir { $_[0]->{_dir}}; | ||||||||||||||||||||||||||
|
Subroutine
dir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 0 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 40 | 0 | my $ano = ++$self->{_max}; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ($id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | $self->{_byid}->{$id} = $ano; | |||||||||||||||||||||||||||
| 44 | 0 | $self->{_byno}->{$ano} = $id; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 0 | $ano; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub article_by_id { | ||||||||||||||||||||||||||
|
Subroutine
article_by_id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 0 | my ($self, $msgid) = @_; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | $self->_update; | |||||||||||||||||||||||||||
| 53 | 0 | $self->{_byid}->{$msgid}; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub article_by_no { | ||||||||||||||||||||||||||
|
Subroutine
article_by_no: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 0 | my ($self, $ano) = @_; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | $self->_update; | |||||||||||||||||||||||||||
| 60 | 0 | $self->{_byno}->{$ano}; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub overview {$_[0]->{_dir}. '/.overview'} | ||||||||||||||||||||||||||
|
Subroutine
overview: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub _update { | ||||||||||||||||||||||||||
|
Subroutine
_update: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 66 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # Assume '.overview' has not changed if 'active' was not | ||||||||||||||||||||||||||||
| 69 | # modified. The implementation is not correct since a stat() for | ||||||||||||||||||||||||||||
| 70 | # active is not forced - but it saves many stat() calls. A stat() | ||||||||||||||||||||||||||||
| 71 | # call for 'active' is forced when message id's are used. Therfore | ||||||||||||||||||||||||||||
| 72 | # this is quite good. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if (NNML::Active::last_change() > $self->{_time}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | my $mtime = (stat($self->overview))[9]; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $self->_read_overview if $mtime > $self->{_time}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub _read_overview { | ||||||||||||||||||||||||||
|
Subroutine
_read_overview: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 82 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 83 | 0 | $self->{_time} = time; | |||||||||||||||||||||||||||
| 84 | 0 | $self->{_byid} = {}; | |||||||||||||||||||||||||||
| 85 | 0 | $self->{_byno} = {}; | |||||||||||||||||||||||||||
| 86 | 0 | $self->{_ctime} = (stat($self->overview))[9]; | |||||||||||||||||||||||||||
| 87 | 0 | my $fh = new IO::File "<" . $self->overview; | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | die "Could not read overview file" unless defined $fh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | my $line; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | while (defined ($line = <$fh>)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | chomp($line); | |||||||||||||||||||||||||||
| 92 | 0 | my($ano, $subject, $from, $date, $id, $references, $chars, $lines, $xref) | |||||||||||||||||||||||||||
| 93 | = split /\t/, $line; | ||||||||||||||||||||||||||||
| 94 | 0 | $id =~ s/^\s+//; $id =~ s/\s+$//; | |||||||||||||||||||||||||||
| 95 | 0 | $self->{_byid}->{$id} = $ano; | |||||||||||||||||||||||||||
| 96 | 0 | $self->{_byno}->{$ano} = $id; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 0 | $fh->close; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | # This assumes that articles are stored in increasing order. | ||||||||||||||||||||||||||||
| 102 | # It deserves tuning (binary search). | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub newnews { | ||||||||||||||||||||||||||
|
Subroutine
newnews: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 0 | my ($self, $time) = @_; | |||||||||||||||||||||||||||
| 105 | 0 | my %result; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | $self->_update; | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | return () if $self->{_ctime} < $time; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | my $ano; | |||||||||||||||||||||||||||
| 110 | 0 | my $dir = $self->{_dir}.'/'; | |||||||||||||||||||||||||||
| 111 | 0 | ▶ | for ($ano=$self->max;$ano>=$self->min;$ano--) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | my $file = $dir.$ano; | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | if (-e $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | my $ctime = (stat($file))[9]; | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($ctime >= $time) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $result{$self->{_byno}->{$ano}} = $ctime; | |||||||||||||||||||||||||||
| 117 | } else { | ||||||||||||||||||||||||||||
| 118 | 0 | last; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | 0 | %result; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub xover { | ||||||||||||||||||||||||||
|
Subroutine
xover: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 0 | my ($self,$min,$max) = @_; | |||||||||||||||||||||||||||
| 127 | 0 | my $result; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $min ||= $self->min; | ||||||||||||||||||||||||||
|
Condition0%0/3
$min ||= $self->min
MC/DC0%0/2
$min ||= $self->min
$min
$self->min
Truth table0%0/3
A ||= B
A= $minB= $self->min
| |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $max ||= $self->max; | ||||||||||||||||||||||||||
|
Condition0%0/3
$max ||= $self->max
MC/DC0%0/2
$max ||= $self->max
$max
$self->max
Truth table0%0/3
A ||= B
A= $maxB= $self->max
| |||||||||||||||||||||||||||||
| 131 | 0 | my $fh = new IO::File "<" . $self->overview; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | die "Could not read overview file" unless defined $fh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | my $line; | |||||||||||||||||||||||||||
| 134 | 0 | ▶ | while (defined ($line = <$fh>)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ($line =~ /^(\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ($1 >= $min and $1 <= $max) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$1 >= $min and $1 <= $max
MC/DC0%0/2
$1 >= $min and $1 <= $max
$1 >= $min
$1 <= $max
Truth table0%0/3
A and B
A= $1 >= $minB= $1 <= $max
| |||||||||||||||||||||||||||||
| 137 | 0 | $result .= $line; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | 0 | $fh->close; | |||||||||||||||||||||||||||
| 142 | 0 | $result; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 146 | 0 | my ($self, $ano) = @_; | |||||||||||||||||||||||||||
| 147 | 0 | my $file = $self->{_dir} . "/$ano"; | |||||||||||||||||||||||||||
| 148 | 0 | ▶ | if (-e $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 0 | my $date = ((stat($file))[10]); | |||||||||||||||||||||||||||
| 150 | 0 | my $fh = new IO::File "<" . $file; | |||||||||||||||||||||||||||
| 151 | 0 | ▶ | return unless $fh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 0 | local($/); | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | my ($head, $body) = split /^\r?\n/m, <$fh>, 2; | |||||||||||||||||||||||||||
| 155 | 0 | return $head, $body, $date; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 160 | 0 | my ($self, $ano) = @_; | |||||||||||||||||||||||||||
| 161 | 0 | my $file = $self->{_dir} . "/$ano"; | |||||||||||||||||||||||||||
| 162 | 0 | my ($result, $line); | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if (-e $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | unlink $file or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | 0 | my $overview = $self->overview; | |||||||||||||||||||||||||||
| 168 | 0 | my $backup = $self->overview . '~'; | |||||||||||||||||||||||||||
| 169 | 0 | ▶ | rename ($overview, $backup) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | my $in = new IO::File "<" . $backup; | |||||||||||||||||||||||||||
| 171 | 0 | my $out = new IO::File ">" . $overview; | |||||||||||||||||||||||||||
| 172 | 0 | ▶ | return unless $in and $out; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$in and $out
MC/DC0%0/2
$in and $out
$in
$out
Truth table0%0/3
A and B
A= $inB= $out
| |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | while (defined ($line = <$in>)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ($line =~ /^(\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ($1 == $ano) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 0 | $result++; | |||||||||||||||||||||||||||
| 177 | 0 | next; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | 0 | $out->print($line); | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | 0 | $in->close; | |||||||||||||||||||||||||||
| 183 | 0 | $out->close; | |||||||||||||||||||||||||||
| 184 | 0 | return($result); | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 1 | 1; | |||||||||||||||||||||||||||