Commits

Shlomi Fish committed 0cb5aee

Normalised more open() calls.

Converted them to slurp() or added lexical filehandles.

Comments (0)

Files changed (5)

     # Log Memory Usage
     local $^W;
     my %mem;
-    if (open(FH, "/proc/self/status")) {
+    if (open(my $FH, '<', '/proc/self/status')) {
         my $units;
-        while (<FH>) {
+        while (<$FH>) {
             if (/^VmSize.*?(\d+)\W*(\w+)$/) {
                 $mem{Total} = $1;
                 $units = $2;
                 $mem{Resident} = $1;
             }
         }
-        close FH;
+        close ($FH);
 
         if ($LibXML::TOTALMEM != $mem{Total}) {
             warn("LEAK! : ", $mem{Total} - $LibXML::TOTALMEM, " $units\n") unless $initialise;
     ok($doc);
 }
 
-my $fh = IO::File->new($html) || die "Can't open $html: $!";
+my $fh;
+
+open $fh, '<', $html
+    or die "Can't open '$html': $!";
 
 my $string;
 {
   ok($htmldoc->findvalue('//p/text()'), $utf_str);
   ok($htmldoc->URI, 'foo');
   
-  open $fh, $test_file;
+  open $fh, '<', $test_file
+    or die "Cannot open '$test_file' for reading - $!";
   $htmldoc = $parser->parse_html_fh( $fh );
   close $fh;
   ok( $htmldoc && $htmldoc->getDocumentElement );
   ok($htmldoc->findvalue('//p/text()'), $utf_str);
   
-  open $fh, $test_file;
+  open $fh, '<', $test_file
+    or die "Cannot open '$test_file' for reading - $!";
   $htmldoc = $parser->parse_html_fh( $fh, { encoding => 'iso-8859-2',
 					    URI => 'foo',
 					  });
     skip("skipping for libxml2 < 2.6.27") for 1..2;
   } else {
     # translate to UTF8 on perl-side
-    open $fh, '<:encoding(iso-8859-2)', $test_file;
+    open $fh, '<:encoding(iso-8859-2)', $test_file
+        or die "Cannot open '$test_file' for reading - $!";
     $htmldoc = $parser->parse_html_fh( $fh, { encoding => 'UTF-8' });
     close $fh;
     ok( $htmldoc && $htmldoc->getDocumentElement );
   ok( $htmldoc && $htmldoc->getDocumentElement );
   ok($htmldoc->findvalue('//p/text()'), $utf_str);
 
-  open $fh, $test_file;
+  open $fh, '<', $test_file
+    or die "Cannot open '$test_file' for reading - $!";
   $htmldoc = $parser->parse_html_fh( $fh, { encoding => 'iso-8859-2' });
   close $fh;
   ok( $htmldoc && $htmldoc->getDocumentElement );
     skip("skipping for Perl < 5.8") for 1..2;
   } else {
     # translate to UTF8 on perl-side
-    open $fh, '<:encoding(iso-8859-2)', $test_file;
+    open my $fh, '<:encoding(iso-8859-2)', $test_file
+        or die "Cannot open '$test_file' for reading - $!";
     $htmldoc = $parser->parse_html_fh( $fh, { encoding => 'UTF-8' } );
     close $fh;
     ok( $htmldoc && $htmldoc->getDocumentElement );
 use strict;
 use warnings;
 
+use lib './t/lib';
+use TestHelpers;
+
 use Test;
 BEGIN { plan tests => 42 }
 use XML::LibXML;
 }
 
 chdir("example/complex") || die "chdir: $!";
-open(F, "complex.xml") || die "Cannot open complex.xml: $!";
-local $/;
-my $str = <F>;
-close F;
+
+my $str = slurp('complex.xml');
 
 {
     # tests if callbacks are called correctly within DTDs
 
 use strict;
 use warnings;
+
+use lib './t/lib';
+use TestHelpers;
+
 use Test;
 
 BEGIN { 
 
 print "# 2 parse schema from a string\n";
 {
-    open RNGFILE, "<$file";
-    my $string = join "", <RNGFILE>;
-    close RNGFILE;
+    my $string = slurp($file);
 
     my $rngschema = XML::LibXML::RelaxNG->new( string => $string );
     ok ( $rngschema );
 
-    open RNGFILE, "<$badfile";
-    $string = join "", <RNGFILE>;
-    close RNGFILE;
+    $string = slurp($badfile);
+
     eval { $rngschema = XML::LibXML::RelaxNG->new( string => $string ); };
     ok( $@ );
 }
 }
 
 
-my $fd;
 # FD interface
 for my $how (qw(FD IO)) {
 #  my $fd;
-  open $fd, $file or die "cannot open $file: $!\n";
+  open my $fd, '<', $file or die "cannot open $file: $!\n";
   my $reader = new XML::LibXML::Reader($how => $fd, URI => $file);
   isa_ok($reader, "XML::LibXML::Reader");
   $reader->read;
 
 # scalar interface
 {
-  open my $fd, $file or die "cannot open $file: $!\n";
+  open my $fd, '<', $file or die "cannot open $file: $!\n";
   my $doc;
   {
     local $/;