Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Shlomi Fish (918)

Shlomi Fish
  shlomif@iglu.org.il
http://www.shlomifish.org/
AOL IM: ShlomiFish (Add Buddy, Send Message)
Yahoo! ID: shlomif2 (Add User, Send Message)
Jabber: ShlomiFish@jabber.org

I'm a hacker of Perl, C, Shell, and occasionally other languages. Perl is my favourite language by far. I'm a member of the Israeli Perl Mongers, and contribute to and advocate open-source technologies. Technorati Profile [technorati.com]

Journal of Shlomi Fish (918)

Sunday September 09, 2007
11:37 AM

The Perl Apps as Modules Paradigm

[ #34397 ]

Back at the time when I was uploading new versions of Test::Run::CmdLine, I found out that some CPAN testers report were failing because one of the scripts that was supposed to be installed by a dependency, and was used in a test, was not available in the path.

My solution to this was to make sure the script just called the "run()" function of a module, and then to invoke the module in the tests from the command line like this:

perl -MApp::MyApp -e 'run()' -- --name "Sophie"

App::MyApp can be something like:

package App::MyApp;

use strict;
use warnings;

use base 'Exporter';

our @EXPORT=(qw(run));

use Getopt::Long;

sub run
{
    my $name = "World";

    GetOptions("name=s" => \$name);

    print "Hello, $name!\n";
}

1;

It's also useful to be able to run such programs without needing to install scripts and with just dependence on the Perl module's path.

On my homepage makefile, I have the following rules to handle the Screenplays:

lib/docbook/xml/%.xml: lib/screenplay-xml/xml/%.xml
    perl -MXML::Grammar::Screenplay::App::ToDocBook -e 'run()' -- \
    -o $@ $<

lib/screenplay-xml/html/%.html: lib/screenplay-xml/xml/%.xml
    perl -MXML::Grammar::Screenplay::App::ToHTML -e 'run()' -- \
    -o $@ $<

lib/screenplay-xml/xml/%.xml: lib/screenplay-xml/txt/%.txt
    perl -MXML::Grammar::Screenplay::App::FromProto -e 'run()' -- \
    -o $@ $<

This solves me the problem of depending on the scripts being in the path.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.