blib/script/check-page

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
« requires.PL ↑ Summary blib/script/suggest »
1 #!/usr/local/bin/perl
2  
3 =head1 NAME
4  
5 check-page - check the links in a single HTML page and report problems
6  
7 =head1 DESCRIPTION
8  
9 This program reads an HTML page, from the command line arguments and
10 reports errors in it. It gives the line number of the error. One
11 useful feature is that the output is in the same format as various
12 other utilities (such as the gnu ones) which means that your editor
13 may well be able to understand it and move you to the correct line.
14  
15 In emacs, you can use this by using the following sequence
16  
17 M-x compile RET check-page [filename] RET
18  
19 Which will check the page and record the errors. You can then use
20  
21 M-`
22  
23 from within the file you are trying to get to the next error. For
24 more information about this see the emacs help on compiling.
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 HTML::LinkExtor;
44 use WWW::Link::Reporter::Compile;
45  
46 #Configuration - we go through %ENV, so you'd better not be running SUID
47 #eval to ignore if a file doesn't exist.. e.g. the system config
48  
49 use WWW::Link_Controller::ReadConf;
50 use WWW::Link_Controller::InfoStruc;
51 use WWW::Link_Controller::URL;
52  
53  
54 ##############################################################################
55 #start command line processing
56 use Getopt::Function qw(maketrue makevalue);
57  
58 use vars qw($not_perfect $redirect $since);
59  
60 $::redirect=0;
61 $::ignore_missing=0;
62 $::verbose=0;
63  
64 $::opthandler = new Getopt::Function
65 [ "version V>version",
66 "usage h>usage help>usage",
67 "help-opt=s",
68 "verbose:i v>verbose",
69 "",
70 "redirect r>redirect",
71 "ignore-missing m>ignore-missing",
72 "",
73 "link-index=s",
74 "link-database=s",
75 ],
76 {
77 "redirect" => [ \&maketrue,
78 "Report links which are redirected." ],
79 "ignore-missing" => [ \&maketrue,
80 "Don't complain about links which aren't in database." ],
81  
82 "link-index" => [ sub { $::link_index=$::value; },
83 "Use the given file as the index of which file has "
84 . "what link.",
85 "FILENAME" ],
86 "link-database" => [ sub { $::links=$::value; },
87 "Use the given file as the dbm containing links.",
88 "FILENAME" ],
89  
90 };
91 $::opthandler->std_opts;
92  
93 $::opthandler->check_opts;
94  
95 sub usage() {
96 print <<EOF;
97 check-page [options] filename...
98  
99 EOF
100 $::opthandler->list_opts;
101  
102 print <<EOF;
103  
104 Check an HTML page against the information in the link database (\$::links:-
105 $::links).
106 EOF
107 }
108  
109 sub version() {
110 print <<'EOF';
111 check-page version
112 $Id: check-page.pl,v 1.9 2002/02/03 21:20:41 mikedlr Exp $
113 EOF
114 }
115  
116 ##############################################################################
117 #end command line processing
118  
119 $::default_infostrucs=1 unless defined $::default_infostrucs;
120  
121 die "you must define the \$::infostrucs configuration variable"
122 if $::default_infostrucs and not defined $::infostrucs ;
123  
124 WWW::Link_Controller::InfoStruc::default_infostrucs()
125 if $::default_infostrucs;
126  
127 die 'you must define the $::links configuration variable'
128 unless $::links;
129 $::linkdbm = undef;
130 $::linkdbm = tie %::links, "MLDBM", $::links, O_RDONLY, 0666, $DB_HASH
131 or die $!;
132  
133 my $reporter = new WWW::Link::Reporter::Compile;
134 $reporter->all_reports(1);
135 $reporter->{"report_okay"}=0;
136  
137  
138 my $base_url=undef;
139 my $file=undef;
140 $linkfunc = sub {
141 my($tag, %attr) = @_;
142 LINK: while (my ($attr, $linkname)=each %attr) {
143 unless ( $linkname ) {
144 warn "Undefined link name generated";
145 next LINK;
146 }
147 my ( $uri, $fragment )
148 = WWW::Link_Controller::URL::fixup_link_url($linkname,$base_url);
149 defined $uri or do {
150 reporter->invalid($linkname);
151 };
152 print STDERR "examining link $uri\n" if
153 $::verbose & 8;
154 my $link=$::links{$uri};
155 unless (defined $link) {
156 $reporter->not_found($uri) unless $::ignore_missing;
157 next LINK;
158 }
159 $reporter->examine($link);
160 }
161 };
162  
163 #FIXME now wouldn't it be really nice to use an html validator and
164 #get all of the problems at the same time..
165  
166 my $p = HTML::LinkExtor->new($linkfunc);
167  
168 # we force this to work line by line.. This should mean that error
169 # messages come out at the end of any tag
170  
171 foreach $file ( @ARGV) {
172 print STDERR "file is $file " if $::verbose;
173 $reporter->filename($file);
174 $base_url=WWW::Link_Controller::InfoStruc::file_to_url($file);
175 print STDERR "url is $base_url\n" if $::verbose;
176 open IN, $file;
177 while (my $line=<IN> ) {
178 $p->parse($line);
179 }
180 close IN ; #reset line numbers
181 $p->eof(); #force link extractor to finish
182 }
« requires.PL ↑ Summary blib/script/suggest »