<commit_before># Copyright (C) 2008, <NAME>.

package Mojo::Template;

use strict;
use warnings;

use base 'Mojo::Base';

use constant DEBUG => $ENV{MOJO_TEMPLATE_DEBUG} || 0;

use Carp 'croak';
use IO::File;

__PACKAGE__->attr('code'           , chained => 1, default => sub {''  });
__PACKAGE__->attr('comment_mark'   , chained => 1, default => sub {'#' });
__PACKAGE__->attr('expression_mark', chained => 1, default => sub {'=' });
__PACKAGE__->attr('line_start'     , chained => 1, default => sub {'%' });
__PACKAGE__->attr('template'       , chained => 1, default => sub {''  });
__PACKAGE__->attr('tree'           , chained => 1, default => sub {[]  });
__PACKAGE__->attr('tag_start'      , chained => 1, default => sub {'<%'});
__PACKAGE__->attr('tag_end'        , chained => 1, default => sub {'%>'});

sub compile {
    my $self = shift;

    # Compile
    my @lines;
    for my $line (@{$self->tree}) {

        # New line
        push @lines, '';
        for (my $j = 0; $j < @{$line}; $j += 2) {
            my $type  = $line->[$j];
            my $value = $line->[$j + 1];

            # Need to fix line ending?
            my $newline = chomp $value;

            # Text
            if ($type eq 'text') {

                # Quote and fix line ending
                $value = quotemeta($value);
                $value .= '\n' if $newline;

                $lines[-1] .= "\$_MOJO .= \"" . $value . "\";";
            }

            # Code
            if ($type eq 'code') {
                $lines[-1] .= "$value;";
            }

            # Expression
            if ($type eq 'expr') {
                $lines[-1] .= "\$_MOJO .= $value;";
            }
        }
    }

    # Wrap
    $lines[0]   = q/sub { my $_MOJO = '';/ . $lines[0];
    $lines[-1] .= q/return $_MOJO; };/;

    $self->code(join "\n", @lines);
    return $self;
}

sub interpret {
    my $self = shift;

    # Shortcut
    my $code = $self->code;
    return undef unless $code;

    # Catch warnings
    local $SIG{__WARN__} = sub {
        my $error = shift;
        warn $self->_error($error);
    };

    # Prepare
    my $sub  = eval $code;
    return $self->_error($@) if $@;

    # Interpret
    my $result = eval { $sub->(@_) };
    return $self->_error($@) if $@;

    return $result;
}
<commit_msg>fixed empty template warning<commit_after># Copyright (C) 2008, <NAME>.

package Mojo::Template;

use strict;
use warnings;

use base 'Mojo::Base';

use constant DEBUG => $ENV{MOJO_TEMPLATE_DEBUG} || 0;

use Carp 'croak';
use IO::File;

__PACKAGE__->attr('code'           , chained => 1, default => sub {''  });
__PACKAGE__->attr('comment_mark'   , chained => 1, default => sub {'#' });
__PACKAGE__->attr('expression_mark', chained => 1, default => sub {'=' });
__PACKAGE__->attr('line_start'     , chained => 1, default => sub {'%' });
__PACKAGE__->attr('template'       , chained => 1, default => sub {''  });
__PACKAGE__->attr('tree'           , chained => 1, default => sub {[]  });
__PACKAGE__->attr('tag_start'      , chained => 1, default => sub {'<%'});
__PACKAGE__->attr('tag_end'        , chained => 1, default => sub {'%>'});

sub compile {
    my $self = shift;

    # Compile
    my @lines;
    for my $line (@{$self->tree}) {

        # New line
        push @lines, '';
        for (my $j = 0; $j < @{$line}; $j += 2) {
            my $type  = $line->[$j];
            my $value = $line->[$j + 1];

            # Need to fix line ending?
            my $newline = chomp $value;

            # Text
            if ($type eq 'text') {

                # Quote and fix line ending
                $value = quotemeta($value);
                $value .= '\n' if $newline;

                $lines[-1] .= "\$_MOJO .= \"" . $value . "\";";
            }

            # Code
            if ($type eq 'code') {
                $lines[-1] .= "$value;";
            }

            # Expression
            if ($type eq 'expr') {
                $lines[-1] .= "\$_MOJO .= $value;";
            }
        }
    }

    # Wrap
    $lines[0] ||= '';
    $lines[0]   = q/sub { my $_MOJO = '';/ . $lines[0];
    $lines[-1] .= q/return $_MOJO; };/;

    $self->code(join "\n", @lines);
    return $self;
}

sub interpret {
    my $self = shift;

    # Shortcut
    my $code = $self->code;
    return undef unless $code;

    # Catch warnings
    local $SIG{__WARN__} = sub {
        my $error = shift;
        warn $self->_error($error);
    };

    # Prepare
    my $sub  = eval $code;
    return $self->_error($@) if $@;

    # Interpret
    my $result = eval { $sub->(@_) };
    return $self->_error($@) if $@;

    return $result;
}

{'fraction_non_alphanumeric': 0.19524324324324324, 'fraction_numerical': 0.00972972972972973, 'mean_word_length': 1.839779005524862, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 75, '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': '4399230', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1527, 'n_words': 390}