in reply to Re^2: Multiple packages for first time
in thread Multiple packages for first time

"I would much rather do FORTRAN that OOP"

I wouldn't want to do a CGI application in FORTRAN however! I think you are making the OO part out to harder than it is. In perl you can make your objects as complicated or as simple as you're task demands. At the simple level you are just placing your data and it's access methods in a separate Package. You don't have to make the methods private if you don't want to. The Package can be in the same file or a separate one. You don't even have to export your methods (doing so makes them easier to call). You don't have to use inheritance and should you need inheritance you can choose your inheritance method.

If there is a "philosophy" behind perl OO it's "There is more than one way to do it." I can't take credit for that particular insight. I just heard it somewhere, once. ;->

There exists templates for making perl classes. I'm not familiar with them but a search of CPAN and this site should turn up some. My own tendency would be to learn to do it "longhand" first before evaluating packaged solutions. YMMV

  • Step one is to localize your data.
  • Step two is to create access methods (subroutines) for your data.
  • Step three is to move the data and methods into a separate file. Bless the references and call Exporter on your methods. Done!


    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}
  • Replies are listed 'Best First'.
    Re^4: Multiple packages for first time
    by Anonymous Monk on Feb 25, 2008 at 23:42 UTC
      The philosophy helped a bit. There is almost no end of has-a in this problem, and very little is-a. Objects make the interface nicer (to me), but inheritance looks like a non-issue now. Thanks.