package a;
sub new {
my $class = shift;
my $self = {};
bless $self,$class;
return $self;
}
my $obj = new a ();
####
my $obj = "a"->new();
##
##
$obj ->{$self}{avalue}=10;
print $obj->{$self}{avalue};
##
##
{
package a;
sub new {
my $class = shift;
my $self = {};
bless $self,$class;
return $self;
}
sub avalue {
my $self = shift;
$self->{avalue} = shift if @_;
return $self->{avalue};
}
}
my $obj = "a"->new();
$obj->avalue(10); # set
print $obj->avalue, "\n"; # get
##
##
{
package a;
use Moo;
has avalue => (is => 'rw');
}
my $obj = "a"->new();
$obj->avalue(10); # set
print $obj->avalue, "\n"; # get