Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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

Replies are listed 'Best First'.
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?
[Corion]: LanX: Yes, that's the main problem - you have lots (and lots) of workarounds in various places and stages of the processing, and to clean that mess up requires action across the complete codebase. And it's almost impossible to do it piece-by-piece

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (13)
As of 2017-01-16 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (150 votes). Check out past polls.