XP is just a number | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
One thing that is quintisential to all object orriented programming is inheritance. I don't believe your script allows for that (what if module script use()es it, and put @ISA = yourModule). I'm sure there are other ways to preserve inheritance, but the one I've used is that of CGI.pm, which has a self_or_default function. That function creates a blessed object, if there is not one to begin with. A more simple version, which would be fine for you would be:
All the subroutine does is checks that an object is defined, and that it is the object for the class you are using. If there is no object, the script creates one, for use throughout the script, without the user knowing that it exists. It's actually a really cool idea, because an oblivious user can't mess with an object, although it exists, but I'm sure some guru has a reason not to use it. It also preserves inheritance by using Universal::isa (UNIVERSAL::isa ( VAL, TYPE ) ), which returns true if the VAL is the name of a package that inherits from (or is itself) package TYPE. Update: And to use the subroutine -
Gyan Kapur gyan.kapur@rhhllp.com In reply to Re: How to morph a plain module to OO
by Revelation
|
|