My Favorite Module: CPAN
by Aighearach (Initiate) on May 21, 2000 at 20:03 UTC
|
The Module of Modules: CPAN
Modules make possible in an afternoon, what would take many months without them. It is because of this the time needed to learn to use them is well spent.
Once you learn to effectively use modules, you will wonder how you ever got by without them. Switching from Perl without modules, to Perl with modules, is as big a step is ease of use and project clarity as moving from C to Perl was is the first place.
So, my favorite module is the module that brings me my modules: CPAN.pm
This should have come with your perl dist. I won't get into how to use it in your program, as most modules are used; no, there is a very special power within CPAN that no monk can live without. This is the CPAN shell. To invoke, issue the following incantation:
perl -MCPAN -e'shell'
It will probably tell you some things, like that there is a newer version of the spell, and that you should fetch some network Bundle:: 's. Follow these instructions, always.
Now, to look for a module, light your purifying incense, and chant:
i /keyword/
Give it a try. If you don't know what to search for, try i /lingua/.
When you find something that sounds way-super-cool, concentrate on:
install package::name
For example, you might want to install Lingua::EN::Gender. This will download the tarball, configure it, make it, make test and make install it for you, saving you the trouble.
Why should a Perl hacker have to wrestle with gcc? I say, let's leave the C coding to St. Wall, and his Disciples.
When you first run it, it will ask you some congif questions; I recommend asking the Gods to install any dependencies for you; I have found them to be better at knowing these things than I am.
It might help to run this as root.
If make test fails, you can probably go to $HOME/.cpan/build and make install. Usually when make test fails, it is becuase no time was spent developing the test, and instead of making it always pass, they like to make it always fail... but this is rare. Most packages are written well.
Paris Sinclair | 4a75737420416e6f74686572
pariss@efn.org | 205065726c204861636b6572
I wear my Geek Code on my finger.
| [reply] |
|
|
I like the writing style -- informative, entertaining, and easy to read. Perhaps you (or someone else) could add a footnote addressing some of the cross-platform issues in installing modules. Personally, I've never installed a module for the Windows version of Perl, and perhaps it works exactly the same way as you've described. Deep down though, I don't really believe this is possible.
Thanks!
e-mail neshura
| [reply] |
|
|
Thank you for your kind words.
>Perhaps you (or someone else) could add a footnote addressing some of the cross-platform issues in installing modules.
It would have to be somebody else. I am in complete agreement with St. Larry Wall, who teaches:
| Perl is, in intent, a cleaned up and summarized version of that wonderful semi-natural language known as "Unix".
|
But you are right, there are many levels of enlightenment, and it would be nice if somebody could amend instructions for those multitudes who walk Another Path.
Paris Sinclair | 4a75737420416e6f74686572
pariss@efn.org | 205065726c204861636b6572
I wear my Geek Code on my finger.
| [reply] |
|
|
Yup, unfortunately it doesn't work exactly like that on Windows. If I could figure it out, I'd tell you all the differences, but unfortunately I can't get it to do anything :(
Anyone have any tips for a novice?
Nodecam
| [reply] |
|
|
|
|
This (possibly slightly expanded) could make a very nice
tutorial about the CPAN module.
--ZZamboni
| [reply] |
|
|
install package::name
For example, you might want to install Lingua::EN::Gender. This will download the tarball, configure it, make it, make test and make install it for you, saving you the trouble. Why should a Perl hacker have to wrestle with gcc? I say, let's leave the C coding to St. Wall, and his Disciples.
When you first run it, it will ask you some congif questions; I recommend asking the Gods to install any dependencies for you; I have found them to be better at knowing these things than I am.
It might help to run this as root.
This last comment perplexes me a little. When 'might' it help run this as root?
My experience has included piles of Perl development but very little module installation. In the last few months I've been trying my hand at this on the Linux boxes I use as webmaster/developer, but I keep running into privilege violations, and I'm not really sure why. It's a little frustrating, and I hope this post isn't going to increase my 'goof!' rating on PM.
What I'd like to do is create a personal library of stuff from CPAN that my web provider has not yet installed (this is on a Linux box). I would then do a use lib in my code to remind Perl where that module is.
I assume that when I try to install stuff from CPAN (using the CPAN module), it thinks I'm running as root, hence the privilege violations. What do I have to do to get the CPAN installation process to understand that I don't want to alter the system-wide Perl installation, I just want to affect my installation (that is, just my directories)? The answer so far has eluded me.
Any guidance would be most appreciate. Thanks.
--t. alex
"Excellent. Release the hounds." -- Monty Burns.
| [reply] [d/l] |
|
|
Try creating a file ~/.cpan/CPAN/MyConfig.pm that overrides
likely-looking values in CPAN::Config. (eg where you build
stuff, where you install it, etc). That should let you use
CPAN to install anything you want into a directory tree of
your choice. You can then use lib as you do now.
| [reply] |
|
|
The installation location is determined by the settings built into your perl at compile time. The working directory is set in CPAN::Config.pm. Generally to use the CPAN module for user module installation, you'll want to install your own perl. Usually this is done with the binaries in ~/bin and the libs in ~/lib/perl5.
-- Snazzy tagline here
| [reply] |
RE: New Module Area?
by ZZamboni (Curate) on May 19, 2000 at 19:28 UTC
|
How about expanding this idea into a general "Reviews" section,
with subsections for Modules, books, web sites, etc. To keep
the quality good, it could have a peer-review process, in which
the posts are reviewed by a number of other monks, and only then
it gets posted for everyone to see.
--ZZamboni (who has been sick at home the last couple of days, and therefore not as active as usual)
| [reply] |
|
|
Great idea! No one has time to review every module and
every book, but lots of people have time to review one or
two. There are more than a few modules that have saved
my sorry butt on various occasions -- I'd like a chance
to sing their praises (tempered with appropriate criticism, of course).
I enjoy chromatic's book reviews on /. and would
like to see such things here. (Heh heh...I wonder who's going
to step up and write a review of La Camel?)
e-mail neshura
| [reply] |
|
|
| [reply] |
|
|
I agree
See my previous post Reviews section on the same topic. I think the voting idea could be particularly useful.
Perhaps a vote on both the book and each review. Then a lot more monks would be able to offer their own ' mini-review '.
The vote for each book should be always visible - that way AMs would benefit as well. Of course Amazon may have copyrighted this idea and we'll all end up in court :-)
| [reply] |
RE: New Module Area?
by lhoward (Vicar) on May 21, 2000 at 06:58 UTC
|
There are something like 1500
modules on CPAN with more being added every day.
Being "introduced" to modules without having to go
out and look for them when you need them enables you
to be prepared for new challenges.
I think it would be fantastic to have a "modules" area
on perlmonks that would introduce module.
Maybe have a module of the week (or day, or whatever)
and a section listing
"new additions to CPAN".
Knowledge is power and knowing what modules
are out there can make your job as a perl programmer
much easier. | [reply] |
RE: New Module Area?
by turnstep (Parson) on May 19, 2000 at 19:22 UTC
|
I tend to think of modules as very specific tools. If I have a
certain task I need to perform, I check CPAN to see what sort of
tools are available for the job at hand. I might not know
everything that is available out there, but that's only
because I never had a need to go looking for them. Still,
I like the idea of having people extoll their favorite
modules - perhaps in the Perl Monks discussion section? Perhaps
as a future voting topic? Perhaps "The module I use the most
is..." (CGI, LWP, Benchmark, Date, String, Math, etc...)
| [reply] |
|
|
To refine this idea somewhat more, consider that there are quite a few Date modules (Date::Manip and Date::SimpleCalc) come to mind. How about writing up "In this situation I would use that module. Here's why." If you would roll your own solution (big can of worms here), explain why too.
For example, I stay away from Date::Manip because it's huge and usually overkill for my purposes. One of the other modules is usually more appropriate, or even using some special chromatic library code I wrote days ago (if I were in the habit of doing such a thing) is a better solution for performance reasons.
| [reply] |