diff --git a/Makefile.PL b/Makefile.PL index d81dda7b..3f21bb86 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -307,6 +307,8 @@ sub setup_files "img/*$Config{_o}", "api/*$Config{_o}", "$platform/*$Config{_o}", + qw(img/codecs.c Prima/Config.pm), + qw(makefile.log makefile.log.old makepl.log utils/par.txt), ); # I still like to have my scripts as .pl, but installed without @@ -484,13 +486,13 @@ sub _find_file my ( $pathname, $found); $pathname = "$dir/$fname"; return $pathname if $pathname !~ /\.\./ && -e $pathname; - opendir D, $dir or die "Cannot open dir $dir: $!"; + opendir my $dh, $dir or die "Cannot open dir $dir: $!"; my @entries = map { "$dir/$_"} grep { !/^blib/ } grep { /^[^.]/ && -d "$dir/$_"} - readdir D; - closedir D; + readdir $dh; + closedir $dh; foreach my $entry ( @entries) { $pathname = _find_file( $fname, $entry); next unless defined $pathname; @@ -530,9 +532,8 @@ sub find_cdeps $alldeps{ $cfile} = []; return () unless -f $cfile; - local *CF; - open CF, "<$cfile" or die "Cannot open $cfile: $!"; - while ( ) { + open my $cf, "<", $cfile or die "Cannot open $cfile: $!"; + while ( <$cf>) { chomp; next unless /^\s*\#\s*include\s+"([^\"]+)"/; my $incfile = $1; @@ -548,7 +549,7 @@ sub find_cdeps push @{ $deps->{ $cfile}}, @subdeps; push @{ $alldeps{ $cfile}}, @subdeps; } - close CF; + close $cf; return @{ $deps->{ $cfile}}; } @@ -625,13 +626,12 @@ sub restore_output close OLDSTDERR; if ( -f $NULLDEV ) { - if ( open MAKEFILELOG, '<', $NULLDEV) { - binmode MAKEFILELOG; - seek MAKEFILELOG, $offset_makefile_log, 0; + if ( open my $mffh, '<', $NULLDEV) { + binmode $mffh; + seek $mffh, $offset_makefile_log, 0; local $/; - $captured_makefile_log = ; + $captured_makefile_log = <$mffh>; print "\n", $captured_makefile_log if $cmd_options{VERBOSE}; - close MAKEFILELOG; } } } @@ -658,9 +658,9 @@ sub compile $tmpextras[1] =~ s/\.[^\.+]$/.pdb/; unlink @tmpextras; # leftovers are toxic to msvc - open TMPSRC, ">$tmpsrc" or die "Creation of temporary file $tmpsrc failed"; - print TMPSRC $text; - close TMPSRC; + open my $fh, ">", $tmpsrc or die "Creation of temporary file $tmpsrc failed"; + print $fh $text; + close $fh; null_output; my $cc = cc_command_line( $tmpsrc, $tmpo, $tmpexe, $compile_only || 0); @@ -686,9 +686,9 @@ sub compile_and_run $tmpextras[1] =~ s/\.[^\.+]$/.pdb/; unlink @tmpextras; # leftovers are toxic to msvc - open TMPSRC, ">$tmpsrc" or die "Creation of temporary file $tmpsrc failed"; - print TMPSRC $text; - close TMPSRC; + open my $fh, ">", $tmpsrc or die "Creation of temporary file $tmpsrc failed"; + print $fh $text; + close $fh; null_output; my $cc = cc_command_line( $tmpsrc, $tmpo, $tmpexe, 0); @@ -804,8 +804,8 @@ sub have_define my $tmpsrc = tempfile( "pmts%04d.c"); my $tmpo = $tmpsrc; $tmpo =~ s/\.c$/\.$Config{_o}/; - open TMPSRC, ">$tmpsrc" or die "Creation of temporary file $tmpsrc failed"; - print TMPSRC <", $tmpsrc or die "Creation of temporary file $tmpsrc failed"; + print $fh <$c1" or die "Creation of temporary file $c1 failed"; - print TMPSRC <", $c1 or die "Creation of temporary file $c1 failed"; + print $fh < #include #include @@ -1202,11 +1202,11 @@ XS(boot_pmts$n1) { XSRETURN(1); } D - close TMPSRC; + close $fh; my $c2 = tempfile( "$TMPDIR/pmts%04d.c"); - open TMPSRC, ">$c2" or die "Creation of temporary file $c2 failed"; - print TMPSRC <", $c2 or die "Creation of temporary file $c2 failed"; + print $fh2 < #include #include @@ -1220,7 +1220,7 @@ XS(boot_pmts$n2) { XSRETURN(1); } D - close TMPSRC; + close $fh2; my $cc1 = cc_command_line( $c1, $o1, $dl1, 1, 1); my $cc2 = cc_command_line( $c2, $o2, $dl2, 1, 1); @@ -1918,27 +1918,26 @@ LIBTHAI sub generate_win32_def { - open PRIMADEF, ">$DEFFILE" or die "Cannot create $DEFFILE: $!"; - print PRIMADEF <", $DEFFILE or die "Cannot create $DEFFILE: $!"; + print $primadeffh <; - close F; + my $x = <$fh>; + close $fh; return ( $x =~ m/\bextern\s+\w+(?:\s*\*\s*)?\s+(\w+)\s*\(.*?;/gs ); } @@ -2046,11 +2045,11 @@ sub setup_codecs } } - next unless open F, $fn; - while() { + next unless open my $fh, "<", $fn; + while(<$fh>) { push @inc, $_ if m/^\s*#include\s*\ img/codecs.c" or die "cannot open img/codecs.c:$!\n"; + open my $fh, ">", "img/codecs.c" or die "cannot open img/codecs.c:$!\n"; my $def1 = join("\n", map { "extern void apc_img_codec_$_(void);"} @ACTIVE_CODECS); my $def2 = join("\n", map { "\tapc_img_codec_$_();"} @ACTIVE_CODECS); - print F <$config_h" or die "Creation of $config_h failed: $!"; - print CONFIG <", $config_h or die "Creation of $config_h failed: $!"; + print $configfh < Prima/Config.pm" or die "cannot open Prima/Config.pm:$!\n"; - print F <", "Prima/Config.pm" or die "cannot open Prima/Config.pm:$!\n"; + print $fh <", "utils/par.txt" or die "Cannot open utils/par.txt:$!"; + open my $fh, ">", "utils/par.txt" or die "Cannot open utils/par.txt:$!"; find( sub { return unless -f; return if /\.p[lm]$/i || /^(VB|prima-cfgmaint)$/; my $d = $File::Find::dir; return if $d =~ /examples/; - print F "$d/$_\n"; + print $fh "$d/$_\n"; }, 'Prima'); - close F; } # executed from inside makefiles @@ -2430,16 +2426,15 @@ sub command_postinstall if ( $opt{slib} ) { my $f = "$opt{dest}/auto/Prima/$opt{slib}"; - open F, ">", $f or warn "** warning: Cannot write to a fake lib '$f': Prima extensions won't build\n"; - close F; + open my $fh, ">", $f or warn "** warning: Cannot write to a fake lib '$f': Prima extensions won't build\n"; } $opt{dest} = $ENV{PERL_INSTALL_ROOT} . $opt{dest} if defined $ENV{PERL_INSTALL_ROOT}; my $fn_cfg = "$opt{dest}/Prima/Config.pm"; print "Updating config $fn_cfg\n"; - open F, $fn_cfg or die "cannot open $fn_cfg:$!\n"; - open FF, "> $fn_cfg.tmp" or die "cannot open $fn_cfg.tmp:$!\n"; + open my $fh, "<", $fn_cfg or die "cannot open $fn_cfg:$!\n"; + open my $fh2, ">", "$fn_cfg.tmp" or die "cannot open $fn_cfg.tmp:$!\n"; my ( $c_state, $ci_state) = (0,0); my (%ci, %vars); @@ -2448,12 +2443,13 @@ sub command_postinstall s/\//\\/g for values %vars; } - print FF <catfile(dirname(__FILE__), '..'); %Config = ( HEADER - while ( ) { + while ( <$fh>) { if ( $ci_state == 0) { if ( m/\%Config_inst = \(/) { $ci_state = 1; @@ -2473,7 +2469,7 @@ HEADER } elsif ( m/^\s*(\S+)\s*/ ) { my $k = $1; s/\$\((\w+)\)/\$$1/g; - s/'/"/g; + s/'([^']*)'/qq{$1}/g; s{\\}{\\\\}g; $ci{$k} = $_; } @@ -2487,20 +2483,20 @@ HEADER $c_state = 0; } else { if ( m/^\s*(\S+)\s*/ && exists $ci{$1}) { - print FF $ci{$1}; + print $fh2 $ci{$1}; } else { - print FF $_; + print $fh2 $_; } } } } -print FF <; - close F; + my $ct = <$fh>; + close $fh; $ct =~ m/dl_load_flags\s*\{\s*0x0(\d)/; return if $1 eq $DL_LOAD_FLAGS; @@ -2521,9 +2517,9 @@ sub command_dl print "Setting dl_load_flags=$DL_LOAD_FLAGS in $f\n"; $ct =~ s/(dl_load_flags\s*\{\s*)0x00/${1}0x0$DL_LOAD_FLAGS/; # open_rw(\*F, $f); - open F, "> $f.tmp" or die "Cannot open $f.tmp:$!"; - print F $ct; - close F; + open my $fh2, ">", "$f.tmp" or die "Cannot open $f.tmp:$!"; + print $fh2 $ct; + close $fh2; unlink $f; rename "$f.tmp", $f; } @@ -2557,8 +2553,8 @@ sub command_bindist my %dirs; my @files; - open MAN, "<", "MANIFEST" or die "Cannot open MANIFEST:$!\n"; - for my $path () { + open my $manfh, "<", "MANIFEST" or die "Cannot open MANIFEST:$!\n"; + for my $path (<$manfh>) { chomp $path; my ( $d, $f ); if ( $path =~ m[^(.+)/([^\/]+)$]) { @@ -2596,8 +2592,8 @@ sub command_bindist if ($^O eq 'cygwin') { system "strip $DISTNAME/auto/Prima/Prima.$Config{dlext}" ; # it's 27 MB! $cygwin_fake_Slib = 'SlibPrima' . ( $Config{lib_ext} || '.a' ); - open F, '>', "$DISTNAME/auto/Prima/$cygwin_fake_Slib"; - close F; + open my $fh, '>', "$DISTNAME/auto/Prima/$cygwin_fake_Slib"; + close $fh; } my $zipname = "$DISTNAME.zip"; @@ -2612,12 +2608,12 @@ sub command_cpbin { my ($from, $to) = @_; local $/; - open FROM, '<', $from or die "Cannot open $from:$!\n"; - open TO, '>', $to or die "Cannot open $to:$!\n"; - print TO "#!$Config{perlpath} -w\n"; - print TO ; - close TO; - close FROM; + open my $fromfh, '<', $from or die "Cannot open $from:$!\n"; + open my $tofh, '>', $to or die "Cannot open $to:$!\n"; + print $tofh "#!$Config{perlpath} -w\n"; + print {$tofh} <$fromfh>; + close $tofh; + close $fromfh; chmod 0755, $to; }