summaryrefslogtreecommitdiff
path: root/cpan
diff options
context:
space:
mode:
authorSteve Hay <steve.m.hay@googlemail.com>2014-03-05 08:47:42 +0000
committerSteve Hay <steve.m.hay@googlemail.com>2014-03-05 08:47:42 +0000
commita2fd2fa0b0f25ba4d34f3a1954d85e6cca31632f (patch)
treec549d2d699ed1d976690de1311576b4f4b11c682 /cpan
parent85b1cb07bd15b67e4656e4ba7f54fa03f273b090 (diff)
downloadperl-a2fd2fa0b0f25ba4d34f3a1954d85e6cca31632f.tar.gz
Upgrade Parse-CPAN-Meta from version 1.4413 to 1.4414
Diffstat (limited to 'cpan')
-rw-r--r--cpan/Parse-CPAN-Meta/lib/Parse/CPAN/Meta.pm36
-rw-r--r--cpan/Parse-CPAN-Meta/t/02_api.t28
-rw-r--r--cpan/Parse-CPAN-Meta/t/data/bareyaml.meta21
-rw-r--r--cpan/Parse-CPAN-Meta/t/data/json.meta30
-rw-r--r--cpan/Parse-CPAN-Meta/t/data/yaml.meta22
5 files changed, 130 insertions, 7 deletions
diff --git a/cpan/Parse-CPAN-Meta/lib/Parse/CPAN/Meta.pm b/cpan/Parse-CPAN-Meta/lib/Parse/CPAN/Meta.pm
index 4d773e2f1a..7888d1c3cb 100644
--- a/cpan/Parse-CPAN-Meta/lib/Parse/CPAN/Meta.pm
+++ b/cpan/Parse-CPAN-Meta/lib/Parse/CPAN/Meta.pm
@@ -2,7 +2,7 @@ use 5.008001;
use strict;
package Parse::CPAN::Meta;
# ABSTRACT: Parse META.yml and META.json CPAN metadata files
-our $VERSION = '1.4413'; # VERSION
+our $VERSION = '1.4414'; # VERSION
use Exporter;
use Carp 'croak';
@@ -13,15 +13,30 @@ our @EXPORT_OK = qw/Load LoadFile/;
sub load_file {
my ($class, $filename) = @_;
+ my $meta = _slurp($filename);
+
if ($filename =~ /\.ya?ml$/) {
- return $class->load_yaml_string(_slurp($filename));
+ return $class->load_yaml_string($meta);
}
-
- if ($filename =~ /\.json$/) {
- return $class->load_json_string(_slurp($filename));
+ elsif ($filename =~ /\.json$/) {
+ return $class->load_json_string($meta);
+ }
+ else {
+ $class->load_string($meta); # try to detect yaml/json
}
+}
- croak("file type cannot be determined by filename");
+sub load_string {
+ my ($class, $string) = @_;
+ if ( $string =~ /^---/ ) { # looks like YAML
+ return $class->load_yaml_string($string);
+ }
+ elsif ( $string =~ /^\s*\{/ ) { # looks like JSON
+ return $class->load_json_string($string);
+ }
+ else { # maybe doc-marker-free YAML
+ return $class->load_yaml_string($string);
+ }
}
sub load_yaml_string {
@@ -121,7 +136,7 @@ Parse::CPAN::Meta - Parse META.yml and META.json CPAN metadata files
=head1 VERSION
-version 1.4413
+version 1.4414
=head1 SYNOPSIS
@@ -201,6 +216,13 @@ This method deserializes the given string of JSON and the result.
If the source was UTF-8 encoded, the string must be decoded before calling
C<load_json_string>.
+=head2 load_string
+
+ my $metadata_structure = Parse::CPAN::Meta->load_string($some_string);
+
+If you don't know whether a string contains YAML or JSON data, this method
+will use some heuristics and guess. If it can't tell, it assumes YAML.
+
=head2 yaml_backend
my $backend = Parse::CPAN::Meta->yaml_backend;
diff --git a/cpan/Parse-CPAN-Meta/t/02_api.t b/cpan/Parse-CPAN-Meta/t/02_api.t
index 517f7fe120..72bfccf67f 100644
--- a/cpan/Parse-CPAN-Meta/t/02_api.t
+++ b/cpan/Parse-CPAN-Meta/t/02_api.t
@@ -51,6 +51,9 @@ my $want = {
my $meta_json = catfile( test_data_directory(), 'META-VR.json' );
my $meta_yaml = catfile( test_data_directory(), 'META-VR.yml' );
+my $yaml_meta = catfile( test_data_directory(), 'yaml.meta' );
+my $json_meta = catfile( test_data_directory(), 'json.meta' );
+my $bare_yaml_meta = catfile( test_data_directory(), 'bareyaml.meta' );
### YAML tests
{
@@ -64,6 +67,22 @@ my $meta_yaml = catfile( test_data_directory(), 'META-VR.yml' );
{
local $ENV{PERL_YAML_BACKEND}; # ensure we get CPAN::META::YAML
+ is(Parse::CPAN::Meta->yaml_backend(), 'CPAN::Meta::YAML', 'yaml_backend()');
+ my $from_yaml = Parse::CPAN::Meta->load_file( $yaml_meta );
+ is_deeply($from_yaml, $want, "load from YAML .meta file results in expected data");
+}
+
+{
+ local $ENV{PERL_YAML_BACKEND}; # ensure we get CPAN::META::YAML
+
+ is(Parse::CPAN::Meta->yaml_backend(), 'CPAN::Meta::YAML', 'yaml_backend()');
+ my $from_yaml = Parse::CPAN::Meta->load_file( $bare_yaml_meta );
+ is_deeply($from_yaml, $want, "load from bare YAML .meta file results in expected data");
+}
+
+{
+ local $ENV{PERL_YAML_BACKEND}; # ensure we get CPAN::META::YAML
+
my $yaml = load_ok( 'META-VR.yml', $meta_yaml, 100);
my $from_yaml = Parse::CPAN::Meta->load_yaml_string( $yaml );
is_deeply($from_yaml, $want, "load from YAML str results in expected data");
@@ -102,6 +121,15 @@ SKIP: {
# JSON tests with JSON::PP
local $ENV{PERL_JSON_BACKEND}; # ensure we get JSON::PP
+ is(Parse::CPAN::Meta->json_backend(), 'JSON::PP', 'json_backend()');
+ my $from_json = Parse::CPAN::Meta->load_file( $json_meta );
+ is_deeply($from_json, $want, "load from JSON .meta file results in expected data");
+}
+
+{
+ # JSON tests with JSON::PP
+ local $ENV{PERL_JSON_BACKEND}; # ensure we get JSON::PP
+
my $json = load_ok( 'META-VR.json', $meta_json, 100);
my $from_json = Parse::CPAN::Meta->load_json_string( $json );
is_deeply($from_json, $want, "load from JSON str results in expected data");
diff --git a/cpan/Parse-CPAN-Meta/t/data/bareyaml.meta b/cpan/Parse-CPAN-Meta/t/data/bareyaml.meta
new file mode 100644
index 0000000000..7e4f430b9c
--- /dev/null
+++ b/cpan/Parse-CPAN-Meta/t/data/bareyaml.meta
@@ -0,0 +1,21 @@
+abstract: 'a set of version requirements for a CPAN dist'
+author:
+ - 'Ricardo Signes <rjbs@cpan.org>'
+build_requires:
+ Test::More: 0.88
+configure_requires:
+ ExtUtils::MakeMaker: 6.31
+generated_by: 'Dist::Zilla version 2.100991'
+license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
+name: Version-Requirements
+recommends: {}
+requires:
+ Carp: 0
+ Scalar::Util: 0
+ version: 0.77
+resources:
+ repository: git://git.codesimply.com/Version-Requirements.git
+version: 0.101010
diff --git a/cpan/Parse-CPAN-Meta/t/data/json.meta b/cpan/Parse-CPAN-Meta/t/data/json.meta
new file mode 100644
index 0000000000..fbe9eca82f
--- /dev/null
+++ b/cpan/Parse-CPAN-Meta/t/data/json.meta
@@ -0,0 +1,30 @@
+{
+ "abstract" : "a set of version requirements for a CPAN dist",
+ "author" : [
+ "Ricardo Signes <rjbs@cpan.org>"
+ ],
+ "build_requires" : {
+ "Test::More" : "0.88"
+ },
+ "configure_requires" : {
+ "ExtUtils::MakeMaker" : "6.31"
+ },
+ "generated_by" : "Dist::Zilla version 2.100991",
+ "license" : "perl",
+ "meta-spec" : {
+ "url" : "http://module-build.sourceforge.net/META-spec-v1.4.html",
+ "version" : 1.4
+ },
+ "name" : "Version-Requirements",
+ "recommends" : {},
+ "requires" : {
+ "Carp" : "0",
+ "Scalar::Util" : "0",
+ "version" : "0.77"
+ },
+ "resources" : {
+ "repository" : "git://git.codesimply.com/Version-Requirements.git"
+ },
+ "version" : "0.101010"
+}
+
diff --git a/cpan/Parse-CPAN-Meta/t/data/yaml.meta b/cpan/Parse-CPAN-Meta/t/data/yaml.meta
new file mode 100644
index 0000000000..56d50ddc3d
--- /dev/null
+++ b/cpan/Parse-CPAN-Meta/t/data/yaml.meta
@@ -0,0 +1,22 @@
+---
+abstract: 'a set of version requirements for a CPAN dist'
+author:
+ - 'Ricardo Signes <rjbs@cpan.org>'
+build_requires:
+ Test::More: 0.88
+configure_requires:
+ ExtUtils::MakeMaker: 6.31
+generated_by: 'Dist::Zilla version 2.100991'
+license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
+name: Version-Requirements
+recommends: {}
+requires:
+ Carp: 0
+ Scalar::Util: 0
+ version: 0.77
+resources:
+ repository: git://git.codesimply.com/Version-Requirements.git
+version: 0.101010