blib/script/suggest

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« blib/script/check-page ↑ Summary blib/script/copy-list »
1 #!/usr/local/bin/perl
2  
3 =head1 NAME
4  
5 suggest - suggest alternatives to a link
6  
7 =head1 SYNOPSIS
8  
9 suggest first-link-name suggestion....
10  
11 =head1 DESCRIPTION
12  
13 This program records alternatives to a link in a database. It is
14 designed to be able to run SUID and record these suggestions in a
15 central database where anyone can access them.
16  
17 It accepts no command line options beyond the first link name and the
18 suggestions.
19  
20 No attempt is made to guard against suggestions which are useless or
21 which point to sites which might upset the user. Possibly we should
22 log what suggestions are made.
23  
24 This program trusts the database who's filename is built into it.
25  
26 =head1 SEE ALSO
27  
28 L<verify-link-control(1)>; L<extract-links(1)>; L<build-schedule>
29 L<link-report(1)>; L<fix-link(1)>; L<link-report.cgi(1)>; L<fix-link.cgi>
30 L<suggest(1)>; L<link-report.cgi(1)>; L<configure-link-control>
31  
32 The LinkController manual in the distribution in HTML, info, or
33 postscript formats, included in the distribution.
34  
35 http://scotclimb.org.uk/software/linkcont - the
36 LinkController homepage.
37  
38 =cut
39  
40 2 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 0 ▶use DB_File;
Subroutine BEGIN: called CC=1 SCAR=2.6
42 use MLDBM qw(DB_File);
43 use WWW::Link;
44 use strict;
45 use vars qw($linkdatabase $link $changed);
46  
47 #Configuration - we go through %ENV, so you'd better not be running SUID
48 #eval to ignore if a file doesn't exist.. e.g. the system config
49  
50 use WWW::Link_Controller::ReadConf;
51  
52 use Getopt::Function; #don't need yet qw(maketrue makevalue);
53  
54 $::opthandler = new Getopt::Function
55 [ "version V>version",
56 "usage h>usage help>usage",
57 "help-opt=s",
58 "verbose:i v>verbose",
59 ], {};
60  
61 $::opthandler->std_opts;
62  
63 $::opthandler->check_opts;
64  
65 @::changelist = @ARGV;
66  
67 sub usage() {
68 print <<EOF;
69 suggest original-url new-url
70  
71 EOF
72 $::opthandler->list_opts;
73 print <<EOF;
74  
75 Make a suggestion for a URL for a link which could replace a broken one.
76 EOF
77 }
78  
79 sub version() {
80 print <<'EOF';
81 suggest version
82 $Id: suggest.pl,v 1.7 2001/11/22 15:33:21 mikedlr Exp $
83 EOF
84 }
85  
86  
87 # Our entire aim is to write to a database which the real user should
88 # have no write access to. We should probably check that they have
89 # read access. We should certainly check that the directory is secure
90 # and that the database is not a symlink.
91  
92 #FIXME filechecks
93  
94 die 'you must define the $::links configuration variable'
95 unless $::links;
96 $::linkdbm = tie %::links, "MLDBM", $links, O_RDWR, 0666, $::DB_HASH
97 or die $!;
98  
99 my $oldurl=shift;
100  
101 my $link=$::links{$oldurl} or die "couldn't find a link for your original url";
102 my $changed=0;
103 my $newurl;
104 while ( $newurl=shift ) {
105 if ( $link->add_suggestion($newurl) ) {
106 print "Link suggestion accepted. Thank you\n";
107 #FIXME logging of who and when.
108 $changed ++;
109 } else {
110 print "Already knew about that suggestion. Thanks though.\n";
111 }
112 }
113 $::links{$oldurl}=$link if $changed;
114  
115  
116  
« blib/script/check-page ↑ Summary blib/script/copy-list »