I'm writing a small Perl application, and I have a few questions regarding modules and their version numbers:
1) In order to check whether a module is installed, I currently do the following:
eval
{
require Term::Title;
};
if ( $@ )
{
warn the user that Term::Title was not found,
so he'll be missing some feature in my application
}
Is there a better way to detect whether the module is there?
Say I've changed the module, it has an error inside, and it won't load properly, but the module is there. Or maybe the user does not have file permissions to read the module file, but the file is. In this case, I would like the application to fail with the right error message, instead of just blindly reporting that the module is not there at all.
2) How do I reliably compare version numbers? I've seen that there are more than one version number formats, I'm not sure if a simple string or a simple numeric compare will do.
This is what I would like to achieve:
require Term::Title;
if ( ! is_module_version_at_least( "Term::Title", "a.b" ) )
{
print "I can use this module version, but it has known bugs and
+ you should upgrade it."
}
That is, I would like some example code for routine is_module_version_at_least.
3) I'm finding the problem that some perl distributions do not ship with some modules by default, and others have older versions. I do not think that the end user should necessarily know how to install modules from CPAN or the like. You need different command-line incantations in order to install modules CPAN under Cygwin (no sudo available), under Debian or under Windows (maybe ActiveState's ppm). A particular application user may not necessarily have root privileges to install modules for all Perl users.
I would like to ship some CPAN module XXX together with my application. If the currently-installed perl has the same or newer version of XXX, I would like to use the already-installed versions. If not, I would like the application to fall-back to the version supplied with it.
How do I achieve that? Or maybe you think of a better approach to distribute applications and modules?
Many thanks,
Ruben
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.