<commit_before>package Mongo::Database;

use Mouse;

has _connection => (
    is       => 'ro',
    isa      => 'Mongo::Connection',
    required => 1,
    handles  => [qw/query find_one insert/],
);

has name => (
    is       => 'ro',
    isa      => 'Str',
    required => 1,
);

around qw/query find_one insert/ => sub {
    my ($next, $self, $ns, @args) = @_;
    return $self->$next($self->_query_ns($ns), @args);
};

sub _query_ns {
    my ($self, $ns) = @_;
    my $name = $self->name;
    return qq{${name}.${ns}};
}
<commit_msg>Add a convenience method to run commands on a database.<commit_after>package Mongo::Database;

use Mouse;

has _connection => (
    is       => 'ro',
    isa      => 'Mongo::Connection',
    required => 1,
    handles  => [qw/query find_one insert/],
);

has name => (
    is       => 'ro',
    isa      => 'Str',
    required => 1,
);

around qw/query find_one insert/ => sub {
    my ($next, $self, $ns, @args) = @_;
    return $self->$next($self->_query_ns($ns), @args);
};

sub _query_ns {
    my ($self, $ns) = @_;
    my $name = $self->name;
    return qq{${name}.${ns}};
}

sub run_command {
    my ($self, $command) = @_;
    my $obj = $self->find_one('$cmd', $command);
    return $obj if $obj->{ok};
    confess $obj->{errmsg};
}

{'fraction_non_alphanumeric': 0.20422535211267606, 'fraction_numerical': 0.003129890453834116, 'mean_word_length': 2.562674094707521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '3354881', 'n_tokens_mistral': 482, 'n_tokens_neox': 474, 'n_words': 118}