oop - Object Oriented In Perl Script -
sub new { $class = shift; #off first element $self = { }; bless $self, $class; return $self; }
could explain that? use of following 3 lines of code?
my $self = { }; bless $self, $class; return $self;
my $self = { };
creates anonymous hash reference , stores in the lexical variable $self.bless $self, $class;
tells perl $self not reference object of class stored in $class. see bless in perldoc.bless $x, $y
returns $x, , subroutine returns value of last executed statement unless explicetly told otherwisereturn
statement, next line optional, readability.return $self;
hands value in $self (our special object reference) calling function. see return in perldoc.
edit:
to clarify, if don't bless
reference, won't able call methods on it. bless
tell perl, "look, on, associate reference in $self class in $class, can use methods in class on reference."
Comments
Post a Comment