<commit_before>Perl6-Control-Bail
========

Control::Bail:: Perl 6 module for deferred error cleanup

## Purpose

The Control::Bail module allows nested allocations of resources to be
released in an orderly fashion, without repeating yourself, with no deep
block nesting and with deallocation code placed next to the corresponding
allocation code.

## Status

Brand spanking new.  Let the bikeshedding commence.  Also, uses a lot
of metamodel/internal stuff that is not necessarily nailed down by
specification.

## Idioms

    # This DWYW.  No need to test $skel or $thing to see whether or
    # not they were allocated, works in reverse order of bail statements,
    # and no bail statements get run when successful.
    sub make_thing {
        my $skel = make_skeleton();
        $skel or die "Could not make skeleton";
        bail { destroy_skeleton($skel); }

        my $thing = make_skin($skel);
        $thing or die "Could not make skin";
        bail { destroy_skin($thing); }

        Bool.pick or die("Unpredicable failure");
        $thing;
    }

    # In the following code:
    # If there was a touchdown there is cheering
    # ...then...
    # The Receiver gets an icepack, but only if he was tackled.
    # ...then...
    # The Receiver always gets juice, unless the QB was sacked.
    # ...then...
    # The QB always gets taunted, unless there was a touchdown.
    # ...then...
    # If there was no touchdown, the failure is thrown.
    use Control::Bail;
    sub towlboy {
        bail { say "Taunt the QB" }
        Bool.pick or die "sacked!";
        trail { say "Bring Receiver juice" }
        bail { say "Bring Receiver icepack" }
        Bool.pick or die "tackled!";
        say "touchdown!";
    }
    towlboy();<commit_msg>Consult md cheatsheet, turn on highlighting, AlexDaniel++<commit_after>Perl6-Control-Bail
========

Control::Bail:: Perl 6 module for deferred error cleanup

## Purpose

The Control::Bail module allows nested allocations of resources to be
released in an orderly fashion, without repeating yourself, with no deep
block nesting and with deallocation code placed next to the corresponding
allocation code.

## Status

Brand spanking new.  Let the bikeshedding commence.  Also, uses a lot
of metamodel/internal stuff that is not necessarily nailed down by
specification.

## Idioms

```perl6
# This DWYW.  No need to test $skel or $thing to see whether or
# not they were allocated, works in reverse order of bail statements,
# and no bail statements get run when successful.
sub make_thing {
    my $skel = make_skeleton();
    $skel or die "Could not make skeleton";
    bail { destroy_skeleton($skel); }

    my $thing = make_skin($skel);
    $thing or die "Could not make skin";
    bail { destroy_skin($thing); }

    Bool.pick or die("Unpredicable failure");
    $thing;
}

# In the following code:
# If there was a touchdown there is cheering
# ...then...
# The Receiver gets an icepack, but only if he was tackled.
# ...then...
# The Receiver always gets juice, unless the QB was sacked.
# ...then...
# The QB always gets taunted, unless there was a touchdown.
# ...then...
# If there was no touchdown, the failure is thrown.
use Control::Bail;
sub towlboy {
    bail { say "Taunt the QB" }
    Bool.pick or die "sacked!";
    trail { say "Bring Receiver juice" }
    bail { say "Bring Receiver icepack" }
    Bool.pick or die "tackled!";
    say "touchdown!";
}
towlboy();
```
{'fraction_non_alphanumeric': 0.09595812736260541, 'fraction_numerical': 0.0014539110206455365, 'mean_word_length': 3.014002333722287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '278166', 'n_tokens_mistral': 1049, 'n_tokens_neox': 994, 'n_words': 440}