[libyaml-libyaml-perl] 06/11: use Scalar::Util::openhandle for checking filehandles
gregor herrmann
gregoa at debian.org
Fri Mar 18 18:03:31 UTC 2016
This is an automated email from the git hooks/post-receive script.
gregoa pushed a commit to branch gregoa/use-system-yaml
in repository libyaml-libyaml-perl.
commit ca00324a0f6f6b798e95acec52c4513881262e63
Author: Tina Müller <cpan2 at tinita.de>
Date: Sun Feb 21 20:57:55 2016 +0100
use Scalar::Util::openhandle for checking filehandles
---
lib/YAML/XS.pm | 5 +++--
test/path-class.t | 27 +++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/lib/YAML/XS.pm b/lib/YAML/XS.pm
index a348d39..6d2c507 100644
--- a/lib/YAML/XS.pm
+++ b/lib/YAML/XS.pm
@@ -17,11 +17,12 @@ use base 'Exporter';
$YAML::XS::QuoteNumericStrings = 1;
use YAML::XS::LibYAML qw(Load Dump);
+use Scalar::Util qw/ openhandle /;
sub DumpFile {
my $OUT;
my $filename = shift;
- if (defined fileno($filename)) {
+ if (openhandle $filename) {
$OUT = $filename;
}
else {
@@ -39,7 +40,7 @@ sub DumpFile {
sub LoadFile {
my $IN;
my $filename = shift;
- if (defined fileno($filename)) {
+ if (openhandle $filename) {
$IN = $filename;
}
else {
diff --git a/test/path-class.t b/test/path-class.t
new file mode 100644
index 0000000..66f6b69
--- /dev/null
+++ b/test/path-class.t
@@ -0,0 +1,27 @@
+use strict;
+use warnings;
+
+use t::TestYAML tests => 2;
+use YAML::XS qw/ DumpFile LoadFile /;
+
+my $pc = eval "use Path::Class; 1";
+
+my $file;
+
+SKIP: {
+ skip "Path::Class need for this test", 2 unless $pc;
+
+ my $data = {
+ foo => "boo",
+ };
+ $file = file("t", "path-class-$$.yaml");
+ DumpFile($file, $data);
+ ok -f $file, "Path::Class $file exists";
+
+ my $data2 = LoadFile($file);
+ is_deeply($data, $data2, "Path::Class roundtrip works");
+}
+
+END {
+ unlink $file if defined $file;
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libyaml-libyaml-perl.git
More information about the Pkg-perl-cvs-commits
mailing list