}
else {
safer_unlink $filename;
- open F, ">$filename" or die "Can't open $filename: $!";
+ $F = safer_open($filename);
binmode F;
$F = \*F;
}
}
safer_unlink "pod/perlapi.pod";
-open (DOC, ">pod/perlapi.pod") or
- die "Can't create pod/perlapi.pod: $!\n";
-binmode DOC;
+my $doc = safer_open("pod/perlapi.pod");
walk_table { # load documented functions into appropriate hash
if (@_ > 1) {
}
}
return "";
-} \*DOC;
+} $doc;
for (sort keys %docfuncs) {
# Have you used a full for apidoc or just a func name?
warn "Unable to place $_!\n";
}
-readonly_header(\*DOC);
+readonly_header($doc);
-print DOC <<'_EOB_';
+print $doc <<'_EOB_';
=head1 NAME
perlapi - autogenerated documentation for the perl public API
# case insensitive sort, with fallback for determinacy
for $key (sort { uc($a) cmp uc($b) || $a cmp $b } keys %apidocs) {
my $section = $apidocs{$key};
- print DOC "\n=head1 $key\n\n=over 8\n\n";
+ print $doc "\n=head1 $key\n\n=over 8\n\n";
# Again, fallback for determinacy
for my $key (sort { uc($a) cmp uc($b) || $a cmp $b } keys %$section) {
- docout(\*DOC, $key, $section->{$key});
+ docout($doc, $key, $section->{$key});
}
- print DOC "\n=back\n";
+ print $doc "\n=back\n";
}
-print DOC <<'_EOE_';
+print $doc <<'_EOE_';
=head1 AUTHORS
_EOE_
-readonly_footer(\*DOC);
+readonly_footer($doc);
-close(DOC) or die "Error closing pod/perlapi.pod: $!";
+safer_close($doc);
safer_unlink "pod/perlintern.pod";
-open(GUTS, ">pod/perlintern.pod") or
- die "Unable to create pod/perlintern.pod: $!\n";
-binmode GUTS;
-readonly_header(\*GUTS);
-print GUTS <<'END';
+my $guts = safer_open("pod/perlintern.pod");
+readonly_header($guts);
+print $guts <<'END';
=head1 NAME
perlintern - autogenerated documentation of purely B<internal>
for $key (sort { uc($a) cmp uc($b); } keys %gutsdocs) {
my $section = $gutsdocs{$key};
- print GUTS "\n=head1 $key\n\n=over 8\n\n";
+ print $guts "\n=head1 $key\n\n=over 8\n\n";
for my $key (sort { uc($a) cmp uc($b); } keys %$section) {
- docout(\*GUTS, $key, $section->{$key});
+ docout($guts, $key, $section->{$key});
}
- print GUTS "\n=back\n";
+ print $guts "\n=back\n";
}
-print GUTS <<'END';
+print $guts <<'END';
=head1 AUTHORS
perlguts(1), perlapi(1)
END
-readonly_footer(\*GUTS);
+readonly_footer($guts);
-close GUTS or die "Error closing pod/perlintern.pod: $!";
+safer_close($guts);
}
print $F $trailer if $trailer;
unless (ref $filename) {
- close $F or die "Error closing $filename: $!";
+ safer_close($F);
rename_if_different("$filename-new", $filename);
}
}
/* ex: set ro: */
END
-close($em) or die "Error closing EM: $!";
+safer_close($em);
rename_if_different('embed.h-new', 'embed.h');
$em = safer_open('embedvar.h-new');
/* ex: set ro: */
END
-close($em) or die "Error closing EM: $!";
+safer_close($em);
rename_if_different('embedvar.h-new', 'embedvar.h');
my $capi = safer_open('perlapi.c-new');
/* ex: set ro: */
EOT
-close $capih or die "Error closing CAPIH: $!";
+safer_close($capih);
rename_if_different('perlapi.h-new', 'perlapi.h');
print $capi do_not_edit ("perlapi.c"), <<'EOT';
/* ex: set ro: */
EOT
-close($capi) or die "Error closing CAPI: $!";
+safer_close($capi);
rename_if_different('perlapi.c-new', 'perlapi.c');
# functions that take va_list* for implementing vararg functions
print $kw "\n/* ex: set ro: */\n";
-close $kw or die "Error closing keywords.h-new: $!";
+safer_close($kw);
rename_if_different("keywords.h-new", "keywords.h");
print $oc "/* ex: set ro: */\n";
print $on "/* ex: set ro: */\n";
-close $oc or die "Error closing $opcode_new: $!\n";
-close $on or die "Error closing $opname_new: $!\n";
+safer_close($oc);
+safer_close($on);
rename_if_different $opcode_new, 'opcode.h';
rename_if_different $opname_new, 'opnames.h';
print $pp "\n/* ex: set ro: */\n";
print $ppsym "\n# ex: set ro:\n";
-close $pp or die "Error closing pp_proto.h-new: $!\n";
-close $ppsym or die "Error closing pp.sym-new: $!\n";
+safer_close($pp);
+safer_close($ppsym);
rename_if_different $pp_proto_new, 'pp_proto.h';
rename_if_different $pp_sym_new, 'pp.sym';
}
safer_unlink ('overload.h', 'overload.c');
-die "overload.h: $!" unless open(C, ">overload.c");
-binmode C;
-die "overload.h: $!" unless open(H, ">overload.h");
-binmode H;
+my $c = safer_open("overload.c");
+my $h = safer_open("overload.h");
sub print_header {
my $file = shift;
EOF
}
-select C;
+select $c;
print_header('overload.c');
-select H;
+select $h;
print_header('overload.h');
print <<'EOF';
EOF
-print C <<'EOF';
+print $c <<'EOF';
#define AMG_id2name(id) (PL_AMG_names[id]+1)
#define AMG_id2namelen(id) (PL_AMG_namelens[id]-1)
my $last = pop @names;
-print C " $_,\n" foreach map { length $_ } @names;
+print $c " $_,\n" foreach map { length $_ } @names;
my $lastlen = length $last;
-print C <<"EOT";
+print $c <<"EOT";
$lastlen
};
overload.pm. */
EOT
-print C " \"$_\",\n" foreach map { s/(["\\"])/\\$1/g; $_ } @names;
+print $c " \"$_\",\n" foreach map { s/(["\\"])/\\$1/g; $_ } @names;
-print C <<"EOT";
+print $c <<"EOT";
"$last"
};
EOT
-close H or die $!;
-close C or die $!;
+safer_close($h);
+safer_close($c);
__DATA__
# Fallback should be the first
/* ex: set ro: */
EOF
-close($h);
+safer_close($h);
rename_if_different('reentr.h-new', 'reentr.h');
# Prepare to write the reentr.c.
/* ex: set ro: */
EOF
-close($c);
+safer_close($c);
rename_if_different('reentr.c-new', 'reentr.c');
__DATA__
/* ex: set ro: */
EOP
-close $out or die "close $tmp_h: $!";
+safer_close($out);
rename_if_different $tmp_h, 'regnodes.h';
my $name = shift;
my $fh = gensym;
open $fh, ">$name" or die "Can't create $name: $!";
+ *{$fh}->{SCALAR} = $name;
binmode $fh;
$fh;
}
+sub safer_close {
+ my $fh = shift;
+ close $fh or die 'Error closing ' . *{$fh}->{SCALAR} . ": $!";
+}
+
1;
/* ex: set ro: */
EOM
-close $warn;
+safer_close $warn;
rename_if_different("warnings.h-new", "warnings.h");
while (<DATA>) {
}
print $pm "# ex: set ro:\n";
-close $pm;
+safer_close $pm;
rename_if_different("lib/warnings.pm-new", "lib/warnings.pm");
__END__