use strict;
use warnings;
use 5.010;
sub greet {
say 'hello';
}
sub test {
goto &{"greet"}; #SYMBOLIC REFERENCE
}
test();
--output:--
hello
####
goto &{"greet"};
####
{package Dog;
sub new {
my $class = shift;
bless {Name=>'Spot', Color=>"black"}, $class;
}
#For auto generating the getters:
sub AUTOLOAD {
my $self = shift;
our $AUTOLOAD;
my %methods = (
color => undef,
name => undef,
);
if ($AUTOLOAD =~ /::(\w+)\z/
and
exists $methods{$1} ) {
my $data_name = ucfirst $1;
{
no strict 'refs';
*{$AUTOLOAD} = sub { $self->{$data_name} };
}
goto &{$AUTOLOAD};
}
else {
use Carp;
croak "No method named $AUTOLOAD";
}
}
}
my $dog = Dog->new;
say $dog->name;
say $dog->color;