Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Can't bless

by GrandFather (Saint)
on Mar 21, 2021 at 20:33 UTC ( [id://11130056]=note: print w/replies, xml ) Need Help??


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

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^2: Can't bless
by perlfan (Vicar) on Mar 27, 2021 at 16:10 UTC
    perlootut is a good start, in addition to the other docs mentioned herein. Actually I take that back, I may be misremembering how well done that was, but it doesn't even show a constructor using basic Perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11130056]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 05:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found