<commit_before>package Pakket::Utils;
# ABSTRACT: Utilities for Pakket

use strict;
use warnings;
use version 0.77;

use Exporter qw< import >;
use JSON::MaybeXS;

our @EXPORT_OK = qw<
    is_writeable
    generate_env_vars
    canonical_package_name
    encode_json_canonical
    encode_json_pretty
>;

sub is_writeable {
    my $path = shift; # Path::Tiny objects

    while ( !$path->is_rootdir ) {
        $path->exists and return -w $path;
        $path = $path->parent;
    }

    return -w $path;
}

sub generate_env_vars {
    my ( $build_dir, $prefix, $opts ) = @_;
    my $lib_path       = generate_lib_path($prefix);
    my $bin_path       = generate_bin_path($prefix);
    my $pkgconfig_path = generate_pkgconfig_path($prefix);

    my $inc = $opts->{'inc'} || '';

    my @perl5lib = (
        $prefix->child(qw<lib perl5>)->absolute->stringify,
        $inc,
        $build_dir,
    );

    my %perl_opts = (
        'PERL5LIB'                  => join( ':', $inc, @perl5lib ),
        'PERL_LOCAL_LIB_ROOT'       => '',
        'PERL5_CPAN_IS_RUNNING'     => 1,
        'PERL5_CPANM_IS_RUNNING'    => 1,
        'PERL5_CPANPLUS_IS_RUNNING' => 1,
        'PERL_MM_USE_DEFAULT'       => 1,
        'PERL_MB_OPT'               => '',
        'PERL_MM_OPT'               => '',
    );

    return (
        'CPATH'           => $prefix->child('include')->stringify,
        'PKG_CONFIG_PATH' => $pkgconfig_path,
        'LD_LIBRARY_PATH' => $lib_path,
        'LIBRARY_PATH'    => $lib_path,
        'PATH'            => $bin_path,
        %perl_opts,
    );
}

sub generate_lib_path {
    my $prefix = shift;

    my $lib_path = $prefix->child('lib')->absolute->stringify;<commit_msg>remove duplicated @inc in PERL5LIB<commit_after>package Pakket::Utils;
# ABSTRACT: Utilities for Pakket

use strict;
use warnings;
use version 0.77;

use Exporter qw< import >;
use JSON::MaybeXS;

our @EXPORT_OK = qw<
    is_writeable
    generate_env_vars
    canonical_package_name
    encode_json_canonical
    encode_json_pretty
>;

sub is_writeable {
    my $path = shift; # Path::Tiny objects

    while ( !$path->is_rootdir ) {
        $path->exists and return -w $path;
        $path = $path->parent;
    }

    return -w $path;
}

sub generate_env_vars {
    my ( $build_dir, $prefix, $opts ) = @_;
    my $lib_path       = generate_lib_path($prefix);
    my $bin_path       = generate_bin_path($prefix);
    my $pkgconfig_path = generate_pkgconfig_path($prefix);

    my $inc = $opts->{'inc'} || '';

    my @perl5lib = (
        $prefix->child(qw<lib perl5>)->absolute->stringify,
        $inc,
        $build_dir,
    );

    my %perl_opts = (
        'PERL5LIB'                  => join( ':', @perl5lib ),
        'PERL_LOCAL_LIB_ROOT'       => '',
        'PERL5_CPAN_IS_RUNNING'     => 1,
        'PERL5_CPANM_IS_RUNNING'    => 1,
        'PERL5_CPANPLUS_IS_RUNNING' => 1,
        'PERL_MM_USE_DEFAULT'       => 1,
        'PERL_MB_OPT'               => '',
        'PERL_MM_OPT'               => '',
    );

    return (
        'CPATH'           => $prefix->child('include')->stringify,
        'PKG_CONFIG_PATH' => $pkgconfig_path,
        'LD_LIBRARY_PATH' => $lib_path,
        'LIBRARY_PATH'    => $lib_path,
        'PATH'            => $bin_path,
        %perl_opts,
    );
}

sub generate_lib_path {
    my $prefix = shift;

    my $lib_path = $prefix->child('lib')->absolute->stringify;
{'fraction_non_alphanumeric': 0.14059289697681243, 'fraction_numerical': 0.008511887290871734, 'mean_word_length': 2.2150943396226417, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 59, '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': '5588465', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1198, 'n_words': 216}