Skip to content

Instantly share code, notes, and snippets.

@gugod
Created June 26, 2023 01:51
Show Gist options
  • Save gugod/eaf1f97ee4f55b0fb121efa95effeca7 to your computer and use it in GitHub Desktop.
Save gugod/eaf1f97ee4f55b0fb121efa95effeca7 to your computer and use it in GitHub Desktop.
use v5.36;
use Data::Dumper 'Dumper';
use PerlX::SafeNav ('$safenav', '$unsafenav');
package O {
sub bar { "bar" }
sub foo { undef }
};
sub safenav :prototype(&) ($cb) {
sub {
local $_ = $_->$safenav;
$cb->()->$unsafenav;
}
}
sub with ($o, $p) {
local $_ = $o;
$p->();
}
my $o = bless {}, 'O';
my $result = with $o, safenav {
$_ -> foo -> bar;
};
say Dumper($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment