Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Object Oriented Programming in Perl.

by frankus (Priest)
on Aug 05, 2002 at 09:10 UTC ( #187610=note: print w/replies, xml ) Need Help??

in reply to Object Oriented Programming in Perl.

Hi, A few things I use that, of course, are optional (after all this is Perl)
  • Use the package name in the 'bless' statement : bless $self, $package;. Then call it using my $meal = Food->new()
  • Consider permitting the setting of parameters in the new method, perhaps by using a statement like this:
    my ($package,$params) = @_; my $self = ( ref($params) eq 'HASH' ) ? $params : {};
  • Factor in the use of namespaces, incase anyone decides your object is worth inheriting from.

As an aside, just Perl foibles of mine:

  • in the display function, why use all those print functions when one could be used?
  • use double-quoted variables only when you have to. Use single quotes unless you are interpolating variables in the string.

I mention the foibles as they're are inneficiencies so easily avoided.
Using OO Perl is going to slap an overhead on your code, make sure the code is lean.

As for OO Perl books apart from Damien Conway's OO Perl.. sure there are;
however the Conway book is IMHO well worth reading instead of citing, get it from a library if you can't afford it.
If you find the reading tricky, that's because the topic is tricky.
If you wish to understand OO Perl conventions, better to read this book. In the mean time try:


Brother Frankus.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://187610]
[Lady_Aleena]: james28909, what neat trick?
[james28909]: now if i have packed a script into a PDK exe, and misplaced the source, i can print it.
[james28909]: but you have to prepare for it first by adding this to the source
[james28909]: seek DATA, 0, 0; while (<DATA>) { print; }
[Lady_Aleena]: Sounds interesting. Have you written a meditation or cool use for it?
[Lady_Aleena]: It might be something PerlMonks at large would be interested in.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-05-01 00:06 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (543 votes). Check out past polls.