Skip to content

Commit

Permalink
Apply changes for CPAN-Meta-YAML v0.014.
Browse files Browse the repository at this point in the history
Held to be applied to blead before perl-5.23.1.

One test failure was corrected: t/Porting/exec-bit.t.
set +x on this executable, as it is in the cpan distribution

Additional patch by Karen Etheridge.
  • Loading branch information
xdg authored and jkeenan committed Jun 1, 2015
1 parent 4e3e12f commit 23741be
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 72 deletions.
2 changes: 2 additions & 0 deletions MANIFEST
Expand Up @@ -326,6 +326,7 @@ cpan/CPAN-Meta/t/repository.t
cpan/CPAN-Meta/t/save-load.t
cpan/CPAN-Meta/t/validator.t
cpan/CPAN-Meta-YAML/lib/CPAN/Meta/YAML.pm CPAN-Meta-YAML files
cpan/CPAN-Meta-YAML/t/00-report-prereqs.dd
cpan/CPAN-Meta-YAML/t/01_api.t
cpan/CPAN-Meta-YAML/t/01_compile.t CPAN-Meta-YAML files
cpan/CPAN-Meta-YAML/t/10_read.t
Expand All @@ -337,6 +338,7 @@ cpan/CPAN-Meta-YAML/t/21_yamlpm_compat.t
cpan/CPAN-Meta-YAML/t/30_yaml_spec_tml.t
cpan/CPAN-Meta-YAML/t/31_local_tml.t
cpan/CPAN-Meta-YAML/t/32_world_tml.t
cpan/CPAN-Meta-YAML/t/86_fail.t
cpan/CPAN-Meta-YAML/t/data/ascii.yml
cpan/CPAN-Meta-YAML/t/data/latin1.yml
cpan/CPAN-Meta-YAML/t/data/multibyte.yml CPAN-Meta-YAML files
Expand Down
58 changes: 18 additions & 40 deletions cpan/CPAN-Meta-YAML/lib/CPAN/Meta/YAML.pm
@@ -1,17 +1,12 @@
use 5.008001; # sane UTF-8 support
use strict;
use warnings;
package CPAN::Meta::YAML;
$CPAN::Meta::YAML::VERSION = '0.012';
BEGIN {
$CPAN::Meta::YAML::AUTHORITY = 'cpan:ADAMK';
}
# git description: v1.60-1-g1c16a0a
; # original $VERSION removed by Doppelgaenger
package CPAN::Meta::YAML; # git description: v1.65-6-gfa117d1
# XXX-INGY is 5.8.1 too old/broken for utf8?
# XXX-XDG Lancaster consensus was that it was sufficient until
# proven otherwise

$CPAN::Meta::YAML::VERSION = '0.014';
; # original $VERSION removed by Doppelgaenger

#####################################################################
# The CPAN::Meta::YAML API.
Expand Down Expand Up @@ -153,7 +148,7 @@ my %QUOTE = map { $_ => 1 } qw{
my $re_capture_double_quoted = qr/\"([^\\"]*(?:\\.[^\\"]*)*)\"/;
my $re_capture_single_quoted = qr/\'([^\']*(?:\'\'[^\']*)*)\'/;
# unquoted re gets trailing space that needs to be stripped
my $re_capture_unquoted_key = qr/([^:]+(?::+\S[^:]*)*)(?=\s*\:(?:\s+|$))/;
my $re_capture_unquoted_key = qr/([^:]+(?::+\S(?:[^:]*|.*?(?=:)))*)(?=\s*\:(?:\s+|$))/;
my $re_trailing_comment = qr/(?:\s+\#.*)?/;
my $re_key_value_separator = qr/\s*:(?:\s+(?:\#.*)?|$)/;

Expand Down Expand Up @@ -300,10 +295,11 @@ Did you decode with lax ":utf8" instead of strict ":encoding(UTF-8)"?
}
}
};
if ( ref $@ eq 'SCALAR' ) {
$self->_error(${$@});
} elsif ( $@ ) {
$self->_error($@);
my $err = $@;
if ( ref $err eq 'SCALAR' ) {
$self->_error(${$err});
} elsif ( $err ) {
$self->_error($err);
}
return $self;
Expand Down Expand Up @@ -515,6 +511,10 @@ sub _load_hash {
die \"CPAN::Meta::YAML failed to classify line '$lines->[0]'";
}

if ( exists $hash->{$key} ) {
die \"CPAN::Meta::YAML found a duplicate key '$key' in line '$lines->[0]'";
}

# Do we have a value?
if ( length $lines->[0] ) {
# Yes
Expand Down Expand Up @@ -828,12 +828,10 @@ sub _can_flock {
#####################################################################
# Use Scalar::Util if possible, otherwise emulate it

use Scalar::Util ();
BEGIN {
local $@;
if ( eval { require Scalar::Util }
&& $Scalar::Util::VERSION
&& eval($Scalar::Util::VERSION) >= 1.18
) {
if ( eval { Scalar::Util->VERSION(1.18); } ) {
*refaddr = *Scalar::Util::refaddr;
}
else {
Expand All @@ -855,8 +853,7 @@ END_PERL
}
}



delete $CPAN::Meta::YAML::{refaddr};

1;

Expand All @@ -881,7 +878,7 @@ CPAN::Meta::YAML - Read and write a subset of YAML for CPAN Meta files
=head1 VERSION
version 0.012
version 0.014
=head1 SYNOPSIS
Expand Down Expand Up @@ -917,31 +914,12 @@ C<write> methods do B<not> support UTF-8 and should not be used.
This module is currently derived from L<YAML::Tiny> by Adam Kennedy. If
there are bugs in how it parses a particular META.yml file, please file
a bug report in the YAML::Tiny bugtracker:
L<https://rt.cpan.org/Public/Dist/Display.html?Name=YAML-Tiny>
L<https://github.com/Perl-Toolchain-Gang/YAML-Tiny/issues>
=head1 SEE ALSO
L<YAML::Tiny>, L<YAML>, L<YAML::XS>
=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
=head1 SUPPORT
=head2 Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker
at L<https://github.com/dagolden/CPAN-Meta-YAML/issues>.
You will be notified automatically of any progress on your issue.
=head2 Source Code
This is open source software. The code repository is available for
public review and contribution under the terms of the license.
L<https://github.com/dagolden/CPAN-Meta-YAML>
git clone https://github.com/dagolden/CPAN-Meta-YAML.git
=head1 AUTHORS
=over 4
Expand Down
66 changes: 66 additions & 0 deletions cpan/CPAN-Meta-YAML/t/00-report-prereqs.dd
@@ -0,0 +1,66 @@
do { my $x = {
'configure' => {
'requires' => {
'ExtUtils::MakeMaker' => '6.17',
'perl' => '5.008001'
}
},
'develop' => {
'requires' => {
'Dist::Zilla' => '5',
'Dist::Zilla::Plugin::AppendExternalData' => '0',
'Dist::Zilla::Plugin::Doppelgaenger' => '0.007',
'Dist::Zilla::Plugin::Encoding' => '0',
'Dist::Zilla::Plugin::Git::NextVersion' => '0',
'Dist::Zilla::Plugin::MakeMaker::Highlander' => '0.003',
'Dist::Zilla::Plugin::MetaResources' => '0',
'Dist::Zilla::Plugin::PkgVersion' => '0',
'Dist::Zilla::Plugin::PodWeaver' => '0',
'Dist::Zilla::Plugin::PruneFiles' => '0',
'Dist::Zilla::Plugin::RemovePrereqs' => '0',
'Dist::Zilla::PluginBundle::DAGOLDEN' => '0.072',
'File::Spec' => '0',
'File::Temp' => '0',
'IO::Handle' => '0',
'IPC::Open3' => '0',
'Test::CPAN::Meta' => '0',
'Test::More' => '0',
'Test::Pod' => '1.41',
'Test::Version' => '1'
}
},
'runtime' => {
'requires' => {
'B' => '0',
'Carp' => '0',
'Exporter' => '0',
'Fcntl' => '0',
'Scalar::Util' => '0',
'perl' => '5.008001',
'strict' => '0',
'warnings' => '0'
}
},
'test' => {
'recommends' => {
'CPAN::Meta' => '2.120900'
},
'requires' => {
'ExtUtils::MakeMaker' => '0',
'File::Basename' => '0',
'File::Find' => '0',
'File::Spec' => '0',
'File::Spec::Functions' => '0',
'File::Temp' => '0.18',
'IO::Dir' => '0',
'JSON::PP' => '0',
'Test::More' => '0.99',
'lib' => '0',
'perl' => '5.008001',
'utf8' => '0',
'vars' => '0'
}
}
};
$x;
}
9 changes: 1 addition & 8 deletions cpan/CPAN-Meta-YAML/t/10_read.t
Expand Up @@ -101,12 +101,5 @@ subtest "bad read arguments" => sub {
};

done_testing;
#
# This file is part of CPAN-Meta-YAML
#
# This software is copyright (c) 2010 by Adam Kennedy.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
# COPYRIGHT
# vim: ts=4 sts=4 sw=4 et:
9 changes: 5 additions & 4 deletions cpan/CPAN-Meta-YAML/t/12_write.t
Expand Up @@ -8,7 +8,8 @@ use TestUtils;

use CPAN::Meta::YAML;
use File::Basename qw/basename/;
use File::Temp qw/tempfile/;
use File::Spec::Functions 'catfile';
use File::Temp 0.18;

#--------------------------------------------------------------------------#
# Error conditions
Expand Down Expand Up @@ -44,9 +45,9 @@ for my $c ( @cases ) {
@warnings = ();

# get a tempfile name to write to
my ($fh, $tempfile) = tempfile("YAML-Tiny-test-XXXXXXXX", TMPDIR => 1 );
my $short_tempfile = basename($tempfile);
close $fh; # avoid locks on windows
my $tempdir = File::Temp->newdir("YTXXXXXX", TMPDIR => 1 );
my $short_tempfile = 'output';
my $tempfile = catfile($tempdir, $short_tempfile);

# CPAN::Meta::YAML->write
ok( CPAN::Meta::YAML->new($c)->write($tempfile),
Expand Down
7 changes: 4 additions & 3 deletions cpan/CPAN-Meta-YAML/t/21_yamlpm_compat.t
Expand Up @@ -3,7 +3,8 @@ use warnings;
use lib 't/lib/';
use Test::More 0.99;
use TestBridge;
use File::Temp qw(tempfile);
use File::Spec::Functions 'catfile';
use File::Temp 0.18;

#--------------------------------------------------------------------------#
# This file test that the YAML.pm compatible Dump/Load/DumpFile/LoadFile
Expand Down Expand Up @@ -31,8 +32,8 @@ use CPAN::Meta::YAML;
my $arrayref = [ 1 .. 5 ];
my $hashref = { alpha => 'beta', gamma => 'delta' };

my ($fh, $filename) = tempfile;
close $fh; # or LOCK_SH will hang
my $tempdir = File::Temp->newdir("YTXXXXXX", TMPDIR => 1 );
my $filename = catfile($tempdir, 'compat');

my $rv = CPAN::Meta::YAML::DumpFile(
$filename, $scalar, $arrayref, $hashref);
Expand Down
8 changes: 5 additions & 3 deletions cpan/CPAN-Meta-YAML/t/30_yaml_spec_tml.t
@@ -1,20 +1,22 @@
# Run the appropriate tests from https://github.com/ingydotnet/yaml-spec-tml
use strict;
use warnings;
use lib 't/lib/';
use lib 't/lib';
use Test::More 0.99;
use TestBridge;
use TestUtils;

my $JSON = json_class()
or Test::More::plan skip_all => "no JSON or JSON::PP";
or Test::More::plan skip_all => 'no JSON backends available!?';

diag 'using JSON backend: ' . $JSON;

# Each spec test will need a different bridge and arguments:
my @spec_tests = (
['t/tml-spec/basic-data.tml', 'test_yaml_json', $JSON],
# This test is currently failing massively. We use LAST to only run what is
# covered so far.
['t/tml-spec/unicode.tml', 'test_code_point'],
['t/tml-spec/unicode.tml', 'test_code_point'], # uses JSON::PP
);

for my $test (@spec_tests) {
Expand Down
30 changes: 30 additions & 0 deletions cpan/CPAN-Meta-YAML/t/86_fail.t
@@ -0,0 +1,30 @@
=pod
This is an example of a serious design flaw in CPAN::Meta::YAML.
It is generally a bad idea to fake out a parsing process. In this case,
CPAN::Meta::YAML strips off all lines that look like comments.
It should be easy to find dozens of bugs by looking at the assumptions the code
makes and then finding a counter case like this.
That's why I'm working on Tiny::YAML and YAML::Pegex, which are driven by a
grammar.
=cut

use Test::More tests => 1;
use CPAN::Meta::YAML;

TODO: {
local $TODO = "Failing tests for things CPAN::Meta::YAML does wrong";

my $yaml = <<'...';
- |
# Perl sub:
sub foo {}
...
is Load($yaml)->[0],
"# Perl sub:\nsub foo{}\n",
"Comments in literal scalars";
}
8 changes: 4 additions & 4 deletions cpan/CPAN-Meta-YAML/t/README.md
@@ -1,6 +1,6 @@
# Guide to CPAN::Meta::YAML testing
# Guide to YAML::Tiny testing

CPAN::Meta::YAML tests use several components:
YAML::Tiny tests use several components:

* .t files
* Test libraries in t/lib
Expand Down Expand Up @@ -120,10 +120,10 @@ functions used to process test blocks.
TestML data files are organized into three directories:

* t/tml-spec — these test files are provided by the YAML spec maintainers and
should not be modified except to skip testing features that CPAN::Meta::YAML does not
should not be modified except to skip testing features that YAML::Tiny does not
support

* t/tml-local — these test files are CPAN::Meta::YAML's own unit tests; generally new
* t/tml-local — these test files are YAML::Tiny's own unit tests; generally new
test cases for coverage or correctness should be added here; these are
broken into subdirectories, described later

Expand Down
5 changes: 3 additions & 2 deletions cpan/CPAN-Meta-YAML/t/lib/TestBridge.pm
Expand Up @@ -38,6 +38,7 @@ my %ERROR = (
E_FEATURE => qr{\QCPAN::Meta::YAML does not support a feature},
E_PLAIN => qr{\QCPAN::Meta::YAML found illegal characters in plain scalar},
E_CLASSIFY => qr{\QCPAN::Meta::YAML failed to classify the line},
E_DUPKEY => qr{\QCPAN::Meta::YAML found a duplicate key},
);

# use XXX -with => 'YAML::XS';
Expand Down Expand Up @@ -194,7 +195,7 @@ sub test_perl_to_yaml {
#--------------------------------------------------------------------------#
# test_dump_error
#
# two blocks: perl, error
# two blocks: perl, error
#
# Tests that perl references result in an error when dumped
#
Expand Down Expand Up @@ -225,7 +226,7 @@ sub test_dump_error {
#--------------------------------------------------------------------------#
# test_load_error
#
# two blocks: yaml, error
# two blocks: yaml, error
#
# Tests that a YAML string results in an error when loaded
#
Expand Down
7 changes: 2 additions & 5 deletions cpan/CPAN-Meta-YAML/t/lib/TestUtils.pm
Expand Up @@ -26,12 +26,9 @@ sub find_tml_files {
return @files;
}

# Prefer JSON to JSON::PP; skip if we don't have at least one
sub json_class {
for (qw/JSON JSON::PP/) {
return $_ if eval "require $_; 1";
}
return;
return eval { require JSON::MaybeXS; JSON::MaybeXS->VERSION('1.001000'); $JSON::MaybeXS::JSON_Class }
|| do { require JSON::PP; 'JSON::PP' };
}

sub test_data_directory {
Expand Down
6 changes: 6 additions & 0 deletions cpan/CPAN-Meta-YAML/t/tml-local/load-error/document.tml
Expand Up @@ -3,3 +3,9 @@
\--- foo
a: 1
--- error: E_CLASSIFY

=== mapping with double key
--- yaml
foo: 1
foo: 2
--- error: E_DUPKEY

0 comments on commit 23741be

Please sign in to comment.