<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>use Modern::Perl;</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/marc_sebastian_jakobs/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/marc_sebastian_jakobs/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/marc_sebastian_jakobs//94</id>
    <updated>2009-11-29T08:24:25Z</updated>
    <subtitle>Tips and tricks for Perl developers.</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>How to set-up your own CPAN mirror</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/marc_sebastian_jakobs/2009/11/how-to-set-up-you-own-cpan-mirror.html" />
    <id>tag:blogs.perl.org,2009:/users/marc_sebastian_jakobs//94.53</id>

    <published>2009-11-29T07:51:05Z</published>
    <updated>2009-11-29T08:24:25Z</updated>

    <summary>Are you a sysadmin and you&apos;re running servers with a lot of Perl code and Perl modules installed? You are a Perl hacker, who wish to access the complete CPAN repository on his notebook even when not connected to the...</summary>
    <author>
        <name>Marc</name>
        
    </author>
    
        <category term="CPAN" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Perl Modules I Like" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Perl for Admins" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cpan" label="CPAN" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/marc_sebastian_jakobs/">
        <![CDATA[<p>Are you a sysadmin and you're running servers with a lot of Perl code and Perl modules installed? You are a Perl hacker, who wish to access the complete CPAN repository on his notebook even when not connected to the internet?</p>

<p>Why not set-up your own CPAN-Mirror then? It's really easy.</p>]]>
        <![CDATA[<p>All you need is to install the Perl module called CPAN::Mini.</p>

<pre><code>cpan CPAN::Mini</code></pre>

<p>will do that for you.</p>

<p>Here is a little Perl Script that Mirrors the CPAN Mirror of your choice to your local hard-drive:</p>

<pre><code>#!/usr/bin/env perl

<p>$> = 33;        # switch effective user id to www-data</p>

<p>use CPAN::Mini;</p>

<p>CPAN::Mini->update_mirror(</p>

<p>   remote => "ftp://ftp.cpan.org/pub/CPAN", <br />
   local  => "/var/www/localhost/mirrors/cpan",<br />
   trace  => ($ARGV[0] ? 1 : 0)<br />
);<br />
</code></pre></p>

<p>The trace option will active debug output. If you call your little cpan-mirror script with whatever command line argument, it will tell CPAN::Mini to print out some activity log. If you call it without any argument, it will be silent - which is nice when running as a cronjob.</p>

<p>Alternatively you could go and use the "minicpan" command line tool that comes with the CPAN::Mini bundle (installs to /usr/local/bin by default). Type in "perldoc minicpan" for details how to use it.</p>

<p>Next, you should make sure that you can reach your CPAN-Mirror via HTTP or FTP. This means you should make sure to mirror into a directory that can be accessed by your local web- or ftp-server.</p>

<p>Then, go and tell your CPAN shell to use your mirror. Type in "cpan" to start the CPAN shell.</p>

<pre><code>cpan[1]> o conf urllist 'http://localhost/mirrors/cpan/' 'ftp://ftp.cpan.org/pub/CPAN' 'ftp://ftp.funet.fi/pub/languages/perl/CPAN'
cpan[2]> o conf commit
</code></pre>

<p>You should specify your local web- or ftp-server as first argument in the list of CPAN mirrors. Add as many mirrors as you like. A full list of CPAN mirrors in your country can be obtained <a href="http://mirrors.cpan.org/">here</a>.</p>]]>
    </content>
</entry>

<entry>
    <title>Perl6::Junction</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/marc_sebastian_jakobs/2009/11/my-favorite-module-of-the-month-perl6junction.html" />
    <id>tag:blogs.perl.org,2009:/users/marc_sebastian_jakobs//94.50</id>

    <published>2009-11-28T06:10:09Z</published>
    <updated>2009-11-28T08:39:48Z</updated>

    <summary>Today I&apos;d like to introduce you a Perl module I really like and use a lot in my code. It&apos;s called Perl6::Junction and you can get it from CPAN. Please have a look what it can do for you....</summary>
    <author>
        <name>Marc</name>
        
    </author>
    
        <category term="CPAN" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Perl Modules I Like" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cpan" label="cpan" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="module" label="module" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl6" label="perl6" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/marc_sebastian_jakobs/">
        <![CDATA[<p>Today I'd like to introduce you a Perl module I really like and use a lot in my code. It's called Perl6::Junction and you can get it from <a href="http://search.cpan.org/~cfranks/Perl6-Junction-1.40000/">CPAN</a>.</p>

<p>Please have a look what it can do for you.</p>]]>
        <![CDATA[<p>Perl6::Junction comes in when you're working on Arrays. For example, if you'd like to search your array if it contains a defined element, usually your code will look like this:</p>

<pre><code>my @animal = ('squirrel', 'cat', 'catfish', 'sausage-dog', 'guinea pig', 'pig');

<p># using a foreach loop to walk trough all array elements<br />
#<br />
foreach my $animal ( @animal ) {</p>

<p>    if ( $animal eq 'guinea pig' ) {</p>

<p>        # found my lovely guinea pig in this group of animals!<br />
        last;<br />
    }<br />
}</p>

<p># you could also go and use grep to search your array<br />
#<br />
if ( grep(/^guinea pig$/, @animal) ) {</p>

<p>    # found it!<br />
}<br />
</code></pre></p>

<p>But especially <em>grep</em> is not easy to use for beginners and one could make many mistakes when using it.</p>

<p>For example, just calling grep like <strong>grep('cat', @animal)</strong> will match every string in the array because it excepts a BLOCK or regular expression and not a string as first argument and interprets the string as 'TRUE' which matches everything.</p>

<p>Doing a <strong>grep(/cat/, @animal)</strong> will match every array element that <strong>contains</strong> the string 'cat'. It would match 'cat' and 'catfish' in this example.</p>

<p>Most of the time, this is not really what you want.</p>

<p>When using Perl6::Junction it becomes as easy as this:</p>

<pre><code>use Perl6::Junction qw( all any none one );

<p>my @animal = ('squirrel', 'cat', 'catfish', 'sausage-dog', 'guinea pig', 'pig');</p>

<p>if ( any(@animal) eq 'guinea pig' ) {</p>

<p>    # one or more guinea pig's in the list of animals!<br />
}</p>

<p>if ( one(@ainmal) eq 'guinea pig' ) {</p>

<p>    # exactly one guinea pig in the list<br />
}</p>

<p>my @herd = ('sheep', 'sheep', 'wolf', 'sheep', 'sheep');</p>

<p>unless ( all(@herd) eq 'sheep' ) {</p>

<p>    # watch out!<br />
}<br />
</code></pre></p>

<p>Pretty nice, right? :)</p>

<p>If I caught your interest, please have a look at more examples in the <a href="http://search.cpan.org/~cfranks/Perl6-Junction-1.40000/lib/Perl6/Junction.pm">modules documentation at CPAN</a>.</p>]]>
    </content>
</entry>

<entry>
    <title>How to install Perl Modules from CPAN in the Unix user-space</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/marc_sebastian_jakobs/2009/11/how-to-install-perl-modules-from-cpan-in-the-unix-user-space.html" />
    <id>tag:blogs.perl.org,2009:/users/marc_sebastian_jakobs//94.52</id>

    <published>2009-11-27T17:12:00Z</published>
    <updated>2009-11-27T11:02:50Z</updated>

    <summary>If you&apos;re a sysadmin or if you run a Perl software development environment, you might want to give your users or developers the possibility to install Perl modules from CPAN into their private user-space. This could be helpful for trying...</summary>
    <author>
        <name>Marc</name>
        
    </author>
    
        <category term="CPAN" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Perl &amp; Unix" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Perl for Admins" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Tips &amp; Tricks" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cpan" label="CPAN" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="unix" label="Unix" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/marc_sebastian_jakobs/">
        <![CDATA[<p>If you're a sysadmin or if you run a Perl software development environment, you might want to give your users or developers the possibility to install Perl modules from CPAN into their private user-space. This could be helpful for trying out new modules or playing around with modules that might be used in production at a later time. Or, if a developer wants to test a new version of a module without overwriting the system-wide installed version of that module.</p>

<p>Here is a step by step instruction how you could set-up user-space CPAN support.</p>]]>
        <![CDATA[<p>In the home-directory of the user, you need to create a file called</p>

<pre><code>~/.cpan/CPAN/MyConfig.pm</code></pre>

<p>which is a customized configuration file for the CPAN shell. If you like, you could use the system-wide CPAN config as a template for this file and just overwrite the appropriate attributes.</p>

<p>One way to find the system wide CPAN config is by running a</p>

<pre><code>locate CPAN/Config.pm</code></pre>

<p>and then copy the file over to ~/.cpan/CPAN/MyConfig.pm. Open the MyConfig.pm file in the editor of your choice and change the following lines:</p>

<pre><code>'build_dir' => qq[$ENV{HOME}/.cpan/build],
'cpan_home' => qq[$ENV{HOME}/.cpan],
'histfile' => qq[$ENV{HOME}/.cpan/histfile],
'keep_source_where' => qq[$ENV{HOME}/.cpan/sources],
'makepl_arg' => q[PREFIX=~/lib/perl5 LIB=~/lib/perl5/lib INSTALLMAN1DIR=~/lib/perl5/man1 INSTALLMAN3DIR=~/lib/perl5/man3]
'mbuild_arg' => qq[--extra_linker_flags -L$ENV{HOME}/lib],
'mbuildpl_arg' => qq[--install_base $ENV{HOME}],
</code></pre>

<p>If you like to use a special CPAN mirror (maybe your own local mirror server) for the user, then also change the following line in MyConfig.pm:</p>

<pre><code>'urllist' => [q[http://cpan.mirror1.mydomain.com/], q[http://cpan.mirror2.mydomain.com/]],</code></pre>

<p>Next you need to create the directories where the user-space Perl modules and man-pages will be installed to:</p>

<pre><code>~/lib/perl5/bin
~/lib/perl5/lib
~/lib/perl5/man
</code></pre>

<p>At last, you need to put the following lines into the users ~/.bash_profile (or whatever file your shell runs at login) file:</p>

<pre><code>export PERL5LIB=${PERL5LIB}:~/lib/perl5/lib
export MANPATH=~/lib/perl5/man
</code></pre>

<p>which tells the Perl interpreter to look for modules first in ~/lib/perl5/lib and then search in the system wide directories. The same goes for the man-pages, which are living in ~/lib/perl5/man.</p>

<p>To give your new set-up a try, login with the user-account and install the following module:</p>

<pre><code>cpan Acme::Bleach</code></pre>

<p>and see if you can use it</p>

<pre><code>man Acme::Bleach
perl -e 'use Acme::Bleach;'
</code></pre>

<p>One more thing :)</p>

<p>If you copy your brand-new set-up to /etc/skel</p>

<pre><code>/etc/skel/.cpan/CPAN/MyConfig.pm
/etc/skel/.bash_profile
/etc/skel/lib/perl5
/etc/skel/lib/perl5/lib
/etc/skel/lib/perl5/bin
/etc/skel/lib/perl5/man
</code></pre>

<p>it will be installed automatically for each new Unix user that you create.</p>]]>
    </content>
</entry>

<entry>
    <title>How to install a Perl Module from CPAN</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/marc_sebastian_jakobs/2009/11/how-to-install-a-cpan-perl-module.html" />
    <id>tag:blogs.perl.org,2009:/users/marc_sebastian_jakobs//94.51</id>

    <published>2009-11-26T19:29:03Z</published>
    <updated>2009-11-27T09:48:32Z</updated>

    <summary>Developers and admins who are new to Perl might wonder how they can install one of the 18.000 available Perl Modules from http://search.cpan.org. One of the many ways to do this is to call the CPAN shell from the Unix...</summary>
    <author>
        <name>Marc</name>
        
    </author>
    
        <category term="CPAN" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Perl for Beginners" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cpan" label="CPAN" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/marc_sebastian_jakobs/">
        <![CDATA[<p>Developers and admins who are new to Perl might wonder how they can install one of the 18.000 available Perl Modules from <a href="http://search.cpan.org">http://search.cpan.org</a>.</p>

<p>One of the many ways to do this is to call the <span class="caps">CPAN </span>shell from the Unix command line, like so:</p>

<pre><code>cpan Modern::Perl</code></pre>

<p>You could also go and give the cpan command a list of modules that you like to install:</p>

<pre><code>cpan Modern::Perl DBI YAML JSON::XS</code></pre>

<p>However, if you just type in "cpan" you start the interactive <span class="caps">CPAN </span>shell, where you can install a module by typing:</p>

<pre><code>install Modern::Perl</code></pre>

<p>If you just type in “i Modern::Perl” you get just some information about the module.</p>

<p>The <span class="caps">CPAN </span>shell downloads the archive into your ~/.cpan/build directory and extracts the content there. If the module can not be installed because tests are failing, you could go into that directory and do a</p>

<pre><code>perl Makefile.PL
make
make test
make install</code></pre>

<p>by hand and eventually fix the problem that caused the tests to fail - or just force to install the module and ignore the tests if you know what you’re doing.</p>]]>
        
    </content>
</entry>

</feed>
