Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Coding Perl With Style

by wog (Curate)
on Nov 27, 2001 at 06:31 UTC ( #127701=note: print w/replies, xml ) Need Help??

in reply to Coding Perl With Style

"" is not a good name for a module. "" is a built-in module to perl. Names beggining with lowercase letters should be considered reserved for pragmas; they are considered "special". "Something::Config" would probably be okay, however.

As for your actual question, you could probably make an object that encapsulated this configuration stuff , or (updated) and have your exsiting classes have it as an instance "variable". Or you could, as you suggested, just pass it as an argument to every function. I see no problem with either of these approaches; it is far cleaner then having your code not be so reuseable and modular.

If I declare a scalar as a constant in a module then export that scalar will it remain a constant?

"constants", as you are referring to, are actually functions that have a prototype of () (explictly no arguments), and thus are inlined by perl. You will get this optimization as long as the function is imported (so perl what to use and that it should inline it) when the relevant code is compiled.

Replies are listed 'Best First'.
Re: Re: Coding Perl With Style
by Dogma (Pilgrim) on Nov 27, 2001 at 07:13 UTC
    Actualy isn't the real name. It's so we're on the same page there. So your suggesting using as a base class and having all classes inherit from it. Like a smalltalk-90 oo tree right? Thanks for the answer about inlining.
      I would personally think you want a "has-a" relationship. "Configuration" info is shared by many (instances of) classes; it is not something that each of the instances should maintain an independent copy of.

      (update: Nor do I think you should have one copy of it be held statically by a base class, of course. I would prefer to leave room to maintaining to independent sets of this data in one application, if need-be.)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2022-12-03 18:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found