The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

IPC::PerlSSH::Library - support package for declaring libraries of remote functions

SYNOPSIS

 package IPC::PerlSSH::Library::Info;

 use strict;
 use IPC::PerlSSH::Library;

 func uname   => 'uname()';
 func ostype  => '$^O';
 func perlbin => '$^X';

 1;

This can be loaded by

 use IPC::PerlSSH;

 my $ips = IPC::PerlSSH->new( Host => "over.there" );

 $ips->use_library( "Info" );

 print "Remote perl is running from " . $ips->call("perlbin") . "\n";
 print " Running on a machine of type " . $ips->call("ostype") .
                                          $ips->call("uname") . "\n";

DESCRIPTION

This module allows the creation of pre-prepared libraries of functions which may be loaded into a remote perl running via IPC::PerlSSH.

All the code is kept in its own package in the remote perl. The package declaration is performed in the remote perl, by including an optional block of initialisation code, passed to the init() function.

Typically this code could use a perl module, or declare shared variables or functions. Be careful when useing a module, as the remote perl executing it may not have the same modules installed as the local machine, or even be of the same version.

Note that our variables will be available for use in stored code, but limitations of the way perl's lexical scopes work mean that my variables will not. On versions of perl before 5.10, the variable will have to be oured again in each block of code that requires it. On 5.10 and above, this is not necessary; but beware that the code will not work on remote perls before this version, even if the local perl is 5.10.

For example, consider the following small example:

 package IPC::PerlSSH::Library::Storage;

 use IPC::PerlSSH::Library;

 init q{
    our %storage;

    sub list  { keys %storage }
    sub clear { undef %storage }
 };

 func get   => q{ our %storage; return $storage{$_[0]} };
 func set   => q{ our %storage; $storage{$_[0]} = $_[1] };
 func clear => q{ clear() }
 func list  => q{ return list() }

 1;

FUNCTIONS

func

   func( $name, $code )

Declare a function called $name, which is implemented using the source code in $code. Note that $code must be a plain string, NOT a CODE reference.

The function name may not begin with an underscore.

init( $code )

Declare library initialisation code. This code will be executed in the remote perl before any functions are compiled.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>