in reply to Can't bless
choroba helped with the immediate problem, but maybe an example of common usage will help:
use strict; use warnings; package Pendulum; sub new { my ($class, %params) = @_; # Do interesting parameter validation here my $self = bless \%params, $class; # and other set up here. At this point you can call derived class +methods # as part of setup if you want using $self->methodName(); return $self; } package main; my $pit = Pendulum->new(Hz => 0.5);
Note in particular Pendulum->new(...) used to call the constructor
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't bless
by perlfan (Parson) on Mar 27, 2021 at 16:10 UTC |