File Coverage

File:blib/lib/Test/YAML/Meta.pm
Coverage:97.2%

linestmtbrancondsubpodtimecode
1package Test::YAML::Meta;
2
3
4
4
4
0
0
0
use warnings;
4
4
4
4
0
0
0
use strict;
5
6
4
4
4
0
0
0
use vars qw($VERSION);
7$VERSION = '0.04';
8
9#----------------------------------------------------------------------------
10
11 - 60
=head1 NAME

Test::YAML::Meta - Validation of the META.yml file in a distribution.

=head1 SYNOPSIS

There are two forms this module can be used. 

The first is a standalone test of your distribution's META.yml file:

  use Test::More;
  eval "use Test::YAML::Meta";
  plan skip_all => "Test::YAML::Meta required for testing META.yml" if $@;
  meta_yaml_ok();

Note that you may provide an optional label/comment/message/etc to the 
function, or one will be created automatically.

The second form allows you to test other META.yml files, or specify a specific
version you wish to test against:

  use Test::More test => 6;
  use Test::YAML::Meta;

  # specify a file and specification version
  meta_spec_ok('META.yml','1.3',$msg);       

  # specify the specification version to validate the local META.yml
  meta_spec_ok(undef,'1.3',$msg);       

  # specify a file, where the specification version is deduced 
  # from the file itself
  meta_spec_ok('META.yml',undef,$msg);       

Note that this form requires you to specify the number of tests you will be
running in your test script. Also note that each 'meta_spec_ok' is actually 2
tests under the hood.

=head1 DESCRIPTION

This module was written to ensure that a META.yml file, provided with a 
standard distribution uploaded to CPAN, meets the specifications that slowly 
being introduced to module uploads, via the use of L<ExtUtils::MakeMaker>,
L<Module::Build> and L<Module::Install>.

=head1 ABSTRACT

A test module to validate a META.yml file.

=cut
61
62#----------------------------------------------------------------------------
63
64#############################################################################
65#Library Modules #
66#############################################################################
67
68
4
4
4
0
0
0
use Test::Builder;
69
4
4
4
0
0
0
use Test::YAML::Valid -Syck;
70
4
4
4
0
0
0
use Test::YAML::Meta::Version;
71
72#----------------------------------------------------------------------------
73
74my $Test = Test::Builder->new();
75
76sub import {
77
3
0
    my $self = shift;
78
3
0
    my $caller = caller;
79
4
4
4
0
0
0
    no strict 'refs';
80
3
3
0
0
    *{$caller.'::meta_yaml_ok'} = \&meta_yaml_ok;
81
3
3
0
0
    *{$caller.'::meta_spec_ok'} = \&meta_spec_ok;
82
83
3
0
    $Test->exported_to($caller);
84
3
0
    $Test->plan(@_);
85}
86
87#############################################################################
88#Interface Functions #
89#############################################################################
90
91 - 99
=head1 FUNCTIONS

=over

=item * meta_yaml_ok([$msg])

Basic META.yml wrapper around meta_spec_ok.

=cut
100
101sub meta_yaml_ok {
102
1
1
0
    $Test->plan( tests => 2 );
103
1
0
    meta_spec_ok(undef,undef,@_);
104}
105
106 - 113
=item * meta_spec_ok($file, $version [,$msg])

Validates the named file against the given specification version. Both $file 
and $version can be undefined.

=back

=cut
114
115sub meta_spec_ok {
116
7
1
0
        my ($file, $vers, $msg) = @_;
117
7
0
    $file ||= 'META.yml';
118
119
7
0
    unless($msg) {
120
6
0
        $msg = "$file meets the designated specification";
121
6
0
        $msg .= " ($vers)" if($vers);
122    }
123
124
7
0
    if(my $yaml = yaml_file_ok($file)) {
125
7
0
        my %hash;
126
7
0
        $hash{spec} = $vers if($vers);
127
7
0
        $hash{yaml} = $yaml;
128
129
7
0
        my $spec = Test::YAML::Meta::Version->new(%hash);
130
7
0
        if(my $result = $spec->parse()) {
131
1
0
            $Test->ok(0,$msg);
132
1
1
0
0
            $Test->diag(" ERR: $_") for($spec->errors);
133        } else {
134
6
0
            $Test->ok(1,$msg);
135        }
136    } else {
137
0
        print STDERR "\n#Failed\n";
138    }
139}
140
141q( Currently Listening To: KMDFM - "Hau Ruck" );
142