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

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

# Modules.
use Readonly;

# Constants.
Readonly::Array our @EXPORT_OK => qw(err_bt_pretty err_bt_pretty_rev err_line
	err_line_all err_print err_print_var);
Readonly::Scalar our $EMPTY_STR => q{};
Readonly::Scalar our $SPACE => q{ };

# Version.
our $VERSION = 0.21;

# Pretty print of backtrace.
sub err_bt_pretty {
	my @errors = @_;
	my @ret;
	my $l_ar = _lenghts(@errors);
	foreach my $error_hr (@errors) {
		push @ret, _bt_pretty_one($error_hr, $l_ar);
	}
	return wantarray ? @ret : (join "\n", @ret)."\n";
}

# Reverse pretty print of backtrace.
sub err_bt_pretty_rev {
	my @errors = @_;
	my @ret;
	my $l_ar = _lenghts(@errors);
	foreach my $error_hr (reverse @errors) {
		push @ret, _bt_pretty_one($error_hr, $l_ar);
	}
	return wantarray ? @ret : (join "\n", @ret)."\n";
}

# Pretty print line error.
sub err_line {
	my @errors = @_;
	return _err_line($errors[-1]);
}

# Pretty print with errors each on one line.
sub err_line_all {
	my @errors = @_;
	my $ret;
	foreach my $error_hr (@errors) {
		$ret .= _err_line($error_hr);
	}
	return $ret;
}

# Print error.
sub err_print {
	my @errors = @_;
	my $class = _err_class($errors[-1]);
	return $class.$errors[-1]->{'msg'}->[0];
}

# Print error with all variables.
sub err_print_var {
	my @errors = @_;
	my @msg = @{$errors[0]->{'msg'}};
	my $class = _err_class($errors[-1]);
	my @ret = ($class.(shift @msg));
	push @ret, _err_variables(@msg);
	return wantarray ? @ret : (join "\n", @ret)."\n";
}

# Pretty print one error backtrace helper.
sub _bt_pretty_one {
	my ($error_hr, $l_ar) = @_;
	my @msg = @{$error_hr->{'msg'}};
	my @ret = ('ERROR: '.(shift @msg));
	push @ret, _err_variables(@msg);
	foreach my $i (0 .. $#{$error_hr->{'stack'}}) {
		my $st = $error_hr->{'stack'}->[$i];
		my $ret = $st->{'class'};
		$ret .=  $SPACE x ($l_ar->[0] - length $st->{'class'});
		$ret .=  $st->{'sub'};
		$ret .=  $SPACE x ($l_ar->[1] - length $st->{'sub'});
		$ret .=  $st->{'prog'};
		$ret .=  $SPACE x ($l_ar->[2] - length $st->{'prog'});
		$ret .=  $st->{'line'};
		push @ret, $ret;<commit_msg>Fix last error message.<commit_after>package Error::Pure::Output::Text;

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

# Modules.
use Readonly;

# Constants.
Readonly::Array our @EXPORT_OK => qw(err_bt_pretty err_bt_pretty_rev err_line
	err_line_all err_print err_print_var);
Readonly::Scalar our $EMPTY_STR => q{};
Readonly::Scalar our $SPACE => q{ };

# Version.
our $VERSION = 0.21;

# Pretty print of backtrace.
sub err_bt_pretty {
	my @errors = @_;
	my @ret;
	my $l_ar = _lenghts(@errors);
	foreach my $error_hr (@errors) {
		push @ret, _bt_pretty_one($error_hr, $l_ar);
	}
	return wantarray ? @ret : (join "\n", @ret)."\n";
}

# Reverse pretty print of backtrace.
sub err_bt_pretty_rev {
	my @errors = @_;
	my @ret;
	my $l_ar = _lenghts(@errors);
	foreach my $error_hr (reverse @errors) {
		push @ret, _bt_pretty_one($error_hr, $l_ar);
	}
	return wantarray ? @ret : (join "\n", @ret)."\n";
}

# Pretty print line error.
sub err_line {
	my @errors = @_;
	return _err_line($errors[-1]);
}

# Pretty print with errors each on one line.
sub err_line_all {
	my @errors = @_;
	my $ret;
	foreach my $error_hr (@errors) {
		$ret .= _err_line($error_hr);
	}
	return $ret;
}

# Print error.
sub err_print {
	my @errors = @_;
	my $class = _err_class($errors[-1]);
	return $class.$errors[-1]->{'msg'}->[0];
}

# Print error with all variables.
sub err_print_var {
	my @errors = @_;
	my @msg = @{$errors[-1]->{'msg'}};
	my $class = _err_class($errors[-1]);
	my @ret = ($class.(shift @msg));
	push @ret, _err_variables(@msg);
	return wantarray ? @ret : (join "\n", @ret)."\n";
}

# Pretty print one error backtrace helper.
sub _bt_pretty_one {
	my ($error_hr, $l_ar) = @_;
	my @msg = @{$error_hr->{'msg'}};
	my @ret = ('ERROR: '.(shift @msg));
	push @ret, _err_variables(@msg);
	foreach my $i (0 .. $#{$error_hr->{'stack'}}) {
		my $st = $error_hr->{'stack'}->[$i];
		my $ret = $st->{'class'};
		$ret .=  $SPACE x ($l_ar->[0] - length $st->{'class'});
		$ret .=  $st->{'sub'};
		$ret .=  $SPACE x ($l_ar->[1] - length $st->{'sub'});
		$ret .=  $st->{'prog'};
		$ret .=  $SPACE x ($l_ar->[2] - length $st->{'prog'});
		$ret .=  $st->{'line'};
		push @ret, $ret;
{'fraction_non_alphanumeric': 0.21327781633125145, 'fraction_numerical': 0.006014341892204488, 'mean_word_length': 3.9930715935334873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, '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': '1096918', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1780, 'n_words': 446}