At 6AM on 20/03/08 you (Adam Kennedy via RT) wrote:
Show quoted text>
> YAML::Tiny now behaves identically to YAML.pm in scalar context.
Thank you for fixing this so quickly; unfortunately, you missed
LoadFile. Patch attached.
Ben
diff -Nur YAML-Tiny-1.26/MANIFEST YAML-Tiny/MANIFEST
--- YAML-Tiny-1.26/MANIFEST Thu Mar 20 10:20:06 2008
+++ YAML-Tiny/MANIFEST Thu Mar 20 17:01:15 2008
@@ -3,6 +3,7 @@
LICENSE
Makefile.PL
MANIFEST This list of files
+META.yml Module meta-data (added by MakeMaker)
README
t/01_compile.t
t/02_basic.t
@@ -20,9 +21,10 @@
t/99_pmv.t
t/data/HTML-WebDAO.yml
t/data/multibyte.yml
+t/data/one.yml
t/data/sample.yml
t/data/Template-Provider-Unicode-Japanese.yml
t/data/toolbar.yml
+t/data/two.yml
t/data/vanilla.yml
t/lib/Test.pm
-META.yml Module meta-data (added by MakeMaker)
diff -Nur YAML-Tiny-1.26/lib/YAML/Tiny.pm YAML-Tiny/lib/YAML/Tiny.pm
--- YAML-Tiny-1.26/lib/YAML/Tiny.pm Thu Mar 20 10:19:47 2008
+++ YAML-Tiny/lib/YAML/Tiny.pm Thu Mar 20 17:02:50 2008
@@ -491,7 +491,12 @@
sub LoadFile {
my $self = YAML::Tiny->read($_[0])
or Carp::croak("Failed to load YAML document from '" . ($_[0] || '') . "'");
- return @$self;
+ if (wantarray) {
+ return @$self;
+ } else {
+ # To match YAML.pm, return the LAST document
+ return $self->[-1];
+ }
}
diff -Nur YAML-Tiny-1.26/t/04_scalar.t YAML-Tiny/t/04_scalar.t
--- YAML-Tiny-1.26/t/04_scalar.t Thu Mar 20 10:19:47 2008
+++ YAML-Tiny/t/04_scalar.t Thu Mar 20 16:56:15 2008
@@ -11,7 +11,7 @@
use t::lib::Test;
use Test::More;
if ( t::lib::Test->have_yamlpm ) {
- plan( tests => 8 );
+ plan( tests => 12 );
} else {
plan( skip_all => 'Requites YAML.pm' );
exit(0);
@@ -19,6 +19,7 @@
use YAML ();
use YAML::Tiny ();
+use File::Spec::Functions qw/catfile/;
@@ -39,6 +40,9 @@
- bar
END_YAML
+my $one_file = catfile( 't', 'data', 'one.yml' );
+my $two_file = catfile( 't', 'data', 'two.yml' );
+
@@ -74,3 +78,22 @@
is_deeply( $two_scalar_pm, [ 'bar' ], 'two: Parsed correctly' );
is_deeply( $two_scalar_pm, $two_scalar_tiny, 'two: Scalar context matches' );
+
+
+
+
+
+######################################################################
+# Match LoadFile Behaviour
+
+my $one_file_pm = YAML::LoadFile( $one_file );
+my $two_file_pm = YAML::LoadFile( $two_file );
+my $one_file_tiny = YAML::Tiny::LoadFile( $one_file );
+my $two_file_tiny = YAML::Tiny::LoadFile( $two_file );
+
+is_deeply( $one_file_pm, [ 'foo' ], 'one: Parsed correctly' );
+is_deeply( $one_file_pm, $one_file_tiny, 'one: scalar LoadFile matches' );
+
+is_deeply( $two_file_pm, [ 'bar' ], 'two: Parsed correctly' );
+is_deeply( $two_file_pm, $two_file_tiny, 'two: scalar LoadFile matches' );
+
diff -Nur YAML-Tiny-1.26/t/data/one.yml YAML-Tiny/t/data/one.yml
--- YAML-Tiny-1.26/t/data/one.yml Thu Jan 1 01:00:00 1970
+++ YAML-Tiny/t/data/one.yml Thu Mar 20 16:56:39 2008
@@ -0,0 +1,2 @@
+---
+- foo
diff -Nur YAML-Tiny-1.26/t/data/two.yml YAML-Tiny/t/data/two.yml
--- YAML-Tiny-1.26/t/data/two.yml Thu Jan 1 01:00:00 1970
+++ YAML-Tiny/t/data/two.yml Thu Mar 20 16:56:50 2008
@@ -0,0 +1,4 @@
+---
+- foo
+---
+- bar