January 2019 Archives

bless is good parts of Perl language

Recently I feel bless is good parts of Perl language strongly.

package Point;

use strict;
use warnings;

sub new {
my $class = shift;

my $self = {@_};

return bless $self, $class;
}

sub x { shift->{x} }
sub y { shift->{y} }

This is smallest class which have only read accessors. Very clean and compact.

This class work well completely.

use Point;
my $point = Point->new(x => 1, y => 2);
my $x = $point->x;

Some pe…

About Yuki Kimoto

user-pic I'm Perl Programmer. I LOVE Perl. I want to contribute Perl community and Perl users.