What do you find wrong or strange in this Perl code to simulate objects without bless?
Posted
by user350571
on Stack Overflow
See other posts from Stack Overflow
or by user350571
Published on 2010-05-26T06:07:01Z
Indexed on
2010/05/26
14:31 UTC
Read the original article
Hit count: 254
perl
|class-design
I'm new to Perl and its blessing stuff to imitate class like functionality made me feel strange I even had to go to the bathroom.
Now, please tell me: what do you don't like, find wrong or strange with this code:
sub Person
{
my $age = shift || 15;
return
{
printAge => sub
{
print "Age -> $age\n";
},
changeAge => sub
{
$age = shift
}
}
}
my $p = Person();
my $p2 = Person(27);
$p->{printAge}->();
$p->{changeAge}->(30);
$p->{printAge}->();
$p2->{printAge}->();
© Stack Overflow or respective owner