diff options
author | Steffen Mueller <smueller@cpan.org> | 2009-03-03 21:18:30 +0100 |
---|---|---|
committer | Steffen Mueller <smueller@cpan.org> | 2009-03-03 21:35:30 +0100 |
commit | c59d1bfa1963d67385282b3086f8882458918630 (patch) | |
tree | 77dd4bd7b316dc3ac5af10ade4ef0d3739af664c /lib/Parse | |
parent | 32a618150c45210060f67f2c088de206ddb5fa07 (diff) | |
download | perl-c59d1bfa1963d67385282b3086f8882458918630.tar.gz |
Update Parse::CPAN::Meta to 0.04_01
Diffstat (limited to 'lib/Parse')
-rw-r--r-- | lib/Parse/CPAN/Meta.pm | 39 | ||||
-rw-r--r-- | lib/Parse/CPAN/Meta/Changes | 3 | ||||
-rw-r--r-- | lib/Parse/CPAN/Meta/t/11_meta_yml.t | 2 | ||||
-rw-r--r-- | lib/Parse/CPAN/Meta/t/15_multibyte.t | 10 | ||||
-rw-r--r-- | lib/Parse/CPAN/Meta/t/data/utf_16_le_bom.yml | bin | 0 -> 22 bytes |
5 files changed, 46 insertions, 8 deletions
diff --git a/lib/Parse/CPAN/Meta.pm b/lib/Parse/CPAN/Meta.pm index 8d5e29b5ef..6a80681794 100644 --- a/lib/Parse/CPAN/Meta.pm +++ b/lib/Parse/CPAN/Meta.pm @@ -5,7 +5,7 @@ use Carp 'croak'; BEGIN { require 5.004; require Exporter; - $Parse::CPAN::Meta::VERSION = '0.04'; + $Parse::CPAN::Meta::VERSION = '0.04_01'; @Parse::CPAN::Meta::ISA = qw{ Exporter }; @Parse::CPAN::Meta::EXPORT_OK = qw{ Load LoadFile }; } @@ -25,7 +25,19 @@ my %UNESCAPES = ( ); - +my %BOM = ( + "\357\273\277" => 'UTF-8', + "\376\377" => 'UTF-16BE', + "\377\376" => 'UTF-16LE', + "\0\0\376\377" => 'UTF-32BE', + "\377\376\0\0" => 'UTF-32LE' +); + +sub BOM_MIN_LENGTH () { 2 } +sub BOM_MAX_LENGTH () { 4 } +sub HAVE_UTF8 () { $] >= 5.007003 } + +BEGIN { require utf8 if HAVE_UTF8 } ##################################################################### @@ -53,17 +65,32 @@ sub LoadFile ($) { # Parse a document from a string. # Doing checks on $_[0] prevents us having to do a string copy. sub Load ($) { - unless ( defined $_[0] ) { + + my $str = $_[0]; + + # Handle special cases + foreach my $length ( BOM_MIN_LENGTH .. BOM_MAX_LENGTH ) { + if ( my $enc = $BOM{substr($str, 0, $length)} ) { + croak("Stream has a non UTF-8 BOM") unless $enc eq 'UTF-8'; + substr($str, 0, $length) = ''; # strip UTF-8 bom if found, we'll just ignore it + } + } + + if ( HAVE_UTF8 ) { + utf8::decode($str); # try to decode as utf8 + } + + unless ( defined $str ) { croak("Did not provide a string to Load"); } - return () unless length $_[0]; - unless ( $_[0] =~ /[\012\015]+$/ ) { + return() unless length $str; + unless ( $str =~ /[\012\015]+$/ ) { croak("Stream does not end with newline character"); } # Split the file into lines my @lines = grep { ! /^\s*(?:\#.*)?$/ } - split /(?:\015{1,2}\012|\015|\012)/, shift; + split /(?:\015{1,2}\012|\015|\012)/, $str; # A nibbling parser my @documents = (); diff --git a/lib/Parse/CPAN/Meta/Changes b/lib/Parse/CPAN/Meta/Changes index 9bd147c7f8..5a166519a1 100644 --- a/lib/Parse/CPAN/Meta/Changes +++ b/lib/Parse/CPAN/Meta/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension Parse-CPAN-Meta +0.04_01 Tue 3 Mar 2009 + - Merge Unicode / BOM fixes from YAML::Tiny + 0.04 Wed 7 Jan 2009 - Matching changes in YAML::Tiny 1.36 - Fixing missing feature reported by H.Merijn Brand diff --git a/lib/Parse/CPAN/Meta/t/11_meta_yml.t b/lib/Parse/CPAN/Meta/t/11_meta_yml.t index 9b789f04c8..c5a493467d 100644 --- a/lib/Parse/CPAN/Meta/t/11_meta_yml.t +++ b/lib/Parse/CPAN/Meta/t/11_meta_yml.t @@ -95,7 +95,7 @@ generated_by: ExtUtils::MakeMaker version 6.30 END_YAML [ { name => 'ITS-SIN-FIDS-Content-XML', - version => 0.01, + version => "0.01", version_from => 'lib/ITS/SIN/FIDS/Content/XML.pm', installdirs => 'site', requires => { diff --git a/lib/Parse/CPAN/Meta/t/15_multibyte.t b/lib/Parse/CPAN/Meta/t/15_multibyte.t index c5e0d67147..a67c0f989a 100644 --- a/lib/Parse/CPAN/Meta/t/15_multibyte.t +++ b/lib/Parse/CPAN/Meta/t/15_multibyte.t @@ -20,7 +20,7 @@ BEGIN { use File::Spec::Functions ':ALL'; use Parse::CPAN::Meta::Test; -use Test::More tests(0, 1, 3); +use Test::More tests(0, 1, 4); @@ -46,3 +46,11 @@ SKIP: { 'XSLoader' => 0, }, 'build_requires ok' ); } + +SKIP: { + skip "no utf8 support", 1 unless Parse::CPAN::Meta::HAVE_UTF8(); + ok( utf8::is_utf8($yaml[0]->{author}), "utf8 decoded" ); +} + +exit(0); + diff --git a/lib/Parse/CPAN/Meta/t/data/utf_16_le_bom.yml b/lib/Parse/CPAN/Meta/t/data/utf_16_le_bom.yml Binary files differnew file mode 100644 index 0000000000..b9230ebb5a --- /dev/null +++ b/lib/Parse/CPAN/Meta/t/data/utf_16_le_bom.yml |