Posts Tagged ‘perl’

dh-make-perl will rock your socks

Wednesday, July 2nd, 2008

dh-make-perl is the most awesome Debian package /ever/.

dh-make-perl --cpan Some::Module --build
sudo dpkg -i libsome-module-0.1-1_all.deb

Done.

Dependencies

If you have apt-file installed and Some::Module requires Lib::Foo for which a Debian package is available, the dependancy will automatically be created. If Lib::Foo does not have a Debian package already available, you will likely need to manually run dh-make-perl on Lib::Foo first.

I haven’t seen the apt-file trick mentioned elsewhere. Honestly when someone mentioned it on IRC I didn’t believe him. Sure enough, looking at the source for dh-make-perl revealed that it does indeed check apt-file for each module that Some::Module lists as required in the META.yml.

Why?

Now dpkg/apt know that you have Some::Module installed. If an official package for Some::Module comes out, it will likely have the same name and if it is for a newer version of Some::Module aptitude upgrade will automagically upgrade you to it. The real win is ease of cleanly uninstalling though. How many times have you found what you thought was the perfect module for task XYZ and installed it. Only to find that it isn’t so hot 5 minutes after beginning to use it. Making sure ‘make uninstall‘ really uninstalled every thing can be a pain.

Module::Signature Rocks My Socks

Sunday, June 1st, 2008

Just discovered the perl module Module::Signature by 唐鳳 (Audrey Tang) the other day. It’s pretty spiffy.

Implementing is easy (stolen from the docs):

MakeMaker:

    WriteMakefile(
        (MM->can('signature_target') ? (SIGN => 1) : ()),
        # ... original arguments ...
    );

Module::Build:

   Module::Build->new(
        (sign => 1),
        # ... original arguments ...
    )->create_build_script;

Don’t forget to add SIGNATURE to your MANIFEST if needed.

Then when running make dist you will be prompted for the pass phrase for your gpg key. For extra goodness, add 0-signature.t to your tests. It includes a single test that verifies the package cryptographically during make test if the TEST_SIGNATURE environment variable is set.

If you know waltman and haven’t heard of this module, yell at him for not telling you about it, he’s mentioned in the AUTHORS file for his stellar documentation patches.

Adding a Datastore to an RRD File

Sunday, December 30th, 2007

Mainly for personal future reference.

Adding a DS to a bunch of RRD files is a big pain, RRD doesn’t have any sort of native mechanism for doing this. The usual procedure is exporting the RRD data to XML, creating a new rrd file with the old datastores plus your new ones, then importing the data back in from the XML.

A while back I needed to do this for a load of RRDs so I wrote a quick and dirty bash script for it. Today I had reason to add a DS again but couldn’t find my script. A bit of googling was no help either, surely other people have this problem too? I discovered Nicola Worthington’s RRD::Simple contains add_source method so a few moments in TextMate later we have:

#!/usr/bin/perl

use strict;
use warnings;

use RRD::Simple();

my $rrd_path = /path/to/dir/of/rrds/;
my @rrd_files = <$rrd_path/*.rrd>;

my $rrd = RRD::Simple->new();

for my $file (@rrd_files) {
    print Processing $file…;
    $rrd->add_source($file, DS_name => DERIVE);
    print  ok.\n;
}