<commit_before>#------------------------------------------------------------------------------
package Error::Pure::Output::Text;
#------------------------------------------------------------------------------

# Pragmas.
use strict;

# Modules.
use Exporter;

# Export.
our @EXPORT = qw(err_bt_pretty err_bt_simple err_pretty);

# Inheritance.
our @ISA = qw(Exporter);

# Version.
our $VERSION = 0.03;

#------------------------------------------------------------------------------
sub err_bt_pretty($) {
#------------------------------------------------------------------------------
# Pretty print of backtrace.

	my $errors = shift;
	my $ret;
	my $l = _lenghts($errors);
	foreach my $error (@{$errors}) {
		my $tmp = shift @{$error->{'msg'}};
		$ret .= "ERROR: ".$tmp."\n";
		while (my ($f, $t) = (shift @{$error->{'msg'}}, 
			shift @{$error->{'msg'}})) {

			last unless defined $f;
			$ret .= $f.': '.$t."\n";
		}
		for (my $i = 0; $i <= $#{$error->{'stack'}}; $i++) {
			my $st = $error->{'stack'}->[$i];
			$ret .= $st->{'class'};
			$ret .=  ' ' x ($l->[0] - length $st->{'class'});
			$ret .=  $st->{'sub'};
			$ret .=  ' ' x ($l->[1] - length $st->{'sub'});
			$ret .=  $st->{'prog'};
			$ret .=  ' ' x ($l->[2] - length $st->{'prog'});
			$ret .=  $st->{'line'};
			$ret .= "\n";
		}
	}
	return $ret;
}

#------------------------------------------------------------------------------
sub err_bt_simple($) {
#------------------------------------------------------------------------------
# Line print of backtrace.

	my $errors = shift;
	my $ret;
	foreach my $error (@{$errors}) {
		$ret .= _err_line($error);
	}
	return $ret;
}

#------------------------------------------------------------------------------
sub err_pretty($) {
#------------------------------------------------------------------------------
# Pretty print line error.

	my $errors = shift;
	return _err_line($errors->[-1]);
}

#------------------------------------------------------------------------------
# Private functions.
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
sub _lenghts($) {
#------------------------------------------------------------------------------
# Gets length for errors.

	my $errors = shift;
	my $l = [0, 0, 0];
	foreach my $error (@{$errors}) {
		foreach my $st (@{$error->{'stack'}}) {
			if (length $st->{'class'} > $l->[0]) {
				$l->[0] = length $st->{'class'};
			}
			if (length $st->{'sub'} > $l->[1]) {
				$l->[1] = length $st->{'sub'};
			}
			if (length $st->{'prog'} > $l->[2]) {
				$l->[2] = length $st->{'prog'};
			}
		}
	}
	$l->[0] += 2;
	$l->[1] += 2;
	$l->[2] += 2;
	return $l;
}

#------------------------------------------------------------------------------
sub _err_line($) {
#------------------------------------------------------------------------------
# Pretty print line error.

	my $error = shift;
	my $stack = $error->{'stack'};
	my $msg = $error->{'msg'};
	my $prog = $stack->[0]->{'prog'};
	$prog =~ s/^\.\///g;
	return "#Error [$prog:$stack->[0]->{'line'}] $msg->[0]\n";
}

1;
<commit_msg>Remove prototypes. Rewrite postfix if to normal. Rewrite Exporter.<commit_after>#------------------------------------------------------------------------------
package Error::Pure::Output::Text;
#------------------------------------------------------------------------------

# Pragmas.
use base qw(Exporter);
use strict;
use warnings;

# Export.
our @EXPORT = qw(err_bt_pretty err_bt_simple err_pretty);

# Inheritance.
our @ISA = qw(Exporter);

# Version.
our $VERSION = 0.01;

#------------------------------------------------------------------------------
sub err_bt_pretty {
#------------------------------------------------------------------------------
# Pretty print of backtrace.

	my $errors = shift;
	my $ret;
	my $l = _lenghts($errors);
	foreach my $error (@{$errors}) {
		my $tmp = shift @{$error->{'msg'}};
		$ret .= "ERROR: ".$tmp."\n";
		while (my ($f, $t) = (shift @{$error->{'msg'}}, 
			shift @{$error->{'msg'}})) {

			if (! defined $f) {
				last;
			}
			$ret .= $f.': '.$t."\n";
		}
		for (my $i = 0; $i <= $#{$error->{'stack'}}; $i++) {
			my $st = $error->{'stack'}->[$i];
			$ret .= $st->{'class'};
			$ret .=  ' ' x ($l->[0] - length $st->{'class'});
			$ret .=  $st->{'sub'};
			$ret .=  ' ' x ($l->[1] - length $st->{'sub'});
			$ret .=  $st->{'prog'};
			$ret .=  ' ' x ($l->[2] - length $st->{'prog'});
			$ret .=  $st->{'line'};
			$ret .= "\n";
		}
	}
	return $ret;
}

#------------------------------------------------------------------------------
sub err_bt_simple {
#------------------------------------------------------------------------------
# Line print of backtrace.

	my $errors = shift;
	my $ret;
	foreach my $error (@{$errors}) {
		$ret .= _err_line($error);
	}
	return $ret;
}

#------------------------------------------------------------------------------
sub err_pretty {
#------------------------------------------------------------------------------
# Pretty print line error.

	my $errors = shift;
	return _err_line($errors->[-1]);
}

#------------------------------------------------------------------------------
# Private functions.
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
sub _lenghts {
#------------------------------------------------------------------------------
# Gets length for errors.

	my $errors = shift;
	my $l = [0, 0, 0];
	foreach my $error (@{$errors}) {
		foreach my $st (@{$error->{'stack'}}) {
			if (length $st->{'class'} > $l->[0]) {
				$l->[0] = length $st->{'class'};
			}
			if (length $st->{'sub'} > $l->[1]) {
				$l->[1] = length $st->{'sub'};
			}
			if (length $st->{'prog'} > $l->[2]) {
				$l->[2] = length $st->{'prog'};
			}
		}
	}
	$l->[0] += 2;
	$l->[1] += 2;
	$l->[2] += 2;
	return $l;
}

#------------------------------------------------------------------------------
sub _err_line {
#------------------------------------------------------------------------------
# Pretty print line error.

	my $error = shift;
	my $stack = $error->{'stack'};
	my $msg = $error->{'msg'};
	my $prog = $stack->[0]->{'prog'};
	$prog =~ s/^\.\///g;
	return "#Error [$prog:$stack->[0]->{'line'}] $msg->[0]\n";
}

1;

{'fraction_non_alphanumeric': 0.5320956576463184, 'fraction_numerical': 0.008495909376966647, 'mean_word_length': 0.9505983430500153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1733344', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1881, 'n_words': 426}