@@ -19,7 +19,6 @@ use File::Basename ();
1919use File::Spec 0.82 ();
2020use File::Compare ();
2121use Module::Build::Dumper ();
22- use IO::File ();
2322use Text::ParseWords ();
2423
2524use Module::Build::ModuleInfo;
@@ -1082,7 +1081,7 @@ sub subclass {
10821081 File::Path::mkpath($filedir );
10831082 die " Can't create directory $filedir : $! " unless -d $filedir ;
10841083
1085- my $fh = IO::File -> new( " > $filename " ) or die " Can't create $filename : $! " ;
1084+ open ( my $fh , ' > ' , $filename ) or die " Can't create $filename : $! " ;
10861085 print $fh <<EOF ;
10871086package $opts {class};
10881087use $pack ;
@@ -1229,7 +1228,7 @@ sub _pod_parse {
12291228
12301229 my $docfile = $self -> _main_docfile
12311230 or return ;
1232- my $fh = IO::File -> new( $docfile )
1231+ open ( my $fh , ' < ' , $docfile )
12331232 or return ;
12341233
12351234 require Module::Build::PodParser;
@@ -1289,13 +1288,13 @@ sub read_config {
12891288
12901289 my $file = $self -> config_file(' build_params' )
12911290 or die " Can't find 'build_params' in " . $self -> config_dir;
1292- my $fh = IO::File -> new( $file ) or die " Can't read '$file ': $! " ;
1291+ open ( my $fh , ' < ' , $file ) or die " Can't read '$file ': $! " ;
12931292 my $ref = eval do {local $/ ; <$fh >};
12941293 die if $@ ;
1294+ close $fh ;
12951295 my $c ;
12961296 ($self -> {args }, $c , $self -> {properties }) = @$ref ;
12971297 $self -> {config } = Module::Build::Config-> new(values => $c );
1298- close $fh ;
12991298}
13001299
13011300sub has_config_data {
@@ -1307,13 +1306,14 @@ sub _write_data {
13071306 my ($self , $filename , $data ) = @_ ;
13081307
13091308 my $file = $self -> config_file($filename );
1310- my $fh = IO::File -> new( " > $file " ) or die " Can't create '$file ': $! " ;
1309+ open ( my $fh , ' > ' , $file ) or die " Can't create '$file ': $! " ;
13111310 unless (ref ($data )) { # e.g. magicnum
13121311 print $fh $data ;
13131312 return ;
13141313 }
13151314
13161315 print {$fh } Module::Build::Dumper-> _data_dump($data );
1316+ close $fh ;
13171317}
13181318
13191319sub write_config {
@@ -1832,10 +1832,10 @@ use File::Spec;
18321832
18331833sub magic_number_matches {
18341834 return 0 unless -e '$q {magic_numfile}';
1835- local * FH;
1836- open FH, '$q {magic_numfile}' or return 0;
1837- my \$ filenum = <FH>;
1838- close FH;
1835+ my \$ FH;
1836+ open \$ FH, '<', '$q {magic_numfile}' or return 0;
1837+ my \$ filenum = <\$ FH>;
1838+ close \$ FH;
18391839 return \$ filenum == $magic_number ;
18401840}
18411841
@@ -1972,7 +1972,7 @@ sub create_build_script {
19721972
19731973 $self -> log_info(" Creating new '$build_script ' script for " ,
19741974 " '$dist_name ' version '$dist_version '\n " );
1975- my $fh = IO::File -> new( " > $build_script " ) or die " Can't create '$build_script ': $! " ;
1975+ open ( my $fh , ' > ' , $build_script ) or die " Can't create '$build_script ': $! " ;
19761976 $self -> print_build_script($fh );
19771977 close $fh ;
19781978
@@ -2340,7 +2340,7 @@ sub read_modulebuildrc {
23402340 return () unless $modulebuildrc ;
23412341 }
23422342
2343- my $fh = IO::File -> new( $modulebuildrc )
2343+ open ( my $fh , ' < ' , $modulebuildrc )
23442344 or die " Can't open $modulebuildrc : $! " ;
23452345
23462346 my %options ; my $buffer = ' ' ;
@@ -2461,7 +2461,7 @@ sub get_action_docs {
24612461 (my $file = $class ) =~ s { ::} { /} g ;
24622462 # NOTE: silently skipping relative paths if any chdir() happened
24632463 $file = $INC {$file . ' .pm' } or next ;
2464- my $fh = IO::File -> new( " < $file " ) or next ;
2464+ open ( my $fh , ' < ' , $file ) or next ;
24652465 $files_found ++;
24662466
24672467 # Code below modified from /usr/bin/perldoc
@@ -3104,7 +3104,7 @@ sub fix_shebang_line { # Adapted from fixin() in ExtUtils::MM_Unix 1.35
31043104
31053105 my ($does_shbang ) = $c -> get(' sharpbang' ) =~ / ^\s *\#\! / ;
31063106 for my $file (@files ) {
3107- my $FIXIN = IO::File -> new( $file ) or die " Can't process '$file ': $! " ;
3107+ open ( my $FIXIN , ' < ' , $file ) or die " Can't process '$file ': $! " ;
31083108 local $/ = " \n " ;
31093109 chomp (my $line = <$FIXIN >);
31103110 next unless $line =~ s / ^\s *\# !\s *// ; # Not a shebang file.
@@ -3124,7 +3124,7 @@ eval 'exec $interpreter $arg -S \$0 \${1+"\$\@"}'
31243124 if 0; # not running under some shell
31253125} unless $self -> is_windowsish; # this won't work on win32, so don't
31263126
3127- my $FIXOUT = IO::File -> new( " > $file .new" )
3127+ open ( my $FIXOUT , ' > ' , " $file .new" )
31283128 or die " Can't create new $file : $! \n " ;
31293129
31303130 # Print out the new #! line (or equivalent).
@@ -3321,7 +3321,7 @@ sub contains_pod {
33213321 my ($self , $file ) = @_ ;
33223322 return ' ' unless -T $file ; # Only look at text files
33233323
3324- my $fh = IO::File -> new( $file ) or die " Can't open $file : $! " ;
3324+ open ( my $fh , ' < ' , $file ) or die " Can't open $file : $! " ;
33253325 while (my $line = <$fh >) {
33263326 return 1 if $line =~ / ^\= (?:head|pod|item)/ ;
33273327 }
@@ -3438,7 +3438,7 @@ sub htmlify_pods {
34383438 join (" , " , map { " q{$_ } => q{$opts {$_ }}" } (keys %opts )) . " ) failed: $@ " );
34393439 } else {
34403440 my $path2root = File::Spec-> catdir((File::Spec-> updir) x @dirs );
3441- my $fh = IO::File -> new( $infile ) or die " Can't read $infile : $! " ;
3441+ open ( my $fh , ' < ' , $infile ) or die " Can't read $infile : $! " ;
34423442 my $abstract = Module::Build::PodParser-> new(fh => $fh )-> get_abstract();
34433443
34443444 my $title = join ( ' ::' , (@dirs , $name ) );
@@ -3477,9 +3477,9 @@ sub htmlify_pods {
34773477 $errors ++;
34783478 next POD;
34793479 }
3480- my $fh = IO::File -> new( $tmpfile ) or die " Can't read $tmpfile : $! " ;
3480+ open ( my $fh , ' < ' , $tmpfile ) or die " Can't read $tmpfile : $! " ;
34813481 my $html = join (' ' ,<$fh >);
3482- $fh -> close ;
3482+ close $fh ;
34833483 if (!$self -> _is_ActivePerl) {
34843484 # These fixups are already done by AP::DT:P:pod2html
34853485 # The output from pod2html is NOT XHTML!
@@ -3494,9 +3494,9 @@ sub htmlify_pods {
34943494 # Fixup links that point to our temp blib
34953495 $html =~ s /\Q $blibdir\E // g ;
34963496
3497- $fh = IO::File -> new( " > $outfile " ) or die " Can't write $outfile : $! " ;
3497+ open ( $fh , ' > ' , $outfile ) or die " Can't write $outfile : $! " ;
34983498 print $fh $html ;
3499- $fh -> close ;
3499+ close $fh ;
35003500 unlink ($tmpfile );
35013501 }
35023502
@@ -3865,12 +3865,12 @@ sub _add_to_manifest {
38653865 my $mode = (stat $manifest )[2];
38663866 chmod ($mode | oct (222), $manifest ) or die " Can't make $manifest writable: $! " ;
38673867
3868- my $fh = IO::File -> new( " < $manifest " ) or die " Can't read $manifest : $! " ;
3868+ open ( my $fh , ' < ' , $manifest ) or die " Can't read $manifest : $! " ;
38693869 my $last_line = (<$fh >)[-1] || " \n " ;
38703870 my $has_newline = $last_line =~ / \n $ / ;
3871- $fh -> close ;
3871+ close $fh ;
38723872
3873- $fh = IO::File -> new( " >> $manifest " ) or die " Can't write to $manifest : $! " ;
3873+ open ( $fh , ' >> ' , $manifest ) or die " Can't write to $manifest : $! " ;
38743874 print $fh " \n " unless $has_newline ;
38753875 print $fh map " $_ \n " , @$lines ;
38763876 close $fh ;
@@ -3966,7 +3966,7 @@ HERE
39663966
39673967 $self -> delete_filetree(' LICENSE' );
39683968
3969- my $fh = IO::File -> new( ' > LICENSE' )
3969+ open ( my $fh , ' > ' , ' LICENSE' )
39703970 or die " Can't write LICENSE file: $! " ;
39713971 print $fh $license -> fulltext;
39723972 close $fh ;
@@ -3998,8 +3998,7 @@ EOF
39983998 } elsif ( eval {require Pod::Text; 1} ) {
39993999 $self -> log_info(" Creating README using Pod::Text\n " );
40004000
4001- my $fh = IO::File-> new(' > README' );
4002- if ( defined ($fh ) ) {
4001+ if ( open (my $fh , ' >' , ' README' ) ) {
40034002 local $^W = 0;
40044003 no strict " refs" ;
40054004
@@ -4020,7 +4019,7 @@ EOF
40204019
40214020 Pod::Text::pod2text( $docfile , $fh );
40224021
4023- $fh -> close ;
4022+ close $fh ;
40244023 } else {
40254024 $self -> log_warn(
40264025 " Cannot create 'README' file: Can't open file for writing\n " );
@@ -4214,17 +4213,17 @@ sub _append_maniskip {
42144213 my $skip = shift ;
42154214 my $file = shift || ' MANIFEST.SKIP' ;
42164215 return unless defined $skip && length $skip ;
4217- my $fh = IO::File -> new( " >> $file " )
4216+ open ( my $fh , ' >> ' , $file )
42184217 or die " Can't open $file : $! " ;
42194218
42204219 print $fh " $skip \n " ;
4221- $fh -> close () ;
4220+ close $fh ;
42224221}
42234222
42244223sub _write_default_maniskip {
42254224 my $self = shift ;
42264225 my $file = shift || ' MANIFEST.SKIP' ;
4227- my $fh = IO::File -> new( " > $file " )
4226+ open ( my $fh , ' > ' , $file )
42284227 or die " Can't open $file : $! " ;
42294228
42304229 my $content = $self -> _eumanifest_has_include ? " #!include_default\n "
@@ -4250,6 +4249,8 @@ EOF
42504249 $content .= ' \b' .$self -> dist_name.' -[\d\.\_]+' ." \n " ;
42514250
42524251 print $fh $content ;
4252+
4253+ close $fh ;
42534254
42544255 return ;
42554256}
@@ -5413,7 +5414,7 @@ sub compile_xs {
54135414 @typemaps , $file );
54145415
54155416 $self -> log_info(" @command \n " );
5416- my $fh = IO::File -> new( " > $args {outfile}" ) or die " Couldn't write $args {outfile}: $! " ;
5417+ open ( my $fh , ' > ' , $args {outfile }) or die " Couldn't write $args {outfile}: $! " ;
54175418 print {$fh } $self -> _backticks(@command );
54185419 close $fh ;
54195420 }
@@ -5542,7 +5543,7 @@ sub process_xs {
55425543 require ExtUtils::Mkbootstrap;
55435544 $self -> log_info(" ExtUtils::Mkbootstrap::Mkbootstrap('$spec ->{bs_file}')\n " );
55445545 ExtUtils::Mkbootstrap::Mkbootstrap($spec -> {bs_file }); # Original had $BSLOADLIBS - what's that?
5545- { my $fh = IO::File -> new( " >> $spec ->{bs_file}" )} # create
5546+ open ( my $fh , ' >> ' , $spec -> {bs_file }); # create
55465547 utime ((time )x 2 , $spec -> {bs_file }); # touch
55475548 }
55485549
0 commit comments