use strict;
use warnings;
use Data::Dump qw/pp/;


package INTERPOLATOR;
use PadWalker qw/closed_over peek_sub set_closed_over/;
use Data::Dump qw/pp/;

our @ref_list;


use overload
  '""' => sub {
     #warn '"": ',pp \@_;
     my ($l,$r,$f) = @_;
     push @ref_list, $l;

     '<"'.$l->{val}.'">';
     #'?'
  };
;

sub bless_scalars {
   $_ = \ bless {val=>$_,ref=>\$_}, "INTERPOLATOR" for @_;
}

sub unbless_scalars {
   $_ = $$_->{val} for @_;
}

sub sql(&) {
   my $lambda=shift;
   my $h_vars = closed_over($lambda);
   #warn pp $h_vars;

   #bless_scalars(values %$h_vars);
   $h_vars->{'$x'} = \ bless { val=> 'X' }, "INTERPOLATOR";
   warn values %$h_vars;


   @ref_list = ();
   my $string =  $lambda->();
   my @refs   = @ref_list;
   #   unbless_scalars(values %$h_vars);

   return [$string, \@refs];

}




package main;


my $x = 'X';
my $y = 'Y';

#INTERPOLATOR::bless_scalars($y);

$y = bless { val=> $y }, "INTERPOLATOR"; # explizit überladen

my @a = ("a".."c");



warn pp INTERPOLATOR::sql {
    "$x --- $y --- $x ---"
};

my $z = $y;

warn $z;




