Last active
August 29, 2015 14:13
-
-
Save preaction/a624521088c4b916bd84 to your computer and use it in GitHub Desktop.
Simple readonly hash object
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 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