Over-testing

Quote

Every line of code you write has a cost. It takes time to write it, it takes time to update it, and it takes time to read and understand it. Thus it follows that the benefit derived must be greater than the cost to make it. In the case of over-testing, that’s by definition not the case.
Testing like the TSA by David Heinemeier Hansson

I’m definitely guilty of this, and its a hard habit to break.

Introducing WebService::TVDB

Note: This module is now called WebService::TVDB, as it’s a more appropriate namespace. Net::TVDB will be removed from the CPAN.

WebService::TVDB is a Perl 5 interface to TheTVDB.com, an open database containing a lot of great information on TV series.

The synopsis shows how to use it:

my $tvdb = WebService::TVDB->new(api_key => 'ABC123', language => 'English');
 
my $series_list = $tvdb->search('men behaving badly');
 
my $series = @{$series_list}[0];
# $series is a WebService::TVDB::Series
say $series->SeriesName;
say $series->overview;
 
# fetches full series data
$series->fetch();
 
say $series->Rating;
say $series->Status;
 
for my $episode (@{ $series->episodes }){
  # $episode is a WebService::TVDB::Episode
  say $episode->Overview;
  say $episode->FirstAired;
}
 
for my $actor (@{ $series->actors }){
  # $actor is a WebService::TVDB::Actor
  say $actor->Name;
  say $actor->Role;
}
 
for my $banner (@{ $series->banners }){
  # $banner is a WebService::TVDB::Banner
  say $banner->Rating;
  say $banner->url;
}

I am going to use this as an extra source to App::MP4Meta. It currently uses the IMDB, but while its good for films it doesn’t have as much data on TV series. TheTVDB.com should provide a much better source.

A new version of App::MP4Meta which uses WebService::TVDB should be ready in the next few days.

Links

Related Posts

Building Dist::Zilla Distributions with BuildBot

Recently I have been using Buildbot for continuous integration for a number of my open source projects, including some Dist::Zilla based Perl projects (see http://ci.arjones.co.uk/).

Buildbot is very customisable, so I have created some custom build steps for Dist::Zilla based projects. The main benefit is instead of seeing this in your waterfall.

Before Dist::Zilla Steps

You see this.

After Dist::Zilla Steps

OK, so not too ground-breaking, but then it wasn’t a lot of work :-) .

To use it, first download or clone the code and put it somewhere near your buildmaster.

Then, you can use something like the following in your Buildbot configuration file.

from dzil import DzilDependencies, DzilSmoke
 
factory.addStep(DzilDependencies())
factory.addStep(DzilSmoke())

Currently the following steps are implemented:

  • DzilAuthorDependencies
  • DzilDependencies
  • DzilSmoke
  • DzilTest

For more information, see the Github page. If you like, you can also see my configuration files, which I will explain in a future post :-) .

Get all documents from your KinoSearch1 index

I wanted a script to dump the entire contents of my KinoSearch1 index into a flat file. Turns out this was pretty easy by using the KinoSearch1::Index::IndexReader.

The following Gist shows how I was able to do this.

#!/usr/bin/perl
use strict;
use warnings;

use KinoSearch1::Index::IndexReader;

my $r = KinoSearch1::Index::IndexReader->new( invindex => '/path/to/index' );

# get one or more readers
my @readers = ref $r->{sub_readers} eq 'ARRAY' ? @{ $r->{sub_readers} } : $r;

for my $reader (@readers) {
    print "Segment "
      . $reader->get_seg_name . " has "
      . $reader->max_doc
      . " docs\n";
    
    # the index is numbered from 0 to max_doc, so just loop
    # through them and get the documents
    for(my $i = 0; $i < $reader->max_doc; $i ++){
        # A KinoSearch1::Document::Doc object
        my $doc = $reader->fetch_doc($i);
        
        # this will depend on how your index has been set up
        my $title = $doc->get_value('title');
        print "$title\n";
    }

}
print "Total documents: " . $r->max_doc . " in " . @readers . " segments\n";

Pretty self-explanatory. Let me know if you have any questions.

Ant Task to generate an XML Sitemap

I use Ant for more than just Java projects, including building my own website. So I have written an Ant task to generate an XML Sitemap and released the first version.

Here is an example of using the task:

<target name="generate_sitemap" description="generates the sitemap">
    <taskdef name="sitemap" classname="uk.co.arjones.ant.task.Sitemap" />
    <sitemap url="http://andrew-jones.com" destdir="${BUILD_DIR}" lastmod="now" gzip="yes">
        <fileset dir="${BUILD_DIR}">
            <include name="**.htm"/>
            <include name="**.html"/>
            <exclude name="google*"/>
        </fileset>
    </sitemap>
</target>

Its pretty self-explanatory. For more information and to download it, go to the project page on GitHub.

Perl, Wildcards and the Windows Command Line

When developing for multiple platforms, its always the little things that catch you out.

Heres one example I found while developing gcal, a Command Line Interface to Google Calendar. On Unix (including Mac OS X shells) wildcard expansion is done by the shell, and then the expanded list of files is passed on to the program being run. On Windows, the shell doesn’t do any expansion, and it’s up to programs to do the expansion[1].

To get around this in Perl, you can do something like this[2].

my @args = ($^O eq 'MSWin32') ? map { glob } @ARGV : @ARGV;

Here we are passing all the arguments to glob, which will do the shell expansions, including wildcards. We only want to do this for Windows, as if you use it on Unix you risk globbing real file names – asterisks and question marks are valid characters in Unix file names.

Related Posts

References

  1. The difference in wildcard expansion between Windows and unix/Macintosh []
  2. How can I handle wildcards on the command line using Perl on Windows? – Stack Overflow []