#####################################################################
#
-# the Perl::Tidy::FileWriter class writes the output file
+# The Perl::Tidy::FileWriter class writes the output file created
+# by the formatter. It receives each output line and performs some
+# important monitoring services. These include:
+#
+# - Verifying that lines do not go out with tokens in the wrong order
+# - Checking for obvious iteration convergence when all output tokens
+# match all input tokens
+# - Keeping track of consecutive blank and non-blank lines
+# - Looking for line lengths which exceed the maximum requested length
+# - Reporting results to the log file
#
#####################################################################
use constant DEVEL_MODE => 0;
use constant EMPTY_STRING => q{};
+# A limit on message length when a fault is detected
+use constant LONG_MESSAGE => 256;
+
+# Maximum number of little messages; probably need not be changed.
+use constant MAX_NAG_MESSAGES => 6;
+
sub AUTOLOAD {
# Catch any undefined sub calls so that we are sure to get
# required to avoid call to AUTOLOAD in some versions of perl
}
-my $input_stream_name = EMPTY_STRING;
-
-# Maximum number of little messages; probably need not be changed.
-use constant MAX_NAG_MESSAGES => 6;
-
BEGIN {
# Array index names for variables.
_K_last_arrival_ => $i++,
_save_logfile_ => $i++,
_routput_string_ => $i++,
+ _input_stream_name_ => $i++,
};
} ## end BEGIN
}
sub Fault {
- my ($msg) = @_;
+ my ( $self, $msg ) = @_;
# This routine is called for errors that really should not occur
# except if there has been a bug introduced by a recent program change.
my ( $package2, $filename2, $line2, $subroutine2 ) = caller(2);
my $pkg = __PACKAGE__;
+ # Catch potential error of Fault not called as a method
+ my $input_stream_name;
+ if ( !ref($self) ) {
+ $input_stream_name = "(UNKNOWN)";
+ $msg = "Fault not called as a method - please fix\n";
+ if ( $self && length($self) < LONG_MESSAGE ) { $msg .= $self }
+ $self = undef;
+ }
+ else {
+ $input_stream_name = $self->[_input_stream_name_];
+ }
+
Die(<<EOM);
==============================================================================
While operating on input stream with name: '$input_stream_name'
# '$line_sink_object' is a SCALAR ref which receives the lines.
my $ref = ref($line_sink_object);
if ( !$ref ) {
- Fault("FileWriter expects line_sink_object to be a ref\n");
+ $self->Fault("FileWriter expects line_sink_object to be a ref\n");
}
elsif ( $ref eq 'SCALAR' ) {
$self->[_routput_string_] = $line_sink_object;
else {
my $str = $ref;
if ( length($str) > 63 ) { $str = substr( $str, 0, 60 ) . '...' }
- Fault(<<EOM);
+ $self->Fault(<<EOM);
FileWriter expects 'line_sink_object' to be ref to SCALAR but it is ref to:
$str
EOM
}
- # save input stream name for local error messages
- $input_stream_name = EMPTY_STRING;
+ my $input_stream_name = EMPTY_STRING;
if ($logger_object) {
$input_stream_name = $logger_object->get_input_stream_name();
}
+ $self->[_input_stream_name_] = $input_stream_name;
bless $self, $class;
return $self;
}
my $msg = <<EOM;
-While operating on input stream with name: '$input_stream_name'
Lines have arrived out of order in sub 'write_code_line'
as detected by token index K=$K arriving after index K=$K_prev in the following line:
$str
EOM
# Always die during development, this needs to be fixed
- if (DEVEL_MODE) { Fault($msg) }
+ if (DEVEL_MODE) { $self->Fault($msg) }
# Otherwise warn if string is not empty (added for b1378)
$self->warning($msg) if ( length($str) );