FAQ: p2c - pkgsrc to CPAN version compare

Welcome to the FAQ (2008-09-23)

Well, let' have a small FAQ about various things here. I'll give you some code snippets which will make your life as maintainer of Perl packages alot easier than before.

The link section

Mail subscriptions/feeds/etc

I won't implement a feature which is based on a mail subscription in the near future. I think YOU as maintainer should care for your packages and this tool can be good help. I would like you to pull the information regulary and process it yourself. Have a look at the code snippets to see how you can use p2c for your needs. However, I like the idea of RSS xml feeds and I might implement something in the near future.(top)

Getting notified of updateable packages

Use your cron daemon and a small Perl script to get notified if your name appears on the maintainer list for updates.

#!/usr/pkg/bin/perl 
# Shows pkg count to update for a maintainer
use strict;
use warnings;
use LWP::Simple;
use YAML::Syck;

my $content;
my $url = "http://pkgbox.org/p2c/maintainer.yml";
my $myself = $ARGV[0]
  || die "Specify maintainer email on the command line";
unless ( defined( $content = get $url) ) {
    die "could not get $url\n";
}
my %maintainer = Load($content);
print "$maintainer{$myself} updates for me.\n"
  if ( exists $maintainer{$myself} );
Use this snippet and run it via cron. It will notify you via mail how many updates are waiting for you. The output of the script looks like this:
rhaen@wiesel $ ./updatecheck.pl rhaen@NetBSD.org
2 updates for me.
(top)

What packages should be updated?

You can use the report by maintainer to retrieve informations about your packages which can be updated. The following snippet will help you with a small report.

#!/usr/pkg/bin/perl
# Shows information about pkg and cpan version
use warnings;
use strict;
use LWP::Simple;
use YAML::Syck;

my $content;
my $url = $ARGV[0]
  || die "Specify URL to the maintainer.yml file";

unless ( defined( $content = get $url) ) {
    die "could not get $url\n";
}
my @maint_pkgs = Load($content);
for my $pkgs ( 0 .. $#maint_pkgs ) {
    printf(
        "You should update %s from %s to %s.\n",
        $maint_pkgs[$pkgs]{PKGSRCPKG},
        $maint_pkgs[$pkgs]{DISTINFOVER},
        $maint_pkgs[$pkgs]{CPANVERSION},
    );
}
This might be a help to run it on a frequently basis inside your cron. Cron will send you a mail with the relevant information about the packages. The output of the small script above looks like this:
rhaen@wiesel $ ./p5-info.pl  http://pkgbox.org/p2c/rhaen__at__NetBSD.org.yml
You should update p5-RRD-Simple from 1.43 to 1.44.
You should update p5-CGI-Application-Dispatch from 2.12 to 2.13.
(top)