Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

But, I would like to modify my package and have it reach into the script to see if a function exists.

If it's possible, I'd recommend going the other way. Have the executing script tell your package that the function exists, instead of having the package try to probe it.

With the suggested approaches here, you're hardwiring some function in your script into your package. What if the function moves? What if the function gets renamed? What if it gets deleted?

This is clearly a side effect. Somebody goes into the script and modifies the function, they then need to go into the separate package and modify the link to the function. Nothing makes it explicitly clear that anything else should care, its not like you're talking about modifying a library function it's clear that other calls may be affected.

So I think it'd be better to have the script tell the package instead. I'm thinking of something along these lines:

package FooBar; sub set_function_ref { my $function = shift; #do someting interesting with it. } in script.pl: sub interesting_fuction { # interesting things... } FooBar::set_function_ref(\&interesting_function);

And you're decoupled. Your package can now safely work anywhere else, and not depend upon a particular function existing in a particular package. Anything that wants to use FooBar just calls set_function_ref with the value it wants it to operate on.


In reply to Re: reaching into a perl script from a package by jimt
in thread reaching into a perl script from a package by Brad.Walker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (12)
    As of 2014-09-19 16:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (143 votes), past polls