Distributing application with modules as a single file

Z

zoul

Hello!

I have a small Perl application that consists of a single Perl script.
I'd like to improve it and split the code into modules, so that it is
easier for me to work on it. But I like the single-file approach,
because it is so simple - all my users have to do is download a
single file and place it in their ~/bin or wherever they like. If I
split the application into modules, I will have to think of some more
complicated installation procedure.

I thought maybe there was some module to put all the files together
into one single Perl script that would automatically load the modules
and then run the code? This way I could split the code into modules,
work on the modularized code and then create a special all-in-one
script for distribution. Note that I do not want some
auto-decompressing gizmo that would dump the modules on the appropriate
places in the system, I just want the code to stay in one single file
on the user system. I am also not trying to solve module dependencies
- I just want *my* modularized code to stay in a single file. (But I
want to be able to work on separate files while developing, because it
is pain to jump around in one large file.)

Thanks, T.
 
J

John Bokma

zoul said:
I thought maybe there was some module to put all the files together
into one single Perl script that would automatically load the modules
and then run the code?


Yup: PAR
 
A

anno4000

zoul said:
Hello!

I have a small Perl application that consists of a single Perl script.
I'd like to improve it and split the code into modules, so that it is
easier for me to work on it. But I like the single-file approach,
because it is so simple - all my users have to do is download a
single file and place it in their ~/bin or wherever they like. If I
split the application into modules, I will have to think of some more
complicated installation procedure.

I thought maybe there was some module to put all the files together
into one single Perl script that would automatically load the modules
and then run the code? This way I could split the code into modules,
work on the modularized code and then create a special all-in-one
script for distribution. Note that I do not want some
auto-decompressing gizmo that would dump the modules on the appropriate
places in the system, I just want the code to stay in one single file
on the user system. I am also not trying to solve module dependencies
- I just want *my* modularized code to stay in a single file. (But I
want to be able to work on separate files while developing, because it
is pain to jump around in one large file.)

You can replace a statement

use My::Module arg1, ..., argn;

with this functional equivalent

BEGIN {
# content of My/Module.pm here
}
BEGIN {
My::Module->import( arg1, ..., argn);
}

If My::Module doesn't have an import method that part can go.

It shouldn't be hard to do that transformation for certain modules
automatically.

Anno
 
B

Ben Morrow

Quoth (e-mail address removed)-berlin.de:
You can replace a statement

use My::Module arg1, ..., argn;

with this functional equivalent

BEGIN {
# content of My/Module.pm here
}
BEGIN {

A slight nit: I would put

$INC{'My/Module.pm'} = $0;

here, just in case anything is checking.
My::Module->import( arg1, ..., argn);
}

If My::Module doesn't have an import method that part can go.

It shouldn't be hard to do that transformation for certain modules
automatically.

....but of course it doesn't work for XS modules (which the OP wasn't
asking about, but it's worth noting anyway, especially as it will
probably seem to work on the dev box that has the modules installed :)
).

Ben

--
"Awww, I'm going to miss her."
"Don't you hate her?"
"Yes, with a fiery vengeance."
[[email protected]]

Miles to go. Little Miss Muffet counting down from 7-3-0.
[[email protected]]
 
A

anno4000

Ben Morrow said:
Quoth (e-mail address removed)-berlin.de:

A slight nit: I would put

$INC{'My/Module.pm'} = $0;

here, just in case anything is checking.

Yes, good idea.
...but of course it doesn't work for XS modules (which the OP wasn't
asking about, but it's worth noting anyway, especially as it will
probably seem to work on the dev box that has the modules installed :)
).

Both true. Inline should work, but the initial startup will be slow.

Another thing that breaks is __DATA__ sections. __FILE__ and __LINE__
will also be affected. There's probably more...

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top