### ----------------------------------------------------
### -- FINALIZER
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: t/01-basic.rakutest
### ----------------------------------------------------
use Test;

use FINALIZER <class-only>;

plan 1;

my @order;

sub dbiconnect($string) {
    LEAVE @order.push: "leaving $string";
    my $dbh = $string;
    FINALIZER.register: { @order.push: "leaving registered with $dbh" }
    $dbh
}

LEAVE @order.push: "leaving program";
{
    LEAVE @order.push: "leaving outer";
    {
        use FINALIZER;
        my $dbh = dbiconnect("frobnicate");
        @order.push: "doing stuff with $dbh";
    }
}

END is-deeply @order, [
  "leaving frobnicate",
  "doing stuff with frobnicate",
  "leaving registered with frobnicate",
  "leaving outer",
  "leaving program",
], 'Did all of the things happen in the correct order';

# vim: expandtab shiftwwidth=4


