use v5.12.0;
use warnings;
use B::Deparse;
use PadWalker qw/closed_over set_closed_over/;
use Data::Dump qw/pp/;

goto EX_2;

my $first = "Rolf";                     # closure
my $c_ref = sub { " ... WHERE First = $first ..." };

say $c_ref->();

my $h_vars = closed_over($c_ref);
pp $h_vars;

my %ph = map { $_ => \'?' } keys %$h_vars;
pp \%ph;

set_closed_over($c_ref, \%ph);
say my $query = $c_ref->();

set_closed_over($c_ref, $h_vars);
say $c_ref->();


EX_2:
{
    my ($first0,$last0) = qw/Rolf Lanx/;

    my ($first,$last) = map { proxy($_) } $first0,$last0;

    # tie my $scalar, "HMP::Proxy::Scalar";
    # $scalar = \$orig;

    warn "... First = $first AND Last = $last";

    warn pp \@HMP::Proxy::vars;

    $first0 = "Flor";

    warn pp \@HMP::Proxy::vars;

}


BEGIN {
    sub proxy {
        tie my $scalar, "HMP::Proxy::Scalar",15;
        $scalar = \$_[0];
        return $scalar;
    }

    package HMP::Proxy;
    our @vars;

    package HMP::Proxy::Scalar;
    require Tie::Scalar;
    our @ISA = qw(Tie::StdScalar);

    sub FETCH {
        my ( $self ) = @_ ;
        push @vars, $$self;
        return "?"
    }

}

