NAME
Process::Launcher - Execute Process objects from the command line
SYNOPSIS
# Create from passed params and run
perl -MProcess::Launcher -e run MyProcessClass param value
# Create from STDIN params and run
perl -MProcess::Launcher -e run3 MyProcessClass
# Thaw via Storable from STDIN, and freeze back after to STDOUT
perl -MProcess::Launcher -e storable MyProcessClass
# Requires Process::YAML to be installed:
# Thaw via YAML::Syck from STDIN, and freeze back after to STDOUT
perl -MProcess::Launcher -e yaml MyProcessClass
DESCRIPTION
The Process::Launcher
module provides a mechanism for launching and running a Process-compatible object from the command line, and returning the results.
Example Use Cases
Most use cases involve isolation. By having a Process
object run inside its own interpreter, it is then free do things such as loading in vast amounts of data and modules without bloating out the main process.
It could provide a novel way of giving Out Of Memory (OOM) protection to your Perl process, because when the operating system's OOM-killer takes out the large (or runaway) process, the main program is left intact.
It provides a way to run some piece of code in a different Perl environment than your own. This could mean a different Perl version, or running something with tainting on without needing the main process to have tainting.
FUNCTIONS
All functions are imported into the callers by default.
run
The run
function creates an object based on the arguments passed to the program on the command line.
The first param is take as the Process class and loaded, and the rest of the params are passed directly to the constructor.
Note that this does mean you can't pass anything more complex than simple string pairs. If you need something more complex, try the storable
function below.
Prints one line of output at the end of the process run.
# Prints the following if the process completed correctly
OK
# Prints the following if the process does not complete
FAIL - reason
run3
The run3
function is similar to the run
function but assumes you are launching the process via something that makes it easy to pass in params via STDIN
, such as IPC::Run3 (recommended)
It takes a single param of the Process class.
It then readsa series of key-value pairs from STDIN
in the form
param1=value
param2=value
At the end of the input, the key/value pairs are passed to the constructor, and from there the function behaves identically to run
above, including output.
serialized
The serialized
function is more robust and thorough again.
It takes the name of a Process::Serializable subclass as its parameter, reads data in from STDIN
, then calls the deserialize
method for the class to get the Process object.
This object has prepare
and then run
called on it.
The same OK
or FAIL
line will be written as above, but after that first line, the completed object will be frozen back out via serialize
and written to STDOUT
as well.
The intent is that you create your object of the Process::Serializable
subcless in your main interpreter thread, then hand it off to another Perl instance for execution, and then optionally return it to handle the results.
SUPPORT
Bugs should be reported via the CPAN bug tracker at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Process
For other issues, contact the author.
AUTHOR
Adam Kennedy <adamk@cpan.org>
SEE ALSO
COPYRIGHT
Copyright 2006 - 2009 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.