<commit_before>package CSG::Storage::Slots;

use Modern::Perl;
use Moose;
use Moose::Util::TypeConstraints;
use File::Spec;
use Digest::SHA qw(sha1_hex);
use overload '""' => sub {shift->to_string};

use CSG::Storage::Slots::DB;
use CSG::Storage::Slots::Exceptions;
use CSG::Types;

our $VERSION = "0.1";

subtype 'ValidProject',
  as 'Str',
  where {
    my $schema = CSG::Storage::Slots::DB->new();
    defined $schema->resultset('Project')->find({name => $_});
  },
  message {"Project name, $_, is not a valid project"};

has 'name'    => (is => 'ro', isa => 'Str',           required => 1);
has 'project' => (is => 'ro', isa => 'ValidProject',  required => 1);
has 'size'    => (is => 'rw', isa => 'ValidSlotSize', required => 1, trigger => \&_set_size);

has 'sha1' => (is => 'ro', isa => 'Str', lazy => 1, builder => '_build_sha1');
has 'path' => (is => 'ro', isa => 'Str', lazy => 1, builder => '_build_path');

has '_record' => (is => 'rw', isa => __PACKAGE__ . '::DB::Schema::Result::Slot', predicate => 'has_record');

around [qw(name project size path sha1)] => sub {
  my $orig = shift;
  my $self = shift;

  unless ($self->has_record) {
    my $schema  = CSG::Storage::Slots::DB->new();
    my $project = $schema->resultset('Project')->find({name => $self->{project}});
    my $pool    = $project->next_available_pool($self->{size});

    unless ($pool) {
      CSG::Storage::Slots::Exceptions::Pools::NoPoolAvailable->throw();
    }

    my $record  = $schema->resultset('Slot')->find_or_create(
      {
        name    => $self->{name},
        size    => $self->{size},
        sha1    => sha1_hex($self->{name}),
        pool_id => $pool->id,
      }
    );
<commit_msg>just cleanup, no changes<commit_after>package CSG::Storage::Slots;

use Modern::Perl;
use Moose;
use Moose::Util::TypeConstraints;
use File::Spec;
use Digest::SHA qw(sha1_hex);
use overload '""' => sub {shift->to_string};

use CSG::Storage::Slots::DB;
use CSG::Storage::Slots::Exceptions;
use CSG::Types;

our $VERSION = "0.1";

## no tidy
subtype 'ValidProject',
  as 'Str',
  where {
    my $schema = CSG::Storage::Slots::DB->new();
    defined $schema->resultset('Project')->find({name => $_});
  },
  message { "Project name, $_, is not a valid project" };
## use tidy

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

has 'project' => (
  is       => 'ro',
  isa      => 'ValidProject',
  required => 1
);

has 'size' => (
  is       => 'rw',
  isa      => 'ValidSlotSize',
  required => 1,
  trigger  => \&_set_size
);

has 'sha1' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_sha1'
);

has 'path' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_path'
);

has '_record' => (
  is        => 'rw',
  isa       => __PACKAGE__ . '::DB::Schema::Result::Slot',
  predicate => 'has_record'
);

around [qw(name project size path sha1)] => sub {
  my $orig = shift;
  my $self = shift;

  unless ($self->has_record) {
    my $schema  = CSG::Storage::Slots::DB->new();
    my $project = $schema->resultset('Project')->find({name => $self->{project}});
    my $pool    = $project->next_available_pool($self->{size});

    unless ($pool) {
      CSG::Storage::Slots::Exceptions::Pools::NoPoolAvailable->throw();
    }

    my $record = $schema->resultset('Slot')->find_or_create(
      {
        name    => $self->{name},
        size    => $self->{size},
        sha1    => sha1_hex($self->{name}),
        pool_id => $pool->id,
      }
    );

{'fraction_non_alphanumeric': 0.21821793416572077, 'fraction_numerical': 0.0073779795686719635, 'mean_word_length': 3.2165071770334928, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 109, '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': '4097598', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1261, 'n_words': 283}