<commit_before>package App::KADR::Path::File;
# ABSTRACT: Path::Class::Dir for KADR, faster

use App::KADR::Path::Dir;
use Carp 'croak';
use common::sense;
use File::Spec::Memoized;

use parent 'Path::Class::File', 'App::KADR::Path::Entity';

use Class::XSAccessor
	getters => { basename => 'file' },
	false   => ['is_dir'];

my %cache;

sub dir_class() { 'App::KADR::Path::Dir' }

sub has_dir { defined $_[0]{dir} }

sub is_absolute {
	$_[0]->{is_absolute} //= $_[0]->SUPER::is_absolute;
}

sub is_hidden {
	$_[0]{file} =~ /^\./;
}

sub new {
	my $class = shift;
	my ($volume, $file_dirs, $base) = $class->_spec->splitpath(pop);

	# Dir
	my $dir
		= $file_dirs                        ? $class->dir_class->new(@_, $file_dirs)
		: @_ == 1 && ref $_[0] eq dir_class ? $_[0]
		: @_                                ? $class->dir_class->new(@_)
		:                                     ();

	# Check for cached file
	$cache{$dir || '.'}->{$base} //= do {
		my $self = $class->Path::Class::Entity::new;

		$self->{dir}  = $dir;
		$self->{file} = $base;

		$self;
	};
}

sub relative {
	my $self = shift;
	@_
		? $self->SUPER::relative(@_)
		: $self->{_relative}{$self->_spec->curdir} //= $self->SUPER::relative;
}

sub stringify {
	$_[0]->{_stringify} //= $_[0]->SUPER::stringify;
}

0x6B63;

=head1 DESCRIPTION<commit_msg>Reduce method call overhead of File->stringify<commit_after>package App::KADR::Path::File;
# ABSTRACT: Path::Class::Dir for KADR, faster

use App::KADR::Path::Dir;
use Carp 'croak';
use common::sense;
use File::Spec::Memoized;

use parent 'Path::Class::File', 'App::KADR::Path::Entity';

use Class::XSAccessor
	getters => { basename => 'file' },
	false   => ['is_dir'];

my %cache;

sub dir_class() { 'App::KADR::Path::Dir' }

sub has_dir { defined $_[0]{dir} }

sub is_absolute {
	$_[0]->{is_absolute} //= $_[0]->SUPER::is_absolute;
}

sub is_hidden {
	$_[0]{file} =~ /^\./;
}

sub new {
	my $class = shift;
	my ($volume, $file_dirs, $base) = $class->_spec->splitpath(pop);

	# Dir
	my $dir
		= $file_dirs                        ? $class->dir_class->new(@_, $file_dirs)
		: @_ == 1 && ref $_[0] eq dir_class ? $_[0]
		: @_                                ? $class->dir_class->new(@_)
		:                                     ();

	# Check for cached file
	$cache{$dir || '.'}->{$base} //= do {
		my $self = $class->Path::Class::Entity::new;

		$self->{dir}  = $dir;
		$self->{file} = $base;

		$self;
	};
}

sub relative {
	my $self = shift;
	@_
		? $self->SUPER::relative(@_)
		: $self->{_relative}{$self->_spec->curdir} //= $self->SUPER::relative;
}

sub stringify {
	$_[0]{stringify}
		//= defined $_[0]{dir}
		? $_[0]->_spec->catfile($_[0]{dir}->stringify, $_[0]{file})
		: $_[0]{file};
}

0x6B63;

=head1 DESCRIPTION
{'fraction_non_alphanumeric': 0.22851919561243145, 'fraction_numerical': 0.01170018281535649, 'mean_word_length': 3.108108108108108, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1042456', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1088, 'n_words': 200}