<commit_before>use v6;
use File::Presence;
use Nightscape::Config::Utils;
use Nightscape::Types;
use TXN;
use TXN::Parser::Types;
use TXN::Remarshal;
use X::Nightscape;

class Nightscape::Config::Ledger::FromFile {...}
class Nightscape::Config::Ledger::FromPkg {...}

# Nightscape::Config::Ledger {{{

class Nightscape::Config::Ledger
{
    # --- method new {{{

    multi method new(
        *%opts (
            Str:D :code($)! where *.so,
            Str:D :file($)! where *.so,
            Int :date-local-offset($),
            Str :txn-dir($)
        )
    )
    {
        Nightscape::Config::Ledger::FromFile.bless(|%opts);
    }

    multi method new(
        *%opts (
            Str:D :pkgname($)! where *.so,
            Str:D :pkgver($)! where *.so,
            Int :pkgrel($)
        )
    )
    {
        Nightscape::Config::Ledger::FromPkg.bless(|%opts);
    }

    multi method new(*%)
    {
        die X::Nightscape::Config::Ledger::Malformed.new;
    }

    # --- end method new }}}
}

# end Nightscape::Config::Ledger }}}
# Nightscape::Config::Ledger::FromFile {{{

class Nightscape::Config::Ledger::FromFile is Nightscape::Config::Ledger
{
    # --- class attributes {{{

    has VarNameBare:D $.code is required;
    has AbsolutePath:D $.file is required;
    has Int $.date-local-offset;
    has AbsolutePath $.txn-dir;

    # --- end class attributes }}}

    # --- submethod BUILD {{{

    submethod BUILD(
        Str:D :$code! where *.so,
        Str:D :$file! where *.so,
        Int :$date-local-offset,
        Str :$txn-dir
    )
    {
        $!code = gen-var-name-bare($code);
        $!file = resolve-path($file);
        $!date-local-offset = $date-local-offset if $date-local-offset.defined;
        $!txn-dir = resolve-path($txn-dir) if $txn-dir;
    }

    # --- end submethod BUILD }}}
    # --- method made {{{

    method made(
        ::?CLASS:D:
        *% (
            Int :$date-local-offset,
            Str :$txn-dir
        )
    ) returns Hash:D
    {
        my VarNameBare:D $pkgname = $.code;
        my Str:D $pkgver = '0.0.1';
        my UInt:D $pkgrel = 1;

        # settings passed as args override class attributes
        my %opts{Str:D};
        %opts<date-local-offset> = $.date-local-offset
            if $.date-local-offset.defined;
        %opts<date-local-offset> = $date-local-offset
            if $date-local-offset.defined;
        %opts<txn-dir> = $.txn-dir if $.txn-dir;
        %opts<txn-dir> = resolve-path($txn-dir) if $txn-dir;

        mktxn(:$.file, :$pkgname, :$pkgver, :$pkgrel, |%opts);
    }

    # --- end method made }}}
}

# end Nightscape::Config::Ledger::FromFile }}}
# Nightscape::Config::Ledger::FromPkg {{{

class Nightscape::Config::Ledger::FromPkg is Nightscape::Config::Ledger
{
    # --- class attributes {{{

    has VarNameBare:D $.pkgname is required;
    has Version:D $.pkgver is required;<commit_msg>check for ledger file existence<commit_after>use v6;
use File::Presence;
use Nightscape::Config::Utils;
use Nightscape::Types;
use TXN;
use TXN::Parser::Types;
use TXN::Remarshal;
use X::Nightscape;

class Nightscape::Config::Ledger::FromFile {...}
class Nightscape::Config::Ledger::FromPkg {...}

# Nightscape::Config::Ledger {{{

class Nightscape::Config::Ledger
{
    # --- method new {{{

    multi method new(
        *%opts (
            Str:D :code($)! where *.so,
            Str:D :file($)! where *.so,
            Int :date-local-offset($),
            Str :txn-dir($)
        )
    )
    {
        Nightscape::Config::Ledger::FromFile.bless(|%opts);
    }

    multi method new(
        *%opts (
            Str:D :pkgname($)! where *.so,
            Str:D :pkgver($)! where *.so,
            Int :pkgrel($)
        )
    )
    {
        Nightscape::Config::Ledger::FromPkg.bless(|%opts);
    }

    multi method new(*%)
    {
        die X::Nightscape::Config::Ledger::Malformed.new;
    }

    # --- end method new }}}
}

# end Nightscape::Config::Ledger }}}
# Nightscape::Config::Ledger::FromFile {{{

class Nightscape::Config::Ledger::FromFile is Nightscape::Config::Ledger
{
    # --- class attributes {{{

    has VarNameBare:D $.code is required;
    has AbsolutePath:D $.file is required;
    has Int $.date-local-offset;
    has AbsolutePath $.txn-dir;

    # --- end class attributes }}}

    # --- submethod BUILD {{{

    submethod BUILD(
        Str:D :$code! where *.so,
        Str:D :$file! where *.so,
        Int :$date-local-offset,
        Str :$txn-dir
    )
    {
        $!code = gen-var-name-bare($code);
        $!file = resolve-path($file);
        $!date-local-offset = $date-local-offset if $date-local-offset.defined;
        $!txn-dir = resolve-path($txn-dir) if $txn-dir;
    }

    # --- end submethod BUILD }}}
    # --- method made {{{

    method made(
        ::?CLASS:D:
        *% (
            Int :$date-local-offset,
            Str :$txn-dir
        )
    ) returns Hash:D
    {
        die unless exists-readable-file($.file);

        my VarNameBare:D $pkgname = $.code;
        my Str:D $pkgver = '0.0.1';
        my UInt:D $pkgrel = 1;

        # settings passed as args override class attributes
        my %opts{Str:D};
        %opts<date-local-offset> = $.date-local-offset
            if $.date-local-offset.defined;
        %opts<date-local-offset> = $date-local-offset
            if $date-local-offset.defined;
        %opts<txn-dir> = $.txn-dir if $.txn-dir;
        %opts<txn-dir> = resolve-path($txn-dir) if $txn-dir;

        mktxn(:$.file, :$pkgname, :$pkgver, :$pkgrel, |%opts);
    }

    # --- end method made }}}
}

# end Nightscape::Config::Ledger::FromFile }}}
# Nightscape::Config::Ledger::FromPkg {{{

class Nightscape::Config::Ledger::FromPkg is Nightscape::Config::Ledger
{
    # --- class attributes {{{

    has VarNameBare:D $.pkgname is required;
    has Version:D $.pkgver is required;
{'fraction_non_alphanumeric': 0.17427597955706986, 'fraction_numerical': 0.0017035775127768314, 'mean_word_length': 2.2544345898004434, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3286860', 'n_tokens_mistral': 2083, 'n_tokens_neox': 2017, 'n_words': 404}