1 package LWP::Debug; # legacy
5 @EXPORT_OK = qw(level trace debug conns);
9 my @levels = qw(trace debug conns);
16 my $callpkg = caller(0);
27 Exporter::export($pack, $callpkg, @symbols);
35 if ($_ eq '+') { # all on
36 # switch on all levels
37 %current_level = map { $_ => 1 } @levels;
39 elsif ($_ eq '-') { # all off
42 elsif (/^([-+])(\w+)$/) {
43 $current_level{$2} = $1 eq '+';
46 Carp::croak("Illegal level format $_");
52 sub trace { _log(@_) if $current_level{'trace'}; }
53 sub debug { _log(@_) if $current_level{'debug'}; }
54 sub conns { _log(@_) if $current_level{'conns'}; }
60 $msg .= "\n" unless $msg =~ /\n$/; # ensure trailing "\n"
62 my($package,$filename,$line,$sub) = caller(2);
63 print STDERR "$sub: $msg";
72 LWP::Debug - deprecated
76 LWP::Debug used to provide tracing facilities, but these are not used
77 by LWP any more. The code in this module is kept around
78 (undocumented) so that 3rd party code that happen to use the old
79 interfaces continue to run.
81 One useful feature that LWP::Debug provided (in an imprecise and
82 troublesome way) was network traffic monitoring. The following
83 section provide some hints about recommened replacements.
85 =head2 Network traffic monitoring
87 The best way to monitor the network traffic that LWP generates is to
88 use an external TCP monitoring program. The Wireshark program
89 (L<http://www.wireshark.org/>) is higly recommended for this.
91 Another approach it to use a debugging HTTP proxy server and make
92 LWP direct all its traffic via this one. Call C<< $ua->proxy >> to
93 set it up and then just use LWP as before.
95 For less precise monitoring needs just setting up a few simple
96 handlers might do. The following example sets up handlers to dump the
97 request and response objects that pass through LWP:
100 $ua = LWP::UserAgent->new;
101 $ua->default_header('Accept-Encoding' => scalar HTTP::Message::decodable());
103 $ua->add_handler("request_send", sub { shift->dump; return });
104 $ua->add_handler("response_done", sub { shift->dump; return });
106 $ua->get("http://www.example.com");