Perl Modules: Difference between revisions

From SlackWiki
Jump to navigation Jump to search
mNo edit summary
(I originally created this page and things have changed slightly...)
Line 13: Line 13:


==Listing The Installed Modules==
==Listing The Installed Modules==
As of Slackware 10.2 and Perl 5.8.7- you can look the <code>perllocal.pod</code> file and see the modules.


::<code>cat /usr/lib/perl5/5.8.7/i486-linux/perllocal.pod</code>
'''Easy way'''
    instmodsh
    l (L)




A much cleaner way is by using this Perl program:
'''Hard way'''
use this Perl program:
 
    #!/usr/bin/perl
    use ExtUtils::Installed;
    my $instmod = ExtUtils::Installed->new();
    foreach my $module ($instmod->modules())
    {
    my $version = $instmod->version($module) || "???";
    print "$module -- $version\n";
    }


::<code>#!/usr/bin/perl</code>
::<code>use ExtUtils::Installed;</code>
::<code>my $instmod = ExtUtils::Installed->new();</code>
::<code>foreach my $module ($instmod->modules())</code>
:::<code>{</code>
:::<code>my $version = $instmod->version($module) || "???";</code>
:::<code>print "$module -- $version\n";</code>
:::<code>}</code>


==Installing New Modules==
==Installing New Modules==
From the CPAN shell prompt, type:
From the CPAN shell prompt, type:


::<code>install &lt;Some::Module&gt;</code>
    install &lt;Some::Module&gt;




Line 40: Line 43:
A clean way is by using this Perl program:
A clean way is by using this Perl program:


::<code>#!/usr/bin/perl -w</code>
    #!/usr/bin/perl -w
::<code>use ExtUtils::Packlist;</code>
    use ExtUtils::Packlist;
::<code>use ExtUtils::Installed;</code>
    use ExtUtils::Installed;
::<code>$ARGV[0] or die "Usage: $0 Module::Name\n";</code>
    $ARGV[0] or die "Usage: $0 Module::Name\n";
::<code>my $mod = $ARGV[0];</code>
    my $mod = $ARGV[0];
::<code>my $inst = ExtUtils::Installed->new();</code>
    my $inst = ExtUtils::Installed->new();
::<code>foreach my $item (sort($inst->files($mod)))</code>
    foreach my $item (sort($inst->files($mod)))
:::<code>{</code>
    {
:::<code>print "removing $item\n";</code>
    print "removing $item\n";
:::<code>unlink $item;</code>
    unlink $item;
:::<code>}</code>
    }
::<code>my $packfile = $inst->packlist($mod)->packlist_file();</code>
    my $packfile = $inst->packlist($mod)->packlist_file();
::<code>print "removing $packfile\n";</code>
    print "removing $packfile\n";
::<code>unlink $packfile;</code>
    unlink $packfile;

Revision as of 19:41, 29 August 2012

Getting To The CPAN Prompt

To administer your Perl modules you must use the CPAN prompt. To get to the CPAN prompt, as root type:

perl -MCPAN -e shell

If this is the first time that you have entered the CPAN shell, you will be asked some set-up questions that will allow the shell to access CPAN's servers to get modules. Just read the questions and answer them.

If you ever need to re-run the set-up again, enter the CPAN shell and then type:

o conf init


Listing The Installed Modules

Easy way

    instmodsh
    l (L)


Hard way use this Perl program:

    #!/usr/bin/perl
    use ExtUtils::Installed;
    my $instmod = ExtUtils::Installed->new();
    foreach my $module ($instmod->modules())
    {
    my $version = $instmod->version($module) || "???";
    print "$module -- $version\n";
    }


Installing New Modules

From the CPAN shell prompt, type:

    install <Some::Module>


Removing Modules

A clean way is by using this Perl program:

    #!/usr/bin/perl -w
    use ExtUtils::Packlist;
    use ExtUtils::Installed;
    $ARGV[0] or die "Usage: $0 Module::Name\n";
    my $mod = $ARGV[0];
    my $inst = ExtUtils::Installed->new();
    foreach my $item (sort($inst->files($mod)))
    {
    print "removing $item\n";
    unlink $item;
    }
    my $packfile = $inst->packlist($mod)->packlist_file();
    print "removing $packfile\n";
    unlink $packfile;