package Perl::Tidy::HtmlWriter;
use strict;
use warnings;
-our $VERSION = '20210717';
+our $VERSION = '20221112';
+use English qw( -no_match_vars );
use File::Basename;
+use constant EMPTY_STRING => q{};
+use constant SPACE => q{ };
+
# class variables
use vars qw{
%html_color
BEGIN {
if ( !eval { require HTML::Entities; 1 } ) {
- $missing_html_entities = $@ ? $@ : 1;
+ $missing_html_entities = $EVAL_ERROR ? $EVAL_ERROR : 1;
}
if ( !eval { require Pod::Html; 1 } ) {
- $missing_pod_html = $@ ? $@ : 1;
+ $missing_pod_html = $EVAL_ERROR ? $EVAL_ERROR : 1;
}
}
( $html_fh, my $html_filename ) =
Perl::Tidy::streamhandle( $html_file, 'w' );
unless ($html_fh) {
- Perl::Tidy::Warn("can't open $html_file: $!\n");
+ Perl::Tidy::Warn("can't open $html_file: $ERRNO\n");
return;
}
$html_file_opened = 1;
( $title, my $path ) = fileparse($input_file);
}
my $toc_item_count = 0;
- my $in_toc_package = "";
+ my $in_toc_package = EMPTY_STRING;
my $last_level = 0;
return bless {
_input_file => $input_file, # name of input file
my $end_package_list = sub {
if ( ${$rin_toc_package} ) {
$html_toc_fh->print("</ul>\n</li>\n");
- ${$rin_toc_package} = "";
+ ${$rin_toc_package} = EMPTY_STRING;
}
+ return;
};
my $start_package_list = sub {
<ul>
EOM
${$rin_toc_package} = $package;
+ return;
};
# start the table of contents on the first item
);
# These token types will all be called identifiers for now
- # FIXME: could separate user defined modules as separate type
my @identifier = qw< i t U C Y Z G :: CORE::>;
@token_short_names{@identifier} = ('i') x scalar(@identifier);
my $css_filename = shift;
my $fh;
unless ( $fh = IO::File->new("> $css_filename") ) {
- Perl::Tidy::Die("can't open $css_filename: $!\n");
+ Perl::Tidy::Die("can't open $css_filename: $ERRNO\n");
}
write_style_sheet_data($fh);
close_object($fh);
my $long_name = $short_to_long_names{$short_name};
my $abbrev = '.' . $short_name;
- if ( length($short_name) == 1 ) { $abbrev .= ' ' } # for alignment
+ if ( length($short_name) == 1 ) { $abbrev .= SPACE } # for alignment
my $color = $html_color{$short_name};
if ( !defined($color) ) { $color = $text_color }
$fh->print("$abbrev \{ color: $color;");
# this error shouldn't happen ... we just used this filename
Perl::Tidy::Warn(
"unable to open temporary file $tmpfile; cannot use pod2html\n");
- goto RETURN;
+ return $success_flag;
}
my $html_fh = $self->{_html_fh};
# This routine will write the html selectively and store the toc
my $html_print = sub {
- foreach (@_) {
- $html_fh->print($_) unless ($no_print);
- if ($in_toc) { push @toc, $_ }
+ foreach my $line (@_) {
+ $html_fh->print($line) unless ($no_print);
+ if ($in_toc) { push @toc, $line }
}
+ return;
};
# loop over lines of html output from pod2html and merge in
# the necessary perltidy html sections
my ( $saw_body, $saw_index, $saw_body_end );
- my $timestamp = "";
+ my $timestamp = EMPTY_STRING;
if ( $rOpts->{'timestamp'} ) {
my $date = localtime;
$timestamp = "on $date";
$html_print->("<hr />\n") if $rOpts->{'frames'};
$html_print->("<h2>Code Index:</h2>\n");
##my @toc = map { $_ .= "\n" } split /\n/, $toc_string;
- my @toc = map { $_ . "\n" } split /\n/, $toc_string;
- $html_print->(@toc);
+ my @toc_st = map { $_ . "\n" } split /\n/, $toc_string;
+ $html_print->(@toc_st);
}
- $in_toc = "";
+ $in_toc = EMPTY_STRING;
$no_print = 0;
}
$html_print->("<hr />\n") if $rOpts->{'frames'};
$html_print->("<h2>Code Index:</h2>\n");
##my @toc = map { $_ .= "\n" } split /\n/, $toc_string;
- my @toc = map { $_ . "\n" } split /\n/, $toc_string;
- $html_print->(@toc);
+ my @toc_st = map { $_ . "\n" } split /\n/, $toc_string;
+ $html_print->(@toc_st);
}
- $in_toc = "";
+ $in_toc = EMPTY_STRING;
$ul_level = 0;
$no_print = 0;
}
$success_flag = 0;
}
- RETURN:
close_object($html_fh);
# note that we have to unlink tmpfile before making frames
# because the tmpfile may be one of the names used for frames
if ( -e $tmpfile ) {
unless ( unlink($tmpfile) ) {
- Perl::Tidy::Warn("couldn't unlink temporary file $tmpfile: $!\n");
+ Perl::Tidy::Warn(
+ "couldn't unlink temporary file $tmpfile: $ERRNO\n");
$success_flag = 0;
}
}
$title = escape_html($title);
# FUTURE input parameter:
- my $top_basename = "";
+ my $top_basename = EMPTY_STRING;
# We need to produce 3 html files:
# 1. - the table of contents
# 2. The current .html filename is renamed to be the contents panel
rename( $html_filename, $src_filename )
- or Perl::Tidy::Die("Cannot rename $html_filename to $src_filename:$!\n");
+ or Perl::Tidy::Die(
+ "Cannot rename $html_filename to $src_filename: $ERRNO\n");
# 3. Then use the original html filename for the frame
write_frame_html(
# write a separate html table of contents file for frames
my ( $title, $toc_filename, $src_basename, $rtoc, $src_frame_name ) = @_;
my $fh = IO::File->new( $toc_filename, 'w' )
- or Perl::Tidy::Die("Cannot open $toc_filename:$!\n");
+ or Perl::Tidy::Die("Cannot open $toc_filename: $ERRNO\n");
$fh->print(<<EOM);
<html>
<head>
my $first_anchor =
change_anchor_names( $rtoc, $src_basename, "$src_frame_name" );
- $fh->print( join "", @{$rtoc} );
+ $fh->print( join EMPTY_STRING, @{$rtoc} );
$fh->print(<<EOM);
</body>
) = @_;
my $fh = IO::File->new( $frame_filename, 'w' )
- or Perl::Tidy::Die("Cannot open $toc_basename:$!\n");
+ or Perl::Tidy::Die("Cannot open $toc_basename: $ERRNO\n");
$fh->print(<<EOM);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
# --------------------------------------------------
my $input_file = $self->{_input_file};
my $title = escape_html($input_file);
- my $timestamp = "";
+ my $timestamp = EMPTY_STRING;
if ( $rOpts->{'timestamp'} ) {
my $date = localtime;
$timestamp = "on $date";
my $rlast_level = $self->{_rlast_level};
my $rpackage_stack = $self->{_rpackage_stack};
- for ( my $j = 0 ; $j < @{$rtoken_type} ; $j++ ) {
+ foreach my $j ( 0 .. @{$rtoken_type} - 1 ) {
$type = $rtoken_type->[$j];
$token = $rtokens->[$j];
$level = $rlevels->[$j];
$type = 'M';
# but don't include sub declarations in the toc;
- # these wlll have leading token types 'i;'
- my $signature = join "", @{$rtoken_type};
+ # these will have leading token types 'i;'
+ my $signature = join EMPTY_STRING, @{$rtoken_type};
unless ( $signature =~ /^i;/ ) {
my $subname = $token;
$subname =~ s/[\s\(].*$//; # remove any attributes and prototype
$html_line = $1;
}
else {
- $html_line = "";
+ $html_line = EMPTY_STRING;
}
my ($rcolored_tokens) =
$self->markup_tokens( $rtokens, $rtoken_type, $rlevels );
- $html_line .= join '', @{$rcolored_tokens};
+ $html_line .= join EMPTY_STRING, @{$rcolored_tokens};
}
# markup line of non-code..
elsif ( $line_type eq 'HERE_END' ) { $line_character = 'h' }
elsif ( $line_type eq 'FORMAT' ) { $line_character = 'H' }
elsif ( $line_type eq 'FORMAT_END' ) { $line_character = 'h' }
+ elsif ( $line_type eq 'SKIP' ) { $line_character = 'H' }
+ elsif ( $line_type eq 'SKIP_END' ) { $line_character = 'h' }
elsif ( $line_type eq 'SYSTEM' ) { $line_character = 'c' }
elsif ( $line_type eq 'END_START' ) {
$line_character = 'k';
# otherwise, just clear the current string and start
# over
else {
- ${$rpre_string} = "";
+ ${$rpre_string} = EMPTY_STRING;
$html_pod_fh->print("\n");
}
}
# add the line number if requested
if ( $rOpts->{'html-line-numbers'} ) {
my $extra_space =
- ( $line_number < 10 ) ? " "
- : ( $line_number < 100 ) ? " "
- : ( $line_number < 1000 ) ? " "
- : "";
- $html_line = $extra_space . $line_number . " " . $html_line;
+ ( $line_number < 10 ) ? SPACE x 3
+ : ( $line_number < 100 ) ? SPACE x 2
+ : ( $line_number < 1000 ) ? SPACE
+ : EMPTY_STRING;
+ $html_line = $extra_space . $line_number . SPACE . $html_line;
}
# write the line
return;
}
1;
-