Shrinkwrap Software
with Perl, PAR and SOAP
Chris Dolan
cdolan@cpan.org
Properties of shrinkwrap
|
→ |
|
- Easy to install
- Feels self-contained
- Easy to launch
- Has a GUI
Contrast traditional Perl software
Can't locate Foo.pm in @INC (@INC contains:
/usr/lib/perl5/site_perl/5.8.6
/usr/lib/perl5/site_perl
/usr/lib/perl5/5.8.6
...
- Many prerequisites to install
- Files scattered all over system
- Run from command line...
- ... or web browser
A solution in two parts
- PAR makes Perl monolithic
- SOAP lets you separate engine from interface
Part I: PAR
PAR to the rescue
What is PAR? Perl Archive Toolkit!
|
→ |
|
→ |
|
- A ZIP archive of Perl files, analogous to Java's JAR
- Can include additional library files
(e.g. libjpeg.so)
- Killer feature: Self-extracting executables
PAR example
% pp -o MyProgram MyProgram.pl
% ./MyProgram
PAR's pp
program finds all of the dependencies in your program
via Module::ScanDeps
then zips those files into an
archive and prepends an executable header (including libperl).
For Windows, add the --gui
flag if you want to avoid the
console window.
How PAR works
At runtime, the PAR executable unzips itself into a temp directory
and loads the libperl dynamic library. The @INC is modified to look
in the temp directory first. PAR then finds the main .pl
file and runs it.
Because libperl is embedded, this works even on computers where Perl
is not installed.
Advanced PAR Usage
Add extra libraries:
% pp -l /sw/lib/libjpeg.62.dylib -o jpegmunger jpegmunger.pl
Exclude runtime features:
% pp -X Foo::Plugin::Advanced -o foo_lite foo.pl
Exclude unneeded functionality:
% pp -X DBD::mysql -o sqllite_browser sqllite_browser.pl
Disadvantages of PAR
- Large files ("Hello, world!" is 2.7 MB)
- Slow to start up the first time
-
Hard to get the dependencies right for complex applications.
Use pp -M Foo::Bar
or:
sub hints_for_PAR {
require Encode::Unicode;
require LWP::Protocol::https;
require URI::https;
}
Don't worry, Module::ScanDeps is improving
Part II: SOAP
The problem: GUI?
Perl does have GUI toolkits: Tk, Wx, Qt, GTK, CamelBones. But most
GUIs are developed in other languages. Why?
- IDE tools
- Speed?
- Appearance
- Skill sets
- Legacy...
A solution: modularize!
- Write the GUI in a language well-endowed for GUI development:
- Cocoa
- Flash
- Java
- .NET
- HTML
- XUL
- Write the engine in Perl
- Launch both at runtime and share the work.
But how do they talk?
SOAP cleans your interfaces
What is SOAP? Simple Object Access Protocol
- Call methods in other programs
- Talks via HTTP
- Messages are XML
- Cross-platform, cross-language
Client – Server
|
↔ |
SOAP |
↔ |
|
If you can write a CGI service, you can write a SOAP service.
When your GUI application launches, it attempts to contact the
server. If the connection fails, it forks and execs the server.
The GUI is stateful, the engine is stateless (or less stateful), just
like in the web paradigm.
An example
MediaLandscape Converter
- Windows application to convert Windows Media presentations to Flash
- Required to be pretty
- Required to coordinate hours of video conversions
- Required to talk to a MySQL database
Solution: Flash GUI, Perl server, C++ engine
Nuts & Bolts
How do you implement the solution?
- Define the API, e.g.:
- List presentations in the database
- Query the available output skins
- Submit a convert job
- Stub out the server methods
- Write a trivial command-line client
(hint: Test::More
!)
- Get a designer to paint a pretty GUI
Another example
MediaLandscape Presenter
- Mac application to capture video-narrated presentations
- Uses QuickTime,
Net::VNC
, VGA hardware, HTTP::Server::Simple
and Time::HiRes
- Emits Flash, H.264, MPEG4, PDF, HTML
Solution: Cocoa GUI, 6 PAR exes, Perl glue
More advantages of SOAP
✓
- Can move server to another computer easily
One line change in a WSDL file
- Strict division of labor
- Can write multiple GUIs (maybe Lite vs. Pro)
Disadvantages of SOAP
☓
- Harder to coordinate multiple programs (what if one crashes?)
- Some firewalls trigger even on 127.0.0.1
- Harder to write a WSDL file than a
.h
file
- SOAP::Lite is one of the most impenetrable modules on CPAN (but is remarkably powerful)
Summary
Shrinkwrap software requires technologies
that simplify yet
beautify the experience for the user. PAR and SOAP help Perl
to accomplish that by:
- Encapsulating the best of CPAN without complex installation
- Letting Perl do what it does best and leaving the rest to other languages