++ed by:

78 PAUSE users
66 non-PAUSE users.

Author image Marc A. Lehmann


AnyEvent::Debug - debugging utilities for AnyEvent


   use AnyEvent::Debug;

   # create an interactive shell into the program
   my $shell = AnyEvent::Debug::shell "unix/", "/home/schmorp/myshell";
   # then on the shell: "socat readline /home/schmorp/myshell"


This module provides functionality hopefully useful for debugging.

At the moment, "only" an interactive shell is implemented. This shell allows you to interactively "telnet into" your program and execute Perl code, e.g. to look at global variables.


$shell = AnyEvent;::Debug::shell $host, $service

This function binds on the given host and service port and returns a shell object, whcih determines the lifetime of the shell. Any number of conenctions are accepted on the port, and they will give you a very primitive shell that simply executes every line you enter.

All commands will be executed "blockingly" with the socket selected for output. For a less "blocking" interface see Coro::Debug.

The commands will be executed in the AnyEvent::Debug::shell package, which is initially empty and up to use by all shells. Code is evaluated under use strict 'subs'.

Consider the beneficial aspects of using more global (our) variables than local ones (my) in package scope: Earlier all my modules tended to hide internal variables inside my variables, so users couldn't accidentally access them. Having interactive access to your programs changed that: having internal variables still in the global scope means you can debug them easier.

As no authenticsation is done, in most cases it is best not to use a TCP port, but a unix domain socket, whcih cna be put wherever youc an access it, but not others:

   our $SHELL = AnyEvent::Debug::shell "unix/", "/home/schmorp/shell";

Then you can use a tool to connect to the shell, such as the ever versatile socat, which in addition can give you readline support:

   socat readline /home/schmorp/shell
   # or:
   cd /home/schmorp; socat readline unix:shell

Socat can even give you a persistent history:

   socat readline,history=.anyevent-history unix:shell

Binding on (or ::1) might be a less secure but sitll not totally insecure (on single-user machines) alternative to let you use other tools, such as telnet:

   our $SHELL = AnyEvent::Debug::shell "127.1", "1357";

And then:

   telnet localhost 1357


 Marc Lehmann <schmorp@schmorp.de>