Devel-Scooby
view release on metacpan or search on metacpan
Devel::Scooby version 4.12
==========================
The Devel::Scooby debugger (supports relocation).
See: http://glasnost.itcarlow.ie/~scooby/ for more details.
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
package Devel::Scooby;
# Scooby.pm - a relocation mechanism for use with the Mobile::Location
# and Mobile::Executive modules.
#
# Author: Paul Barry, paul.barry@itcarlow.ie
# Create: October 2002.
# Update: April/May 2003 - Version 4.x series.
#
# Notes: This code takes advantage of the CPAN modules
# PadWalker and Storable (with a little help from the
# Data::Dumper module when it comes to Objects). The Crypt::RSA
# module provides PK+/PK- support.
#
# Version 1.x supported relocating simple Perl code.
# Version 2.x supported relocating SCALARs, ARRAYs, and
# HASHes and references to same.
# Version 3.x supported relocating Perl OO objects. Note
# that this will only occur after Scooby has contacted
# the receiving Location and determined that any
# required classes exist on the remote Perl system.
# Version 4.x supports authenticated relocation using Crypt::RSA,
# as well as encryption of the mobile agent source code.
#
our $VERSION = 4.12;
# The "constant.pm" module does not want to work with the debugger mechanism,
# so "our" variables are used instead.
our $SCOOBY_CONFIG_FILE = "$ENV{'HOME'}/.scoobyrc";
sub sub {
# Called before every subroutine call in the program.
#
# IN: nothing. Although "$sub" is set to the name of the
# subroutine that was just called (thanks to Perl's debugging
# mechanisms).
#
# OUT: nothing.
if ( $sub =~ /^Mobile::Executive::relocate$/ )
{
use Socket; # Functional interface to Socket API.
use Storable qw( freeze thaw ); # Provides a persistence mechanism.
use PadWalker qw( peek_my ); # Provides access to all lexically scoped variables.
use Crypt::RSA; # Provides authentication and
# encryption services.
my $remote = shift;
my $key_server = $1;
# Now that we know the address of the key server, we can
# request the PK+ of the key server and the next location.
_get_store_pkplus( $key_server, $LOCALHOST, $RESPONDER_PPORT );
_get_store_pkplus( $key_server, $remote, $remote_port );
open RELOCATE_FILE, "$Mobile::Executive::absolute_fn"
or die "Scooby: Unable to open file for relocation: $!.\n";
# Dump the current state of the agent to a temporary disk-file
# so that we can encrypt it with the next Location's PK+.
my $tmp_filename = "$0.$$.temporary.tmp";
open TMP_FILE, ">$tmp_filename"
or die "Scooby: could not write to temporary encryption file: $!.\n";
my $line_count = 0;
print TCP_SOCK "$cypher_signature" . $SIGNATURE_DELIMITER;
# Send the encoded cyphertext to the next Location.
print TCP_SOCK $cyphertext;
close TCP_SOCK
or warn "Scooby: close failed: $!.\n";
exit; # We are done on this Location, having just relocated
# to another. This is why we "exit" at this time.
}
# Call the original subroutine with parameters (if there was any).
# We only get to here if there's no request for relocation.
if ( defined @_ )
{
&$sub( @_ );
}
else
{
&$sub;
}
}
sub _storable_decode {
# Called immediately after the lexical variables are stringified
# in order to return the "Storable" output to its original form.
#
# IN: The IP name (or address) of the remote Location.
# The protocol port number of the remote Location.
# The "thawed" output from the Storable::thaw method.
#
# OUT: The stringified representation of the Perl code that can be
# executed to reinitialize the relocated variables.
#
# NOTE: This code also checks to see if any required modules exist
# on the remote Location. It will "die" if some are missing.
my $remote = shift;
my $remote_port = shift;
my $thawed = shift;
my %for_refs;
my $stringified = '';
This is an internal module that is not designed to be "used" directly by a program. Assuming a mobile agent called B<multiwho> exists (that "uses" the B<Mobile::Executive> module), this module can be used to execute it, as follows:
=over 4
perl -d:Scooby multiwho
=back
The B<-d> switch to C<perl> invokes Scooby as a debugger. Unlike a traditional debugger that expects to interact with a human, Scooby runs automatically. It NEVER interacts with a human, it interacts with the mobile agent machinery.
Scooby can be used to relocate Perl source code which contains the following:
=over 4
SCALARs (both numbers and strings).
An ARRAY of SCALARs (known as a simple ARRAY).
A HASH of SCALARs (known as a simple HASH).
References to SCALARs.
References to a simple ARRAY.
References to a simple HASH.
Objects.
References to objects are B<not> supported and are in no way guaranteed to behave the way you expect them to after relocation (even though they do relocate).
The relocation of more complex data structures is B<not> supported at this time (refer to the TO DO LIST section, below).
=back
=head1 Internal methods/subroutines
=over 4
B<DB::DB> - called for every executable statement contained in the mobile agent source code file.
B<DB::sub> - called for every subroutine call contained in the mobile agent source code file.
=back
=head1 ENVIRONMENT
This module must be installed in your Perl system's B<Devel/> directory. This module will only work on an operating system that supports the Perl modules listed in the SEE ALSO section, below. (To date, I've only tested it on various Linux distribu...
=head1 TO DO LIST
Loads. The biggest item on the list would be to enhance Scooby to allow it to handle more complex data structures, such as ARRAYs of HASHes and HASHes of ARRAYs, etc., etc.
My initial plan was to allow for the automatic relocation of open disk-files. However, on reflection, I decided not to do this at this time, but may return to the idea at some stage in the future.
The current implementation checks to see if "used" classes are available on the next Location before attempting relocation, but does not check to see if "used" modules are available. It would be nice if it did.
It would also be nice to incorporate an updated B<Class::Tom> (by James Duncan) to handle the relocation of objects to a Location without the need to have the module exist on the remote Location. On my system (Linux), the most recent B<Class::Tom> g...
=head1 SEE ALSO
The B<Mobile::Executive> module and the B<Mobile::Location> class. Internally, this module uses the following CPAN modules: B<PadWalker> and B<Storable>, in addition to the standard B<Data::Dumper> module. The B<Crypt::RSA> modules provides encrypt...
The Scooby Website: B<http://glasnost.itcarlow.ie/~scooby/>.
=head1 AUTHOR
Paul Barry, Institute of Technology, Carlow in Ireland, B<paul.barry@itcarlow.ie>, B<http://glasnost.itcarlow.ie/~barryp/>.
( run in 1.652 second using v1.01-cache-2.11-cpan-71847e10f99 )