dpeek.pl untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 3 Podpod n/a totaltotal 0.0% 0 / 69 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/perl
2 use lib ".";
3  
4 # peek.pl - sample script to illustrate how the WebCache::Digest code can
5 # can be used to look up URLs in cache digests downloaded off
6 # the Net or uploaded from disk
7  
8 # $Id: dpeek.pl,v 1.1 1999/03/12 17:55:33 martin Exp martin $
9  
10 use Getopt::Std;
11 use WebCache::Digest;
12  
13 getopts("dhuv");
14  
15 $d = new WebCache::Digest;
16  
17 if ($#ARGV == 1) {
18 $host = $ARGV[0] || "localhost",
19 $port = $ARGV[1] || "3128";
20  
21 $d->fetch(host => $host, port => $port);
22 print "> fetching digest from $host:$port\n" if $opt_d;
23 } elsif ($#ARGV == 0) {
24 $d->load($ARGV[0]);
25 print "> loading from $ARGV[0]\n" if $opt_d;
26 }
27  
28 print STDOUT $d->dump_header if $opt_d || $opt_h;
29 exit if $opt_h;
30  
31 $|=1;
32  
33 print "> time is: " . localtime(time) . "\n" if $opt_d;
34  
35 while(<STDIN>) {
36 chop;
37 s/\s+/ /g;
38 if ($opt_u) {
39 $url = $_;
40 } else {
41 @bits = split;
42 $url = $bits[6];
43 }
44  
45 if ($opt_v) {
46 if ($d->lookup("GET", $url)) {
47 print "HIT $url\n";
48 } else {
49 print "MISS $url\n";
50 }
51 } else {
52 $d->lookup("GET", $url);
53 }
54 }
55  
56 print "> time is: " . localtime(time) . "\n" if $opt_d;
57  
58  
59 =head1 NAME
60  
61 peek.pl - look up URLs in Cache Digests
62  
63 =head1 SYNOPSIS
64  
65 echo http://www.w3.org | dpeek.pl -duv reboot.wwwcache.ja.net 3128
66 dpeek.pl -h saved-digest < old-access-log
67 zcat old-access-log.gz | dpeek.pl -v saved-digest
68  
69 =head1 DESCRIPTION
70  
71 This program lets you look up URLs (the HTTP 'GET' method is assumed)
72 in Cache Digests which are either fetched via HTTP or loaded from a
73 file. The list of URLs should be supplied via STDIN, and can be in
74 Squid log file format (the default), or simply a list of URLs (when
75 the B<-u> argument is supplied).
76  
77 =head1 OPTIONS
78  
79 =over 4
80  
81 =item -d
82  
83 Debug mode - causes helpful debugging messages to be printed
84  
85 =item -h
86  
87 Print the Digest header details out, e.g. version number and number
88 of URLs in Digest, then exit.
89  
90 =item -u
91  
92 Input is a list of URLs rather than Squid log file format.
93  
94 =item -v
95  
96 Verbose mode - causes each URL being looked up to be printed to STDOUT,
97 along with a hit/miss indicator.
98  
99 =back
100  
101 =head1 COPYRIGHT
102  
103 Copyright (c) 1999, Martin Hamilton. All rights reserved.
104  
105 This program is free software; you can redistribute it and/or modify
106 it under the same terms as Perl itself.
107  
108 It was developed by the JANET Web Cache Service, which is funded by
109 the Joint Information Systems Committee (JISC) of the UK Higher
110 Education Funding Councils.
111  
112 =head1 AUTHOR
113  
114 Martin Hamilton E<lt>martinh@gnu.orgE<gt>
115