| 1 | package WWW::Chat::Processor; | ||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $VERSION = '0.62'; | |||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Config qw(%Config); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||
| 8 | sub parse | ||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=24 SCAR=51.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 10 | 1 | my ($script, $file) = @_; # get the script as a single $calar | |||||||||||||||||||||||||||||||||||||
| 11 | # plus the file name (optional) | ||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | $file ||= '[unknown]'; # set the default filename | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$file ||= "[unknown]"
MC/DC0%0/1
$file ||= "[unknown]"
$file
Truth table50%1/2
A
A= $file
| |||||||||||||||||||||||||||||||||||||||
| 13 | 1 | my $output = ''; # initialise the output | |||||||||||||||||||||||||||||||||||||
| 14 | 1 | my @LINES = split /\n/, $script; # split the script up into lines | |||||||||||||||||||||||||||||||||||||
| 15 | 1 | undef $script; # and undef the script to save memory | |||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | 1 | my $progname = $0; # get the progname name for diagnostics | |||||||||||||||||||||||||||||||||||||
| 18 | 1 | $progname =~ s,.*[\\/],,; # and loose the path | |||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | 1 | $output .= "$Config{'startperl'} -w\n"; # get the shebang line | |||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | 1 | $output .= "# !!! DO NOT EDIT !!!\n"; # add some cruft | |||||||||||||||||||||||||||||||||||||
| 23 | 1 | $output .= "# This program was automatically generated from '$file' by $progname\n"; | |||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||
| 25 | # .... and awwaaaaaay we go | ||||||||||||||||||||||||||||||||||||||
| 26 | 1 | $output .= <<'EOT'; | |||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | use strict; | ||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | use URI (); | ||||||||||||||||||||||||||||||||||||||
| 31 | use HTTP::Request (); | ||||||||||||||||||||||||||||||||||||||
| 32 | use LWP::UserAgent (); | ||||||||||||||||||||||||||||||||||||||
| 33 | #use LWP::Debug qw(+); | ||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | use HTML::Form (); | ||||||||||||||||||||||||||||||||||||||
| 36 | use WWW::Chat; | ||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | use vars qw($ua $uri $base $req $res $status $ct @forms $form @links $TRACE); | ||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||
| 40 | $base ||= "http://localhost"; | ||||||||||||||||||||||||||||||||||||||
| 41 | unless ($ua) { | ||||||||||||||||||||||||||||||||||||||
| 42 | $ua = LWP::UserAgent->new; | ||||||||||||||||||||||||||||||||||||||
| 43 | $ua->agent("webchat/0.61 " . $ua->agent); | ||||||||||||||||||||||||||||||||||||||
| 44 | $ua->env_proxy; | ||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||
| 47 | $TRACE = $ENV{WEBCHAT_TRACE}; | ||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | EOT | ||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | 1 | $output .= "#line 1 \"$file\"\n"; | |||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | use Data::Dump qw(dump); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my $seen_end; | |||||||||||||||||||||||||||||||||||||
| 56 | 1 | my $level = 0; | |||||||||||||||||||||||||||||||||||||
| 57 | 1 | my $line = 2; | |||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | for ($line=0; $line < scalar @LINES; $line++) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||||||||||||
| 60 | 2 | $_ = $LINES[$line]; | |||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | if ($seen_end) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $output .= $_."\n"; | |||||||||||||||||||||||||||||||||||||
| 64 | 0 | next; | |||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | if (/^(\s*)GET\s+(\S+)\s*$/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 68 | 1 | my $indent = $1; | |||||||||||||||||||||||||||||||||||||
| 69 | 1 | my $uri = $2; | |||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | $uri = dump($uri) unless $uri =~ /^\$/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 71 | 1 | $output .= "$indent#GET $uri\n"; | |||||||||||||||||||||||||||||||||||||
| 72 | 1 | $output .= "${indent}eval {\n"; | |||||||||||||||||||||||||||||||||||||
| 73 | 1 | $level++; | |||||||||||||||||||||||||||||||||||||
| 74 | 1 | $output .= "$indent local \$uri = URI->new_abs($uri, \$base);\n"; | |||||||||||||||||||||||||||||||||||||
| 75 | 1 | $output .= "$indent local \$req = HTTP::Request->new(GET => \$uri);\n"; | |||||||||||||||||||||||||||||||||||||
| 76 | 1 | $output .= request("$indent "); | |||||||||||||||||||||||||||||||||||||
| 77 | 1 | $output .= line($line, $file); | |||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | } elsif (/^(\s*)FOLLOW\s(.*)/) { | ||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $indent = $1; | |||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $what = $2; | |||||||||||||||||||||||||||||||||||||
| 82 | 0 | $what =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||
| 83 | 0 | $output .= "${indent}# FOLLOW $what\n"; | |||||||||||||||||||||||||||||||||||||
| 84 | 0 | $output .= "${indent}eval {\n"; | |||||||||||||||||||||||||||||||||||||
| 85 | 0 | $level++; | |||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($what =~ m,^/,) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $output .= "$indent local \$uri;\n"; | |||||||||||||||||||||||||||||||||||||
| 88 | 0 | $output .= "$indent for (\@links) { \$uri = \$_->[0], last if \$_->[1] =~ $what }\n"; | |||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $text = dump("FOLLOW $what"); | |||||||||||||||||||||||||||||||||||||
| 90 | 0 | $output .= "$indent WWW::Chat::fail($text, \$res, \$ct) unless defined \$uri;\n"; | |||||||||||||||||||||||||||||||||||||
| 91 | 0 | $output .= "$indent \$uri = URI->new_abs(\$uri, \$base);\n"; | |||||||||||||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $what = dump($what); | |||||||||||||||||||||||||||||||||||||
| 94 | 0 | $output .= "$indent local \$uri = WWW::Chat::locate_link($what, \\\@links, \$base);\n"; | |||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $output .= "$indent local \$req = HTTP::Request->new(GET => \$uri);\n"; | |||||||||||||||||||||||||||||||||||||
| 97 | 0 | $output .= request("$indent "); | |||||||||||||||||||||||||||||||||||||
| 98 | 0 | $output .= line($line, $file); | |||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||
| 100 | } elsif (/^(\s*)FORM:?(\d+)?(?:\s+(\S+))?\s*$/) { | ||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $indent = $1; | |||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $form_no = $2 || 1; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$2 || 1
MC/DC0%0/1
$2 || 1
$2
Truth table0%0/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $uri = $3; | |||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $uri = dump($uri) if !defined($uri) || $uri !~ /^\$/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $uri and $uri =~ /^\$/
MC/DC0%0/2
defined $uri and $uri =~ /^\$/
defined $uri
$uri =~ /^\$/
Truth table0%0/3
A and B
A= defined $uriB= $uri =~ /^\$/
| |||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $output .= $indent. "\$form = WWW::Chat::findform(\\\@forms, $form_no, $uri);\n"; | |||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | } elsif (/^(\s*)EXPECT\s+(.*)$/) { | ||||||||||||||||||||||||||||||||||||||
| 108 | 1 | my $indent = $1; | |||||||||||||||||||||||||||||||||||||
| 109 | 1 | my $what = $2; | |||||||||||||||||||||||||||||||||||||
| 110 | 1 | $what =~ s/;$//; | |||||||||||||||||||||||||||||||||||||
| 111 | # $output .= "$indent#EXPECT $what\n"; | ||||||||||||||||||||||||||||||||||||||
| 112 | 1 | my $text = dump($what); | |||||||||||||||||||||||||||||||||||||
| 113 | 1 | $what =~ s/(OK|ERROR)/WWW::Chat::$1(\$status)/g; | |||||||||||||||||||||||||||||||||||||
| 114 | 1 | $output .= $indent. "WWW::Chat::fail($text, \$res, \$ct) unless $what;\n"; | |||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | } elsif (/^(\s*)BACK(?:\s+(ALL|\d+))?\s*$/) { | ||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $indent = $1; | |||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my $done = $2 || "1"; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$2 || '1'
MC/DC0%0/1
$2 || '1'
$2
Truth table0%0/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $output .= done($indent, $done, $line, $file, \$level); | |||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||
| 121 | } elsif (/^(\s*)F\s+([\w.:\-*\#]+)\s*=\s*(.*)/) { | ||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $indent = $1; | |||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $name = $2; | |||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $val = dump ("$3"); | |||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $no = 1; | |||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $no = $1 if $name =~ s/:(\d+)$//; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $name = dump($name); | |||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ($no == 1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $output .= "$indent\$form->value($name => $val);\n"; | |||||||||||||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $output .= "$indent\$form->find_input($name, $no)->value($val);\n"; | |||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||
| 136 | } elsif (/^(\s*)(?:CLICK|SUBMIT)(?:\s+(\w+))?\s+(?:(\d+)\s+(\d+))?/) { | ||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $indent = $1; | |||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $name = $2; | |||||||||||||||||||||||||||||||||||||
| 139 | 0 | $name = dump($name); | |||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $x = $3; | |||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $y = $4; | |||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | for ($x, $y) { $_ = 1 unless defined; } | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $output .= "$indent#CLICK $name $x $y\n"; | |||||||||||||||||||||||||||||||||||||
| 144 | 0 | $output .= $indent. "eval {\n"; | |||||||||||||||||||||||||||||||||||||
| 145 | 0 | $level++; | |||||||||||||||||||||||||||||||||||||
| 146 | 0 | $output .= $indent. " local \$uri = \$form->uri;\n"; | |||||||||||||||||||||||||||||||||||||
| 147 | 0 | $output .= $indent. " local \$req = \$form->click($name, $x, $y);\n"; | |||||||||||||||||||||||||||||||||||||
| 148 | 0 | $output .= request("$indent "); | |||||||||||||||||||||||||||||||||||||
| 149 | 0 | $output .= line($line, $file); | |||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | } elsif (/^__END__$/) { | ||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | $output .= done("", "ALL", $line, $file, \$level) if $level; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $output .= $_."\n"; | |||||||||||||||||||||||||||||||||||||
| 154 | 0 | $seen_end++; | |||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | } else { | ||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $output .= $_."\n"; | |||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||
| 160 | 1 | ▶ | $output .= done("", "ALL", $line, $file, \$level) if $level; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 161 | 1 | return $output; | |||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | sub done | ||||||||||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
done: called CC=5 SCAR=17.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 167 | 1 | my($indent, $done, $line, $file, $rlevel) = @_; | |||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | $done = $$rlevel if $done eq "ALL" || $done > $$rlevel; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$done eq "ALL" or $done > $$rlevel
MC/DC0%0/2
$done eq "ALL" or $done > $$rlevel
$done eq "ALL"
$done > $$rlevel
Truth table33%1/3
A or B
A= $done eq "ALL"B= $done > $$rlevel
| |||||||||||||||||||||||||||||||||||||||
| 169 | 1 | $$rlevel -= $done; | |||||||||||||||||||||||||||||||||||||
| 170 | 1 | my $output = ''; | |||||||||||||||||||||||||||||||||||||
| 171 | 1 | for (1 .. $done) { | |||||||||||||||||||||||||||||||||||||
| 172 | 1 | $output .= $indent. "}; WWW::Chat::check_eval(\$@);\n"; | |||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||
| 174 | 1 | ▶ | $output .= line($line, $file) if ($done > 1); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 175 | 1 | return $output; | |||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||
| 178 | sub request | ||||||||||||||||||||||||||||||||||||||
| 179 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 180 | 1 | my ($indent) = @_; | |||||||||||||||||||||||||||||||||||||
| 181 | 1 | my $output = ''; | |||||||||||||||||||||||||||||||||||||
| 182 | 1 | $output .= $indent. "local \$res = WWW::Chat::request(\$req, \$ua, \$TRACE);\n"; | |||||||||||||||||||||||||||||||||||||
| 183 | 1 | $output .= $indent. "#print STDERR \$res->as_string;\n"; | |||||||||||||||||||||||||||||||||||||
| 184 | 1 | $output .= $indent. "local \$status = \$res->code;\n"; | |||||||||||||||||||||||||||||||||||||
| 185 | 1 | $output .= $indent. "local \$base = \$res->base;\n"; | |||||||||||||||||||||||||||||||||||||
| 186 | 1 | $output .= $indent. "local \$ct = \$res->content_type || \"\";\n"; | |||||||||||||||||||||||||||||||||||||
| 187 | 1 | $output .= $indent. "local \$_ = \$res->content;\n"; | |||||||||||||||||||||||||||||||||||||
| 188 | 1 | $output .= $indent. "local(\@forms, \$form, \@links);\n"; | |||||||||||||||||||||||||||||||||||||
| 189 | 1 | $output .= $indent. "if (\$ct eq 'text/html') {\n"; | |||||||||||||||||||||||||||||||||||||
| 190 | 1 | $output .= $indent. " \@forms = HTML::Form->parse(\$_, \$res->base);\n"; | |||||||||||||||||||||||||||||||||||||
| 191 | 1 | $output .= $indent. " \$form = \$forms[0] if \@forms;\n"; | |||||||||||||||||||||||||||||||||||||
| 192 | 1 | $output .= $indent. " \@links = WWW::Chat::extract_links(\$_);\n"; | |||||||||||||||||||||||||||||||||||||
| 193 | 1 | $output .= $indent. "}\n"; | |||||||||||||||||||||||||||||||||||||
| 194 | 1 | return $output; | |||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||
| 197 | sub line | ||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
line: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 199 | 1 | my ($line, $file) = @_; | |||||||||||||||||||||||||||||||||||||
| 200 | 1 | $line+=2; | |||||||||||||||||||||||||||||||||||||
| 201 | 1 | return qq(#line $line "$file"\n); | |||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||
| 204 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 205 | __END__ | ||||||||||||||||||||||||||||||||||||||