There over 27,000 distributions on CPAN. I guarantee that nobody can remember how to use them all! There are probably a few dozen modules that I know inside and out and never (or almost never) need to look at their documentation. For everything else, there's perldoc!
That said, many modules fall into one of three distinct categories:
Pragmata: modules that effect the Perl language itself. Examples are: strict, warnings, indirect, Modern::Perl, etc.
These usually have lexical scope, so only apply to the code block they're used in:
{
use warnings;
# warnings are enabled here
}
# warnings are not enabled here
Exporters: modules that give you functions. Examples: Carp, LWP::Simple, etc
These generally allow you to pass a list of function names that you want to import. For example use Carp "croak".
These are generally scoped by package.
package Foo;
{
use Carp "croak";
# croak works here
{
package Bar;
# croak does not work here
}
# croak works here again
}
# croak still works here
And if you don't import croak you can generally still call it using the fully-qualified name, Carp::croak() provided somebody has loaded Carp.
Classes: for object-oriented programming. Examples include: Path::Class::File, IO::Socket, etc.
Unlike Pragmata and Exporters, there's generally no need to load classes at compile-time using a use statement; they can be loaded at run-time using require instead if desired.
Classes are not lexically or package scoped like Pragmata and Exporters. Once the Person class has been loaded I can call Person::->new anywhere in my program and it will create a Person object.
{
package Foo;
use Person;
}
{
package Bar;
my $bob = Person::->new;
}
It's possible to create modules which are none of the above, or all of the above (!) but most fall broadly into one of those three categories.
Once you're familiar with those, then it's quite easy to remember that, say, Carp is an exporter and gives you the functions carp, croak, confess, and optionally cluck; Path::Class::File is a class which has methods like openr, slurp and spew; etc.
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
| [reply] [d/l] [select] |
Most of the Perl modules come with documentation on their usage. That documentation is available locally through the perldoc command:
perldoc File::Spec
That documentation is also available online through search.cpan.org: File::Spec.
I find the "SYNOPSIS" section usually the most informative as it usually shows the intended use of a module. | [reply] [d/l] [select] |
In addition to the POD, many CPAN modules also provide test code, commonly in the t directory, which shows example usage. Furthermore, some modules provide ready-to-use example scripts; bin and examples directories are common places for those. Look at the MANIFEST link for a module on CPAN.
Of course, you can search the internet for even more examples, especially on forums such as PerlMonks. | [reply] [d/l] [select] |
Every cpan module comes with pod documentation, which you can read. It'll have usage, descriptions, examples, everything... Also, you can always use some search engines to know the usage.
| [reply] |
I am using the Enormous Power of PERL for my prestigious clients... how can I call a module?
liar XDD ;-)
...show us some code :-) | [reply] |