Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: sub BEGIN

by BrowserUk (Patriarch)
on May 10, 2010 at 22:06 UTC ( [id://839317]=note: print w/replies, xml ) Need Help??


in reply to Re^2: sub BEGIN
in thread sub BEGIN

From my perspective, BEGIN blocks are a form of code smell. In this case, a variation on 'Inappropriate intimacy'.

Several possibilities for a fix stand out:

  1. Making that hash a constant.
  2. Using inheritance rather than poking stuff into remote namespaces.
  3. If the use of the BEGIN block is required to make the code work as need, then a better solution would be to move the require.
  4. If the BEGIN block is a precautionary prophylactic, you might as well use cling film, because it is full of holes.

    What if the required module calls the overridden method within its own BEGIN block?

    Once you start the arms race of every programmer putting the bits of their code they think are of paramount importance in BEGIN blocks, soon everybody will be putting everything in BEGIN blocks, and you're back to square one with no solution.

But the most interesting question here I think would be: why are you poking around in there anyway?

That is, what led you in there? What are you trying to do that you're failing to achieve? What error situation are you trying to avoid? What is it that you're really asking for help with?

If this is just an academic exercise of trying to improve your Perl by reading and understanding the internals of some examples, on the basis of what you've posted in isolation, you'd better pick some better examples.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found