File Coverage

blib/lib/Test/CPAN/Meta/YAML.pm
Criterion Covered Total %
statement 46 47 97.8
branch 9 10 90.0
condition 2 2 100.0
subroutine 10 10 100.0
pod 2 2 100.0
total 69 71 97.1


line stmt bran cond sub pod time code
1             package Test::CPAN::Meta::YAML;
2              
3 8     8   77591 use warnings;
  8         10  
  8         202  
4 8     8   24 use strict;
  8         9  
  8         177  
5              
6 8     8   26 use vars qw($VERSION);
  8         9  
  8         481  
7             $VERSION = '0.25';
8              
9             #----------------------------------------------------------------------------
10              
11             =head1 NAME
12              
13             Test::CPAN::Meta::YAML - Validate a F file within a CPAN distribution.
14              
15             =head1 SYNOPSIS
16              
17             There are two forms this module can be used.
18              
19             The first is a standalone test of your distribution's F file:
20              
21             use Test::More;
22             eval "use Test::CPAN::Meta::YAML";
23             plan skip_all => "Test::CPAN::Meta::YAML required for testing META.yml" if $@;
24             meta_yaml_ok();
25              
26             Note that you may provide an optional label/comment/message/etc to the
27             function, or one will be created automatically.
28              
29             The second form allows you to test other F files, or specify a specific
30             version you wish to test against:
31              
32             use Test::More tests => 6;
33             use Test::CPAN::Meta::YAML;
34              
35             # specify a file and specification version
36             meta_spec_ok('META.yml','1.3',$msg);
37              
38             # specify the specification version to validate the local META.yml
39             meta_spec_ok(undef,'1.3',$msg);
40              
41             # specify a file, where the specification version is deduced
42             # from the file itself
43             meta_spec_ok('META.yml',undef,$msg);
44              
45             Note that this form requires you to specify the number of tests you will be
46             running in your test script. Also note that each C is actually two
47             tests under the hood.
48              
49             =head1 DESCRIPTION
50              
51             This module was written to ensure that a F file, provided with a
52             standard distribution uploaded to CPAN, meets the specifications that slowly
53             being introduced to module uploads, via the use of L,
54             L and L.
55              
56             See L for further details of the CPAN Meta Specification.
57              
58             =cut
59              
60             #----------------------------------------------------------------------------
61              
62             #############################################################################
63             #Library Modules #
64             #############################################################################
65              
66 8     8   562 use Test::Builder;
  8         7285  
  8         151  
67 8     8   2877 use Test::YAML::Valid -Syck;
  8         6107  
  8         41  
68 8     8   17815 use Test::CPAN::Meta::YAML::Version;
  8         21  
  8         441  
69              
70             #----------------------------------------------------------------------------
71              
72             my $Test = Test::Builder->new();
73              
74             sub import {
75 8     8   83 my $self = shift;
76 8         12 my $caller = caller;
77 8     8   43 no strict 'refs';
  8         7  
  8         1709  
78 8         11 *{$caller.'::meta_yaml_ok'} = \&meta_yaml_ok;
  8         29  
79 8         11 *{$caller.'::meta_spec_ok'} = \&meta_spec_ok;
  8         18  
80              
81 8         24 $Test->exported_to($caller);
82 8         60 $Test->plan(@_);
83             }
84              
85             #############################################################################
86             #Interface Functions #
87             #############################################################################
88              
89             =head1 FUNCTIONS
90              
91             =over
92              
93             =item * meta_yaml_ok([$msg])
94              
95             Basic F wrapper around C.
96              
97             =cut
98              
99             sub meta_yaml_ok {
100 1     1 1 14 $Test->plan( tests => 2 );
101 1         112 return meta_spec_ok(undef,undef,@_);
102             }
103              
104             =item * meta_spec_ok($file, $version [,$msg])
105              
106             Validates the named file against the given specification version. Both C<$file>
107             and C<$version> can be undefined.
108              
109             =back
110              
111             =cut
112              
113             sub meta_spec_ok {
114 10     10 1 2578 my ($file, $vers, $msg) = @_;
115 10   100     26 $file ||= 'META.yml';
116              
117 10 100       17 unless($msg) {
118 8         12 $msg = "$file meets the designated specification";
119 8 100       29 $msg .= " ($vers)" if($vers);
120             }
121              
122 10 50       25 if(my $yaml = yaml_file_ok($file)) {
123 10         4538 my %hash;
124 10 100       26 $hash{spec} = $vers if($vers);
125 10         11 $hash{data} = $yaml;
126              
127 10         51 my $spec = Test::CPAN::Meta::YAML::Version->new(%hash);
128 10 100       23 if(my $result = $spec->parse()) {
129 2         5 $Test->ok(0,$msg);
130 2         603 $Test->diag(" ERR: $_") for($spec->errors);
131             } else {
132 8         20 $Test->ok(1,$msg);
133             }
134              
135 10         1657 return $yaml;
136              
137             } else {
138 0           print STDERR "\n#Failed\n";
139             }
140             }
141              
142             q( This release is sponsored by Made In Love: Hand made gifts for your loved ones, friends or even a treat for your own home - http://madeinlove.co.uk );
143              
144             __END__