Last active
February 24, 2018 10:41
-
-
Save haukex/7da1940256716ec1ff6bd3f9c89814e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use warnings; | |
use strict; | |
use Data::Dumper; | |
use Memoize::Expire; | |
tie my %cache => 'Memoize::Expire'; | |
my $self = { cache => [ \%cache ] }; # self is not tied nor an object | |
eval { print Dumper($self); 1 } or warn $@; | |
#=> Can't locate object method "FIRSTKEY" via package "Memoize::Expire" at ... | |
$self = $self->{cache}[0]; # $self is now a ref to the tied hash | |
print Dumper(tied $self); #=> $VAR1 = undef; | |
print Dumper(tied %$self); | |
#=> $VAR1 = bless( { | |
# 'LIFETIME' => 0, | |
# 'C' => {}, | |
# 'NUM_USES' => 0 | |
# }, 'Memoize::Expire' ); | |
{ package MyTie; | |
BEGIN { require Tie::Scalar; our @ISA = qw(Tie::StdScalar); } | |
use overload bool => sub {} } | |
my $plain = 'plain'; | |
tie my $tied, 'MyTie'; | |
$tied = 'tied'; | |
print Dumper(tied $plain); #=> $VAR1 = undef; | |
print Dumper(tied $plain || $plain); #=> $VAR1 = 'plain'; | |
print Dumper(tied $plain // $plain); #=> $VAR1 = 'plain'; | |
print Dumper(tied $tied); #=> $VAR1 = bless( do{\(my $o = 'tied')}, 'MyTie' ); | |
print Dumper(tied $tied || $tied); #=> $VAR1 = 'tied'; (!!) | |
print Dumper(tied $tied // $tied); #=> $VAR1 = bless( do{\(my $o = 'tied')}, 'MyTie' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment