<commit_before>#!/usr/bin/perl
package Marla::Site;

use strict;
use warnings;

use Carp;

require Exporter;

our @ISA     = qw(Exporter);
our @EXPORT  = qw();
our $VERSION = 1.00;

sub new {
    my $class = shift;
    my $self = {
        routes => [],
        views => {},
        models => {},
        config => {}
    };

    return bless($self, $class);
}

sub serve {
    my $self = shift;
    my $request = shift;

    my $best_route_score = 0;
    my $best_route;

    foreach my $route_pred (@{$self->{routes}}) {
        my ($route, $route_score) = $route_pred->($request);

        next if not defined $route;

        if (not defined $route_score or $route_score > $best_route_score) {
            $best_route_score = $route_score;
            $best_route = $route;
        }
        # Short-circuit for routes without scores
        last if not defined $route_score;
    }

    $best_route->($self) if $best_route or croak "Unhandled request: $request";
}

sub get_view {
    my $self = shift;

    my $name = shift;
    my $view = $self->{views}->{$name} or croak "No view found for name: '$name'";
    return $view;
}

sub set_view {
    my $self = shift;

    my $name = shift;
    $self->{views}->{$name} = shift;
}

sub get_model {
    my $self = shift;

    my $name = shift;
    my $model = $self->{models}->{$name} or croak "No model found for name: '$name'";
    return $model;
}
<commit_msg>Automatically call views and models when retrieved<commit_after>#!/usr/bin/perl
package Marla::Site;

use strict;
use warnings;

use Carp;

require Exporter;

our @ISA     = qw(Exporter);
our @EXPORT  = qw();
our $VERSION = 1.00;

sub new {
    my $class = shift;
    my $self = {
        routes => [],
        views => {},
        models => {},
        config => {}
    };

    return bless($self, $class);
}

sub serve {
    my $self = shift;
    my $request = shift;

    my $best_route_score = 0;
    my $best_route;

    foreach my $route_pred (@{$self->{routes}}) {
        my ($route, $route_score) = $route_pred->($request);

        next if not defined $route;

        if (not defined $route_score or $route_score > $best_route_score) {
            $best_route_score = $route_score;
            $best_route = $route;
        }
        # Short-circuit for routes without scores
        last if not defined $route_score;
    }

    $best_route->($self) if $best_route or croak "Unhandled request: $request";
}

sub get_view {
    my $self = shift;

    my $name = shift;
    my $view = $self->{views}->{$name} or croak "No view found for name: '$name'";
    return $view->(@_);
}

sub set_view {
    my $self = shift;

    my $name = shift;
    $self->{views}->{$name} = shift;
}

sub get_model {
    my $self = shift;

    my $name = shift;
    my $model = $self->{models}->{$name} or croak "No model found for name: '$name'";
    return $model->(@_);
}

{'fraction_non_alphanumeric': 0.1529370872436566, 'fraction_numerical': 0.002780674313521029, 'mean_word_length': 2.422116527942925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '2710086', 'n_tokens_mistral': 1011, 'n_tokens_neox': 977, 'n_words': 288}