#!/usr/bin/perl
# Idiom #282 Use a custom type as map key
# https://p...content-available-to-author-only...s.org/idiom/282/use-a-custom-type-as-map-key/6042/perl

use v5.10;
use Data::Dumper;

package Foo {
   use Scalar::Util 'refaddr';
    
   use overload '""' => sub { shift->_stringify() };
  
    sub _stringify {
        my $self = shift;
        my $x = $self->x;
        return "object $x: " . refaddr $self;
    }
    sub x { my $self = shift; $self->{x} // '' };
    
    sub new { my $class = shift; return bless { @_ }, $class }    
};
 
my $p = Foo->new(x => 5);
say '$p->x is ', $p->x;

my %map;

$map{$p} = 'some data';

say Dumper \%map;
