Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: construct a standard object oriented program

by Anonymous Monk
on Mar 30, 2002 at 22:41 UTC ( #155513=note: print w/ replies, xml ) Need Help??


in reply to construct a standard object oriented program

It really doesn't matter what you call it. I tend to give it a name in context with the name of the module. For instance, I am writing a wrapper around DBI.pm to handle all my database calls and I call the instantiating subroutine connect.

What is important is that you have a sub that blesses a hash. Objects are really hash references and blessing allows them to call subs from their module as well as the information stored within them.

To be specific, you need:

#...
my $self = bless {};
#...
return $self;
#

Note that 'return $self' is not required if bless is on the last line of your code and you don't assign the bless to a scalar.

Hope that helps!


Comment on Re: construct a standard object oriented program
Re: Re: construct a standard object oriented program
by PrakashK (Pilgrim) on Mar 30, 2002 at 23:50 UTC
    What is important is that you have a sub that blesses a hash. Objects are really hash references ...
    Objects need not be hash references. Rather, any reference whose referent has been bless()ed into a particular class (read: package). The reference may be an array reference, scalar reference or even a reference to a subroutine.

    /prakash

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2014-10-23 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (124 votes), past polls