| 1 | package WWW::RobotRules::AnyDBM_File; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use WWW::RobotRules (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | our @ISA = qw(WWW::RobotRules); | |||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '6.03'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use AnyDBM_File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Fcntl qw( O_CREAT O_RDWR ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 4 | my ($class, $ua, $file) = @_; | |||||||||||||||||||||||||||
| 14 | 4 | ▶ | Carp::croak('WWW::RobotRules::AnyDBM_File filename required') unless $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 17 | 4 | $self->{'filename'} = $file; | |||||||||||||||||||||||||||
| 18 | 4 | ▶ | tie %{$self->{'dbm'}}, 'AnyDBM_File', $file, O_CREAT | O_RDWR, 0600 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | or Carp::croak("Can't open $file: $!"); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | ▶ | if ($ua) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 2 | $self->agent($ua); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | else { | ||||||||||||||||||||||||||||
| 25 | # Try to obtain name from DBM file | ||||||||||||||||||||||||||||
| 26 | 2 | $ua = $self->{'dbm'}{"|ua-name|"}; | |||||||||||||||||||||||||||
| 27 | 2 | ▶ | Carp::croak("No agent name specified") unless $ua; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 3 | $self; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 5 | ▶ | sub agent { | ||||||||||||||||||||||||||
|
Subroutine
agent: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 5 | my ($self, $newname) = @_; | |||||||||||||||||||||||||||
| 35 | 5 | my $old = $self->{'dbm'}{"|ua-name|"}; | |||||||||||||||||||||||||||
| 36 | 5 | ▶ | if (defined $newname) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 2 | $newname =~ s!/?\s*\d+.\d+\s*$!!; # loose version | |||||||||||||||||||||||||||
| 38 | 2 | ▶ | unless ($old && $old eq $newname) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$old and $old eq $newname
MC/DC0%0/2
$old and $old eq $newname
$old
$old eq $newname
Truth table66%2/3
A and B
A= $oldB= $old eq $newname
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Old info is now stale. Clear all keys through the tied | ||||||||||||||||||||||||||||
| 41 | # interface rather than untie+tie(O_TRUNC), which is a | ||||||||||||||||||||||||||||
| 42 | # symlink-follow TOCTOU on the DBM-backing file(s). | ||||||||||||||||||||||||||||
| 43 | 2 | %{$self->{'dbm'}} = (); | |||||||||||||||||||||||||||
| 44 | 2 | $self->{'dbm'}{"|ua-name|"} = $newname; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 5 | $old; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 5 | ▶ | sub no_visits { | ||||||||||||||||||||||||||
|
Subroutine
no_visits: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 5 | my ($self, $netloc) = @_; | |||||||||||||||||||||||||||
| 52 | 5 | my $t = $self->{'dbm'}{"$netloc|vis"}; | |||||||||||||||||||||||||||
| 53 | 5 | ▶ | return 0 unless $t; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 4 | (split(/;\s*/, $t))[0]; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | sub last_visit { | ||||||||||||||||||||||||||
|
Subroutine
last_visit: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 2 | my ($self, $netloc) = @_; | |||||||||||||||||||||||||||
| 59 | 2 | my $t = $self->{'dbm'}{"$netloc|vis"}; | |||||||||||||||||||||||||||
| 60 | 2 | ▶ | return undef unless $t; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 2 | (split(/;\s*/, $t))[1]; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 6 | ▶ | sub fresh_until { | ||||||||||||||||||||||||||
|
Subroutine
fresh_until: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 6 | my ($self, $netloc, $fresh) = @_; | |||||||||||||||||||||||||||
| 66 | 6 | my $old = $self->{'dbm'}{"$netloc|exp"}; | |||||||||||||||||||||||||||
| 67 | 6 | ▶ | if ($old) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 3 | $old =~ s/;.*//; # remove cleartext | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 6 | ▶ | if (defined $fresh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 2 | $fresh .= "; " . localtime($fresh); | |||||||||||||||||||||||||||
| 72 | 2 | $self->{'dbm'}{"$netloc|exp"} = $fresh; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 6 | $old; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 4 | ▶ | sub visit { | ||||||||||||||||||||||||||
|
Subroutine
visit: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | 4 | my ($self, $netloc, $time) = @_; | |||||||||||||||||||||||||||
| 79 | 4 | ▶ | $time ||= time; | ||||||||||||||||||||||||||
|
Condition100%2/2
$time ||= time
MC/DC100%1/1
$time ||= time
$time
Truth table100%2/2
A
A= $time
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 4 | my $count = 0; | |||||||||||||||||||||||||||
| 82 | 4 | my $old = $self->{'dbm'}{"$netloc|vis"}; | |||||||||||||||||||||||||||
| 83 | 4 | ▶ | if ($old) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 2 | my $last; | |||||||||||||||||||||||||||
| 85 | 2 | ($count, $last) = split(/;\s*/, $old); | |||||||||||||||||||||||||||
| 86 | 2 | ▶ | $time = $last if $last > $time; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 4 | $count++; | |||||||||||||||||||||||||||
| 89 | 4 | $self->{'dbm'}{"$netloc|vis"} = "$count; $time; " . localtime($time); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 4 | ▶ | sub push_rules { | ||||||||||||||||||||||||||
|
Subroutine
push_rules: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 93 | 4 | my ($self, $netloc, @rules) = @_; | |||||||||||||||||||||||||||
| 94 | 4 | my $cnt = 1; | |||||||||||||||||||||||||||
| 95 | 4 | ▶ | $cnt++ while $self->{'dbm'}{"$netloc|r$cnt"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 4 | foreach (@rules) { | |||||||||||||||||||||||||||
| 98 | 6 | $self->{'dbm'}{"$netloc|r$cnt"} = $_; | |||||||||||||||||||||||||||
| 99 | 6 | $cnt++; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 4 | ▶ | sub clear_rules { | ||||||||||||||||||||||||||
|
Subroutine
clear_rules: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 4 | my ($self, $netloc) = @_; | |||||||||||||||||||||||||||
| 105 | 4 | my $cnt = 1; | |||||||||||||||||||||||||||
| 106 | 4 | ▶ | while ($self->{'dbm'}{"$netloc|r$cnt"}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 4 | delete $self->{'dbm'}{"$netloc|r$cnt"}; | |||||||||||||||||||||||||||
| 108 | 4 | $cnt++; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 4 | ▶ | sub rules { | ||||||||||||||||||||||||||
|
Subroutine
rules: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 113 | 4 | my ($self, $netloc) = @_; | |||||||||||||||||||||||||||
| 114 | 4 | my @rules = (); | |||||||||||||||||||||||||||
| 115 | 4 | my $cnt = 1; | |||||||||||||||||||||||||||
| 116 | 4 | while (1) { | |||||||||||||||||||||||||||
| 117 | 12 | my $rule = $self->{'dbm'}{"$netloc|r$cnt"}; | |||||||||||||||||||||||||||
| 118 | 12 | ▶ | last unless $rule; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 8 | push(@rules, $rule); | |||||||||||||||||||||||||||
| 120 | 8 | $cnt++; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | 4 | @rules; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub dump { } | ||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1 | 1; | |||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||