Learning to use META.yml

barbie on 2007-02-23T14:17:46

I'd been added tests to Data-Phrasebook and decided that I ought to get a proper META.yml sorted for all my modules, so have been slowly going through them all, update POD, tests and code along the way too. However, it occurred to me that I should actually test whether I have a valid META.yml file. A quick search of CPAN and I discovered Test-YAML-Valid. I wrote a short test file (93metatest.t):

use Test::More;

eval "use Test::YAML::Valid";
if($@) {
    plan skip_all => "Test::YAML::Valid required for testing YAML";
} else {
    plan tests => 1;
    yaml_file_ok('META.yml');
}
and ran it:
C:\Perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harness(1, 'blib\lib'
, 'blib\arch')" t/93metatest.t
t/93metatest....1..1

#   Failed test 'META.yml contains valid YAML'
#   at t/93metatest.t line 8.
# Looks like you failed 1 test of 1.
not ok 1 - META.yml contains valid YAML
not ok 1 - META.yml contains valid YAML
dubious
        Test returned status 1 (wstat 256, 0x100)
DIED. FAILED test 1
        Failed 1/1 tests, 0.00% okay
Failed Test    Stat Wstat Total Fail  Failed  List of Failed
-------------------------------------------------------------------------------
t/93metatest.t    1   256     1    1 100.00%  1
Failed 1/1 test scripts, 0.00% okay. 1/1 subtests failed, 0.00% okay.

Okay so I've created a bad META.yml file, but what is wrong with it? I ended up having to create a new script just to see the errors that YAML.pm was producing. As a consequence I'm now writing a patch for Jonathan to provide the appropriate output in the module.

However, in doing all this, I have learnt a bit more about YAML itself. I discovered a few errors with my META.yml which basically boiled down to the following rules:

  1. Don't use tabs

    I'm not entirely convinced, even after reading the spec, but although there are places the tab character can be used, it is probably far safer to not use them at all. This only arose because having reinstalled all my apps, I hadn't gotten around to ensuring the tab key inserted spaces.

  2. EOF must be preceeded by a newline character

    I think I can understand this one, if the data is being streamed, but it caught me out.

  3. Indentation is everything

    When I write notes I tend to have the title and the bullet (a dash) lined up. I fell foul of the indentation requirement in my no_index/directory section. However, the error that it produced took a while to figure out that it's the wrong error for this situation, although I can see why it produced the error.

Thankfully I only uploaded 5 distributions, and not all 21, so I'll be clean them all up before the next release session.