line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Chat; |
2
|
|
|
|
|
|
|
$VERSION = '0.65'; |
3
|
1
|
|
|
1
|
|
1497
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
58
|
|
4
|
|
|
|
|
|
|
require Exporter; |
5
|
|
|
|
|
|
|
*import = \&Exporter::import; |
6
|
|
|
|
|
|
|
#use vars qw(@EXPORT_OK); |
7
|
|
|
|
|
|
|
#@EXPORT_OK=qw(fail OK ERROR); |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1119
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub fail |
12
|
|
|
|
|
|
|
{ |
13
|
0
|
|
|
0
|
0
|
|
my ($reason, $mres, $mct) = @_; |
14
|
0
|
|
0
|
|
|
|
$mres ||= $main::res; |
15
|
0
|
|
0
|
|
|
|
$mct ||= $main::ct; |
16
|
0
|
|
|
|
|
|
Carp::carp("FAILED $reason"); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Print current response too... |
19
|
0
|
|
|
|
|
|
my $res = $mres->clone; |
20
|
0
|
|
|
|
|
|
my $cref = $res->content_ref; |
21
|
0
|
0
|
|
|
|
|
if ($mct =~ m,^text/,) { |
22
|
0
|
0
|
|
|
|
|
substr($$cref, 256) = "..." if length($$cref) > 512; |
23
|
|
|
|
|
|
|
} else { |
24
|
0
|
|
|
|
|
|
$$cref = ""; |
25
|
|
|
|
|
|
|
} |
26
|
0
|
|
|
|
|
|
$res = $res->as_string; |
27
|
0
|
|
|
|
|
|
$res =~ s/^/ /gm; |
28
|
0
|
|
|
|
|
|
print STDERR $res; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
die "ASSERT"; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub check_eval |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
0
|
|
0
|
0
|
|
return unless $_[0]; |
36
|
0
|
0
|
|
|
|
|
return if $_[0] =~ /^ASSERT /; |
37
|
0
|
|
|
|
|
|
print STDERR $_[0]; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub OK |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
0
|
0
|
|
my $mstatus = shift; |
44
|
0
|
|
0
|
|
|
|
$mstatus ||= $main::status; |
45
|
0
|
|
|
|
|
|
$mstatus == 200; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub ERROR |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
0
|
0
|
|
my $mstatus = shift; |
51
|
0
|
|
0
|
|
|
|
$mstatus ||= $main::status; |
52
|
0
|
0
|
|
|
|
|
$mstatus >= 400 && $mstatus < 600; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub request |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
0
|
0
|
|
my ($req, $mua, $MTRACE) = @_; |
58
|
0
|
|
0
|
|
|
|
$mua ||= $main::ua; |
59
|
0
|
|
0
|
|
|
|
$MTRACE ||= $main::TRACE; |
60
|
0
|
0
|
|
|
|
|
print STDERR ">> " . $req->method . " " . $req->uri . " ==> " |
61
|
|
|
|
|
|
|
if $MTRACE; |
62
|
|
|
|
|
|
|
#print STDERR "\nCC " . $req->content . "\n" if $MTRACE; |
63
|
0
|
|
|
|
|
|
my $res = $mua->request($req); |
64
|
0
|
0
|
|
|
|
|
print STDERR $res->status_line . "\n" |
65
|
|
|
|
|
|
|
if $MTRACE; |
66
|
0
|
|
|
|
|
|
$res; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub findform |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
0
|
0
|
|
my($forms, $no, $uri) = @_; |
72
|
0
|
|
|
|
|
|
my $f = $forms->[$no-1]; |
73
|
0
|
0
|
|
|
|
|
Carp::croak("No FORM number $no") unless $f; |
74
|
0
|
|
|
|
|
|
my $furi = $f->uri; |
75
|
0
|
0
|
0
|
|
|
|
Carp::croak("Wrong FROM name ($furi)") if $uri && $furi !~ /$uri$/; |
76
|
0
|
|
|
|
|
|
$f; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub extract_links |
80
|
|
|
|
|
|
|
{ |
81
|
0
|
|
|
0
|
0
|
|
require HTML::TokeParser; |
82
|
0
|
|
|
|
|
|
my $p = HTML::TokeParser->new(\$_[0]); |
83
|
0
|
|
|
|
|
|
my @links; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
while (my $token = $p->get_tag("a")) { |
86
|
0
|
|
|
|
|
|
my $url = $token->[1]{href}; |
87
|
0
|
0
|
|
|
|
|
next unless defined $url; # probably just a name link |
88
|
0
|
|
|
|
|
|
my $text = $p->get_trimmed_text("/a"); |
89
|
0
|
|
|
|
|
|
push(@links, [$url => $text]); |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
return @links; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub locate_link |
95
|
|
|
|
|
|
|
{ |
96
|
0
|
|
|
0
|
0
|
|
my($where, $links, $base) = @_; |
97
|
0
|
|
|
|
|
|
my $no_links = @$links; |
98
|
0
|
0
|
|
|
|
|
Carp::croak("Only $no_links links on this page ($where)") if $where >= $no_links; |
99
|
0
|
|
|
|
|
|
require URI; |
100
|
0
|
|
|
|
|
|
URI->new_abs($links->[$where][0], $base); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |