File: MockMechanize.pm

package info (click to toggle)
libwww-mechanize-treebuilder-perl 1.20000-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 172 kB
  • sloc: perl: 1,418; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,040 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package # Hide from pause
  MockMechanize;

use strict;
use warnings;

use base 'Test::WWW::Mechanize';

sub _make_request {
  my ($self, $req) = @_;

  my ($res);

  if ($req->uri eq '/') {
   $res = HTTP::Response->new(200, 'OK', ['Content-Type' => 'text/html; charset=utf-8'], <<"EOF");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
  <title>Hurrah \342\230\203!</title>
</head>
<body>
  <h1>It works</h1>
  <p>A para</p>
</body>
</html>
EOF
  } elsif ($req->uri eq '/plain') {
   $res =  HTTP::Response->new(200, 'OK', ['Content-Type' => 'text/plain'], "I'm plain text");
  } elsif ($req->uri eq '/image') {
   $res =  HTTP::Response->new(200, 'OK', ['Content-Type' => 'image/gif'], "I should be an image");
  }
 
  $res->request($req);
  $res->header( 'Content-Base'   => $req->uri,
                'Content-Length' => length $res->content,
                Status => 200,
                Date   => 'Tue, 04 Sep 2007 16:57:36 GMT' ); 
  return $res;
}

1;