}
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__;
- my $input_stream_name = get_input_stream_name();
+ # Catch potential error of not being a method call
+ my $input_stream_name;
+ if ( !ref($self) ) {
+ $msg = "Fault not called as a method - please fix\n";
+ $input_stream_name = "(UNKNOWN)";
+ }
+ else {
+ $input_stream_name = $self->get_input_stream_name();
+ }
Die(<<EOM);
==============================================================================
} ## end sub warning
sub get_input_stream_name {
+
+ my $self = shift;
+
my $input_stream_name = EMPTY_STRING;
- my $logger_object = $tokenizer_self->[_logger_object_];
+ my $logger_object = $self->[_logger_object_];
if ($logger_object) {
$input_stream_name = $logger_object->get_input_stream_name();
}
sub complain {
- my $msg = shift;
+ my ( $self, $msg ) = @_;
- my $logger_object = $tokenizer_self->[_logger_object_];
+ my $logger_object = $self->[_logger_object_];
if ($logger_object) {
my $input_line_number = $tokenizer_self->[_last_line_number_];
$logger_object->complain( $msg, $input_line_number );
}
else {
- complain(
+ $self->complain(
"hit eof while in pod documentation (no =cut seen)\n\tthis can cause trouble with some pod utilities\n"
);
}
);
}
else {
- complain("Useless hash-bang after line 1\n");
+ $self->complain("Useless hash-bang after line 1\n");
}
}
# leading =head. In any case, this isn't good.
if ( $input_line =~ /^=cut\b/ ) {
if ( $self->[_saw_data_] || $self->[_saw_end_] ) {
- complain("=cut while not in pod ignored\n");
+ $self->complain("=cut while not in pod ignored\n");
$self->[_in_pod_] = 0;
$line_of_tokens->{_line_type} = 'POD_END';
}
sub split_pretoken {
- my ($numc) = @_;
+ my ( $self, $numc ) = @_;
# Split the leading $numc characters from the current token (at index=$i)
# which is pre-type 'w' and insert the remainder back into the pretoken
# Shouldn't get here
if (DEVEL_MODE) {
- Fault(<<EOM);
+ $self->Fault(<<EOM);
While working near line number $input_line_number, bad arg '$tok' passed to sub split_pretoken()
EOM
}
# Try to fix it by splitting the pretoken
if ( $i > 0
&& $rtokens->[ $i - 1 ] eq '^'
- && split_pretoken(1) )
+ && $self->split_pretoken(1) )
{
$identifier = substr( $identifier, 0, 3 );
$tok = $identifier;
# ref: camel 3 p 703.
if ( $last_last_nonblank_token eq 'do' ) {
- complain(
+ $self->complain(
"do SUBROUTINE is deprecated; consider & or -> notation\n"
);
}
# ','
if ( $last_nonblank_type eq ',' ) {
- complain("Repeated ','s \n");
+ $self->complain("Repeated ','s \n");
}
# Note that we have to check both token and type here because a
# Something like this is valid but strange:
# undef ^I;
- complain("The '^' seems unusual here\n");
+ $self->complain("The '^' seems unusual here\n");
}
}
}
$type = 'h';
if ( length($here_doc_target) > 80 ) {
my $truncated = substr( $here_doc_target, 0, 80 );
- complain("Long here-target: '$truncated' ...\n");
+ $self->complain("Long here-target: '$truncated' ...\n");
}
elsif ( !$here_doc_target ) {
warning(
unless ($here_quote_character);
}
elsif ( $here_doc_target !~ /^[A-Z_]\w+$/ ) {
- complain(
+ $self->complain(
"Unconventional here-target: '$here_doc_target'\n");
}
}
# shouldn't happen..arriving here implies an error in
# the logic in sub 'find_here_doc'
if (DEVEL_MODE) {
- Fault(<<EOM);
+ $self->Fault(<<EOM);
Program bug; didn't find here doc target
EOM
}
if ( length($here_doc_target) > 80 ) {
my $truncated = substr( $here_doc_target, 0, 80 );
- complain("Long here-target: '$truncated' ...\n");
+ $self->complain("Long here-target: '$truncated' ...\n");
}
elsif ( $here_doc_target !~ /^[A-Z_]\w+$/ ) {
- complain(
+ $self->complain(
"Unconventional here-target: '$here_doc_target'\n");
}
# shouldn't happen..arriving here implies an error in
# the logic in sub 'find_here_doc'
if (DEVEL_MODE) {
- Fault(<<EOM);
+ $self->Fault(<<EOM);
Program bug; didn't find here doc target
EOM
}
# '=>'
if ( $last_nonblank_type eq $tok ) {
- complain("Repeated '=>'s \n");
+ $self->complain("Repeated '=>'s \n");
}
# patch for operator_expected: note if we are in the list (use.t)
# shouldn't happen - we should always get a number
if (DEVEL_MODE) {
- Fault(<<EOM);
+ $self->Fault(<<EOM);
non-number beginning with digit--program bug
EOM
}
)
{
$type = 'n';
- if ( split_pretoken(1) ) {
+ if ( $self->split_pretoken(1) ) {
$type = 'x';
$tok = 'x';
}
# as a number, $type = 'n', and fixed downstream by the
# Formatter.
$type = 'n';
- if ( split_pretoken(1) ) {
+ if ( $self->split_pretoken(1) ) {
$type = 'x';
$tok = 'x';
}
#
elsif ( $last_nonblank_type eq 'C' ) {
if ( $tok !~ /::$/ ) {
- complain(<<EOM);
+ $self->complain(<<EOM);
Expecting operator after '$last_nonblank_token' but found bare word '$tok'
Maybe indirectet object notation?
EOM
# Must not be in multi-line quote
# and must not be in an equation
if ( !$in_quote
- && ( operator_expected( [ 'b', '=', 'b' ] ) == TERM ) )
+ && ( $self->operator_expected( [ 'b', '=', 'b' ] ) == TERM ) )
{
$self->[_in_pod_] = 1;
return;
if ( ( $type eq 'n' ) && ( $tok ne '0' ) ) {
if ( $last_nonblank_token eq 'eq' ) {
- complain("Should 'eq' be '==' here ?\n");
+ $self->complain("Should 'eq' be '==' here ?\n");
}
elsif ( $last_nonblank_token eq 'ne' ) {
- complain("Should 'ne' be '!=' here ?\n");
+ $self->complain("Should 'ne' be '!=' here ?\n");
}
}
if ( $test_tok eq '//' && $last_nonblank_type ne 'Z' ) {
# note that here $tok = '/' and the next tok and type is '/'
- $expecting = operator_expected( [ $prev_type, $tok, '/' ] );
+ $expecting =
+ $self->operator_expected( [ $prev_type, $tok, '/' ] );
# Patched for RT#101547, was 'unless ($expecting==OPERATOR)'
$combine_ok = 0 if ( $expecting == TERM );
if ( $pre_type eq 'w' ) {
$expecting =
- operator_expected( [ $prev_type, $tok, $next_type ] );
+ $self->operator_expected( [ $prev_type, $tok, $next_type ] );
my $is_last = $self->do_BAREWORD($is_END_or_DATA);
last if ($is_last);
}
#-----------------------------
elsif ( $pre_type eq 'd' ) {
$expecting =
- operator_expected( [ $prev_type, $tok, $next_type ] );
+ $self->operator_expected( [ $prev_type, $tok, $next_type ] );
$self->do_DIGITS();
}
my $code = $tokenization_code->{$tok};
if ($code) {
$expecting =
- operator_expected( [ $prev_type, $tok, $next_type ] );
+ $self->operator_expected(
+ [ $prev_type, $tok, $next_type ] );
$code->($self);
redo if $in_quote;
}
# Should not happen unless @{$rtoken_map} is corrupted
DEVEL_MODE
- && Fault(
+ && $self->Fault(
"number of characters is '$numc' but should be >0\n");
}
}
# Should not happen unless @{$rtoken_map} is corrupted
DEVEL_MODE
- && Fault(
+ && $self->Fault(
"Number of Characters is '$numc' but should be >0\n");
}
}
# Returns a parameter indicating what types of tokens can occur next
# Call format:
- # $op_expected = operator_expected( [ $prev_type, $tok, $next_type ] );
+ # $op_expected =
+ # $self->operator_expected( [ $prev_type, $tok, $next_type ] );
# where
# $prev_type is the type of the previous token (blank or not)
# $tok is the current token
# the 'operator_expected' value by a simple hash lookup. If there are
# exceptions, that is an indication that a new type is needed.
- my ($rarg) = @_;
+ my ( $self, $rarg ) = @_;
#-------------
# Table lookup
# For example, from RT#130344:
# use lib $FindBin::Bin . '/lib';
if ( $statement_type ne 'use' ) {
- complain(
+ $self->complain(
"operator in possible indirect object location not recommended\n"
);
}
# could be bug caused by older perltidy if
# followed by '('
if ( $input_line =~ m/\G\s*\(/gc ) {
- complain(
+ $self->complain(
"Caution: unknown word '$tok' in indirect object slot\n"
);
}
# shouldn't happen:
if (DEVEL_MODE) {
- Fault(<<EOM);
+ $self->Fault(<<EOM);
Program bug in scan_id: undefined type but scan_state=$id_scan_state
EOM
}
# shouldn't happen: bad call parameter
my $msg =
"Program bug detected: scan_complex_identifier received bad starting token = '$tok'\n";
- if (DEVEL_MODE) { Fault($msg) }
+ if (DEVEL_MODE) { $self->Fault($msg) }
if ( !$self->[_in_error_] ) {
warning($msg);
$self->[_in_error_] = 1;
# check for a valid starting state
if ( DEVEL_MODE && !$is_returnable_scan_state{$id_scan_state} ) {
- Fault(<<EOM);
+ $self->Fault(<<EOM);
Unexpected starting scan state in sub scan_complex_identifier: '$id_scan_state'
EOM
}
# unknown state - should not happen
else {
if (DEVEL_MODE) {
- Fault(<<EOM);
+ $self->Fault(<<EOM);
Unknown scan state in sub scan_complex_identifier: '$id_scan_state'
Scan state at sub entry was '$id_scan_state_begin'
EOM
# shouldn't happen - we shouldn't be here if operator is expected
else {
if (DEVEL_MODE) {
- Fault(<<EOM);
+ $self->Fault(<<EOM);
Bad call to find_angle_operator_termination
EOM
}
# If this happens, it may be necessary to split the pretoken.
if ($error) {
if (DEVEL_MODE) {
- Fault(<<EOM);
+ $self->Fault(<<EOM);
unexpected error condition returned by inverse_pretoken_map
EOM
}
# Look for bad starting characters; Shouldn't happen..
if ( $first_char !~ /[\d\.\+\-Ee]/ ) {
if (DEVEL_MODE) {
- Fault(<<EOM);
+ $self->Fault(<<EOM);
Program bug - scan_number given bad first character = '$first_char'
EOM
}