Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: questions about bless's second argument

by perlfan (Vicar)
on Nov 20, 2020 at 20:01 UTC ( #11123926=note: print w/replies, xml ) Need Help??

in reply to questions about bless's second argument

Welcome! My preferred idiom or pattern looks like this,
package Widget; use strict; use warnings; # generic constructor, allows for any keys to be passed like, # my $widget = Widget->new(field1 => "value 1", field2 => "value 2", e +tc => "etc..."); sub new { my ($pkg, %self) = @_; # can validate parameters here... (I like Validate::Tiny) # technically it's a "package", also the 2nd argument to # bless is a string, literally just the "package" name ('Widget') return bless \%self, $pkg; } 1; #<-- note

I highly recommend looking at the following:

My standard advice is to stay away from any OO perl systems that promise the m00n until you understand how Perl makes all this happen. Conway's, Object Orient Perl is a must peruse.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2021-04-11 10:34 GMT
Find Nodes?
    Voting Booth?

    No recent polls found