Skip to content

Instantly share code, notes, and snippets.

@preaction
Last active August 29, 2015 14:13
Show Gist options
  • Save preaction/a624521088c4b916bd84 to your computer and use it in GitHub Desktop.
Save preaction/a624521088c4b916bd84 to your computer and use it in GitHub Desktop.
Simple readonly hash object
use strict;
use warnings;
use feature qw( say );
package Hash::Object;
sub new {
my ( $class, %self ) = @_;
return bless { %self }, $class;
}
our $AUTOLOAD;
sub AUTOLOAD {
my ( $self ) = @_;
my ( @parts ) = split /::/, $AUTOLOAD;
return $self->{ $parts[-1] };
}
package main;
my $hobbit = Hash::Object->new( name => 'Frodo', home => 'Bag End' );
say $hobbit->name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment