Link/Reporter/RepairForm.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Link/Tester/Base.pm ↑ Summary Link/Test/Validate.pm »
1 package WWW::Link::Reporter::RepairForm;
2 $REVISION=q$Revision: 1.6 $ ; $VERSION = sprintf ( "%d.%02d", $REVISION =~ /(\d+).(\d+)/ );
3  
4 =head1 NAME
5  
6 WWW::Link::Reporter::RepairForm - Build a form for repairing links
7  
8 =head1 SYNOPSIS
9  
10 use WWW::Link;
11 use WWW::Link::Reporter::RepairForm;
12  
13 $link=new WWW::Link;
14 #over time do things to the link ......
15  
16 $::reporter=new WWW::Link::Reporter::RepairForm;
17 $::reporter->examine($link)
18  
19 or see WWW::Link::Selector for a way to recurse through all of the links.
20  
21 =head1 DESCRIPTION
22  
23 This class will output information about any link that it is given.
24  
25 =cut
26  
27  
28 1 ▶use WWW::Link;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use HTML::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use WWW::Link::Reporter::HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 0 ▶use CGI::Form;
Subroutine BEGIN: called CC=1 SCAR=2.6
32  
33 @ISA=qw(WWW::Link::Reporter::HTML);
34 use warnings;
35 use strict;
36  
37  
38 sub new {
39 my $class=shift;
40 my $fixlink_cgi=shift;
41 my $index=shift;
42 my $self=WWW::Link::Reporter::new($class, $index);
43 my $stream=shift;
44 $self->{"hstr"} = new HTML::Stream::LinkRepairForm $stream;
45 $self->{"docurl"} = "http://localhost/linkcontroler/docs/";
46 $self->{"fixlink_cgi"} = $fixlink_cgi;
47 return $self;
48 }
49  
50 sub not_found { return 1; } #just shut up please.
51  
52 #...inherited methods.....
53  
54  
55 sub broken {
56 my $self=shift;
57 my $link=shift;
58 my $url=$link->url();
59 my $hstr=$self->{"hstr"};
60  
61 $hstr-> P;
62  
63 $hstr -> STRONG -> nl
64 ->Link_Heading($url, "Link found BROKEN")
65 -> _STRONG -> nl;
66  
67 $hstr -> auto_form($link, $self->{"fixlink_cgi"}, $url);
68
69 if ($self->{"index"}) {
70 $hstr->page_list( $self->{"index"}->lookup_second($url) );
71 }
72  
73 $hstr-> _P->nl;
74 }
75  
76 sub okay {
77 my $self=shift;
78 my $link=shift;
79 my $url=$link->url();
80 my $hstr=$self->{"hstr"};
81  
82 $hstr -> P;
83  
84 $hstr->Link_Heading($url, "Link tested okay");
85  
86 if ($self->{"index"}) {
87 $hstr->page_list( $self->{"index"}->lookup_second($url) );
88 }
89  
90 $hstr -> _P->nl;
91 }
92  
93 sub damaged {
94 my $self=shift;
95 my $link=shift;
96 my $url=$link->url();
97 my $hstr=$self->{"hstr"};
98  
99 $hstr -> P;
100  
101 $hstr->Link_Heading($url, "Link may be broken");
102  
103 $hstr -> auto_form($link, $self->{"fixlink_cgi"}, $url);
104
105 if ($self->{"index "}) {
106 $hstr->page_list( $self->{"index"}->lookup_second($url) );
107 }
108  
109 $hstr -> _P->nl;
110 }
111  
112 sub not_checked {
113 my $self=shift;
114 my $link=shift;
115 my $url=$link->url();
116 my $hstr=$self->{"hstr"};
117  
118 $hstr -> P;
119  
120 $hstr->Link_Heading($url, "Link has not yet been checked");
121  
122 $hstr -> correct_form($self->{"fixlink_cgi"}, $url);
123
124 if ($self->{"index"}) {
125 $hstr->page_list( $self->{"index"}->lookup_second($url) );
126 }
127  
128 $hstr -> _P->nl;
129 }
130  
131 sub disallowed {
132 my $self=shift;
133 my $link=shift;
134 my $url=$link->url();
135 my $hstr=$self->{"hstr"};
136  
137 $hstr -> P;
138  
139 $hstr->Link_Heading($url, "Link checking is not permitted");
140  
141 $hstr -> auto_form($link, $self->{"fixlink_cgi"}, $url);
142
143 if ($self->{"index"}) {
144 $hstr->page_list( $self->{"index"}->lookup_second($url) );
145 }
146  
147 $hstr -> _P->nl;
148 }
149  
150 sub unsupported {
151 my $self=shift;
152 my $link=shift;
153 my $url=$link->url();
154 my $hstr=$self->{"hstr"};
155  
156 $hstr -> P;
157  
158 $hstr->Link_Heading($url, "Link uses unsupported protocol");
159  
160 $hstr -> auto_form($link, $self->{"fixlink_cgi"}, $url);
161
162 if ($self->{"index"}) {
163 $hstr->page_list( $self->{"index"}->lookup_second($url) );
164 }
165  
166 $hstr -> _P->nl;
167 }
168  
169 sub unknown {
170 my $self=shift;
171 my $link=shift;
172 my $url=$link->url();
173 my $hstr=$self->{"hstr"};
174  
175 $hstr -> P;
176  
177 $hstr->Link_Heading($url, "Link status unknown; error?");
178  
179 $hstr -> auto_form($link, $self->{"fixlink_cgi"}, $url);
180  
181 if ($self->{"index"}) {
182 $hstr->page_list( $self->{"index"}->lookup_second($url) );
183 }
184  
185 $hstr -> _P->nl;
186 }
187  
188 1;
189  
190 package HTML::Stream::LinkRepairForm;
191  
192 our @ISA;
193 @ISA=qw(HTML::Stream::LinkReport);
194  
195 use Carp;
196  
197 =head2 $self->correct_form() $self->auto_form()
198  
199 $self->correct_form(action,url,array_ref)
200 $self->auto_form(link,action,url)
201  
202 These methods write a form which can be used for repairing a broken
203 link. The form has a hidden attribute giving the original link it
204 refered to. It then outputs a list of known suggestions in a radio
205 list and finally outputs a text field in which a completely new
206 suggestion can be input.
207  
208 C<auto_form> automatically populates the form with any suggestions and
209 redirections which the link has attached to it.
210  
211 =cut
212  
213 sub auto_form {
214 my $self=shift;
215 my $link=shift;
216 my @urls=$link->redirect_urls();
217 my $suggestions=$link->fix_suggestions();
218 unshift @urls, @$suggestions if $suggestions;
219 $self->correct_form(@_, \@urls);
220 }
221  
222 sub correct_form {
223 my $self=shift;
224 my $action=shift;
225 my $orig_url=shift;
226 croak "correct_form called without original url\n" unless defined $orig_url;
227 my $array=shift;
228  
229 $self->FORM(METHOD=>"POST", ACTION=>$action);
230 $self->INPUT(NAME=>"orig-url", VALUE=>$orig_url, TYPE=>"HIDDEN");
231 $self->nl->t("Set new end point for link.")->nl->UL;
232 if ($array) {
233 foreach (@$array) {
234 $self -> LI
235 -> INPUT(TYPE=>"radio", NAME=>"canned-suggestion", VALUE=>$_)
236 -> Link($_)
237 -> _LI ->nl;
238 }
239 $self -> LI
240 -> INPUT(TYPE=>"radio", NAME=>"canned-suggestion", VALUE=>"user")
241 -> t("set new url below")
242 -> _LI ->nl;
243 }
244 $self -> LI
245 ->INPUT(TYPE=>"text", NAME=>"user_suggestion")
246 ->INPUT(TYPE=>"submit", NAME=>"Repair Link")
247 -> _LI;
248 $self->_UL
249 ->_FORM;
250 return $self;
251 }
252  
« Link/Tester/Base.pm ↑ Summary Link/Test/Validate.pm »