<commit_before>package UUIDB::Storage::Fileplex;

use v5.10;
use strict;
use warnings;

use Carp qw( carp croak );

use Moo;
use Digest::MD5     qw( md5_hex            );
use File::Path      qw( mkpath             );
use Types::Standard qw( Bool Maybe Ref Str );
use UUIDB::Util     qw( check_args         );

extends qw( UUIDB::Storage );

# TODO: POD

has path => (
    is => "rw",
    isa => Str,
);

# Can be used to introduce higher local variability in those sequences
# used for managing pathing.
#
# It is *highly* recommended to use the "propogate_uuid" setting in
# UUIDB::Document options when this is enabled, since otherwise the reverse
# association from hashed key to UUID is effectively impossible to determine.
has rehash_key => (
    is      => 'rw',
    isa     => Maybe[Bool, Ref[qw( CODE )]],
    default => sub { 0 },
);

sub BUILD {
    my ($self, %opts) = @_;
    # Remove any of those settings which are attribute specific.
    # Pass the remainder onto options.
    $self->set_options( %opts );
}

sub set_options ($%) {
    my ($self, %opts) = @_;
    # TODO: storage_options
    # path (location of the directory in which to build)
    # indexes => {
    #    field_name => sub { qw( which knows how to get the "name" value from a Document }
    # }
}

sub store_document ($$;%) {
}

sub get_document ($$$) {
}

sub exists ($$) {
}

sub delete ($$;$) {
}

sub standardize_key ($$) {
    my ($self, $key) = @_;
    # This also does an is_uuid_string check for us.
    $key = $self->SUPER::standardize_key( $key );
    if ( my $rehash = $self->rehash ) {
        if ( ref $rehash ) {
            # Run the coderef instead
            $key = $rehash->( $key );
        } else {
            # TODO: definable hash engine to use.
            $key = $self->rehash_algorithm( $key );
        }
    }
    return $key;
}

sub rehash_algorithm ($$) {
    my ($self, $key) = @_;
    return md5_hex( $key );
}

sub mkdir ($$) {
}

sub init_check ($) {
    my ($self) = @_;
    croak "Path not set" unless    $self->path;
    croak "Invalid path" unless -d $self->path;
    carp "Path not writable"
        unless -d $self->path
        and    -w $self->path
        and      !$self->readonly;
}

1;<commit_msg>Fileplex stubs (pay not attention to the diff behind the curtain)<commit_after>package UUIDB::Storage::Fileplex;

use v5.10;
use strict;
use warnings;

use Carp qw( carp croak );

use Moo;
use Digest::MD5     qw( md5_hex            );
use File::Path      qw( mkpath             );
use Types::Standard qw( Bool Maybe Ref Str );
use UUIDB::Util     qw( check_args         );

extends qw( UUIDB::Storage );

# TODO: POD

has path => (
    is => "rw",
    isa => Str,
);

# Can be used to introduce higher local variability in those sequences
# used for managing pathing.
#
# It is *highly* recommended to use the "propogate_uuid" setting in
# UUIDB::Document options when this is enabled, since otherwise the reverse
# association from hashed key to UUID is effectively impossible to determine.
has rehash_key => (
    is      => 'rw',
    isa     => Maybe[Bool, Ref[qw( CODE )]],
    default => sub { 0 },
);

# Should this be an array or a hash?  Or a map, of some kind?
has indices => (
    is      => 'rw',
    isa     => ArrayRef[Str],
    default => sub { [] },
);

sub BUILD {
    my ($self, %opts) = @_;
    # Remove any of those settings which are attribute specific.
    # Pass the remainder onto options.
    $self->set_options( %opts );
}

sub set_options ($%) {
    my ($self, %opts) = @_;
    # TODO: storage_options
    # path (location of the directory in which to build)
    # indexes => {
    #    field_name => sub { qw( which knows how to get the "name" value from a Document }
    # }
}

sub store_document ($$;%) {
}

sub get_document ($$$) {
}

sub exists ($$) {
}

sub delete ($$;$) {
}

sub standardize_key ($$) {
    my ($self, $key) = @_;
    # This also does an is_uuid_string check for us.
    $key = $self->SUPER::standardize_key( $key );
    if ( my $rehash = $self->rehash ) {
        if ( ref $rehash ) {
            # Run the coderef instead
            $key = $rehash->( $key );
        } else {
            # TODO: definable hash engine to use.
            $key = $self->rehash_algorithm( $key );
        }
    }
    return $key;
}

sub rehash_algorithm ($$) {
    my ($self, $key) = @_;
    return md5_hex( $key );
}

sub mkdir ($$) {
    # TODO: this
}

sub init_check ($) {
    my ($self) = @_;
    croak "Path not set" unless    $self->path;
    croak "Invalid path" unless -d $self->path;
    carp "Path not writable"
        unless -d $self->path
        and    -w $self->path
        and      !$self->readonly;
}

# Find an index entry
sub search_index ($$$) {
    my ($self, $index, $starts_with) = @_;
}

# Given an index entry, return the list of UUIDs it contains.
sub lookup_by_index ($$$) {
    my ($self, $index, $value) = @_;
}

1;
{'fraction_non_alphanumeric': 0.1402650356778797, 'fraction_numerical': 0.0032619775739041795, 'mean_word_length': 2.437981779957954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, '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': '3076468', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1650, 'n_words': 546}