YAML.pm

filter: Statementstmt 98.0% 49 / 50 Branchbran 90.0% 9 / 10 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 97.3% 73 / 75 CC 8 SCAR 14.6
CC
8
Cov
97%
meta_spec_ok
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.3
« YAML/Version.pm ↑ Summary
1 package Test::CPAN::Meta::YAML;
2  
3 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 $VERSION = '0.25';
8  
9 #----------------------------------------------------------------------------
10  
11 =head1 NAME
12  
13 Test::CPAN::Meta::YAML - Validate a F<META.yml> 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<META.yml> 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<META.yml> 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<meta_spec_ok> is actually two
47 tests under the hood.
48  
49 =head1 DESCRIPTION
50  
51 This module was written to ensure that a F<META.yml> 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<ExtUtils::MakeMaker>,
54 L<Module::Build> and L<Module::Install>.
55  
56 See L<CPAN::Meta> for further details of the CPAN Meta Specification.
57  
58 =cut
59  
60 #----------------------------------------------------------------------------
61  
62 #############################################################################
63 #Library Modules #
64 #############################################################################
65  
66 8 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 8 ▶use Test::YAML::Valid -Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 8 ▶use Test::CPAN::Meta::YAML::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70 #----------------------------------------------------------------------------
71  
72 8 my $Test = Test::Builder->new();
73  
74 8 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
75 8 my $self = shift;
76 8 my $caller = caller;
77 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
78 8 *{$caller.'::meta_yaml_ok'} = \&meta_yaml_ok;
79 8 *{$caller.'::meta_spec_ok'} = \&meta_spec_ok;
80  
81 8 $Test->exported_to($caller);
82 8 $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<META.yml> wrapper around C<meta_spec_ok>.
96  
97 =cut
98  
99 1 ▶sub meta_yaml_ok {
Subroutine meta_yaml_ok: called CC=1 SCAR=0.0
Pod documented
100 1 $Test->plan( tests => 2 );
101 1 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 10 ▶sub meta_spec_ok {
Subroutine meta_spec_ok: called CC=8 SCAR=20.8
Pod documented
114 10 my ($file, $vers, $msg) = @_;
115 10 ▶ $file ||= 'META.yml';
Condition100%2/2
$file ||= "META.yml"
l!l
82
MC/DC100%1/1
$file ||= "META.yml"
$file
Truth table100%2/2
A
A= $file
Aresult
11
00
116  
117 10 ▶ unless($msg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($msg) 8 2 10
118 8 $msg = "$file meets the designated specification";
119 8 ▶ $msg .= " ($vers)" if($vers);
Branch: 1 branch
BranchTrueFalseTotal
if $vers 5 3 8
120 }
121  
122 10 ▶ if(my $yaml = yaml_file_ok($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $yaml = &yaml_file_ok($file)) { } 10 0 10
123 10 my %hash;
124 10 ▶ $hash{spec} = $vers if($vers);
Branch: 1 branch
BranchTrueFalseTotal
if $vers 6 4 10
125 10 $hash{data} = $yaml;
126  
127 10 my $spec = Test::CPAN::Meta::YAML::Version->new(%hash);
128 10 ▶ if(my $result = $spec->parse()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $spec->parse) { } 2 8 10
129 2 $Test->ok(0,$msg);
130 2 $Test->diag(" ERR: $_") for($spec->errors);
131 } else {
132 8 $Test->ok(1,$msg);
133 }
134  
135 10 return $yaml;
136  
137 } else {
138 0 print STDERR "\n#Failed\n";
139 }
140 }
141  
142 8 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__
« YAML/Version.pm ↑ Summary