Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Do I have to export all variables and functions from my PM file?

by cavac (Parson)
on Mar 09, 2022 at 14:30 UTC ( [id://11141947]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Do I have to export all variables and functions from my PM file?
in thread Do I have to export all variables and functions from my PM file?

As long as you don't make it too hard to modify the behaviour of your code, that is. Also see the discussion on How to redefine a modules private function?.

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
  • Comment on Re^3: Do I have to export all variables and functions from my PM file?
  • Download Code

Replies are listed 'Best First'.
Re^4: Do I have to export all variables and functions from my PM file?
by eyepopslikeamosquito (Archbishop) on Mar 11, 2022 at 00:14 UTC

    Also related is TDD because writing a test first forces you to focus on module interface early and from the point of view of the module user.

    In your example discussion, module tests that employed a mock DNS server running on a different port would have caught this specific module interface issue before the module was released. Not only that, having your own mock DNS server controlled by your tests makes it easier to test module robustness and recovery (for example, how your module handles timeouts, broken connections, data corruption, ...).

      And a test would be pretty much impossible to run with the current version, unless the test was run as root AND unless there wasn't already a process running at the default port.

      perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
Re^4: Do I have to export all variables and functions from my PM file?
by eyepopslikeamosquito (Archbishop) on Mar 10, 2022 at 02:05 UTC

    Yes indeed! An example of having to resort to mind-boggling trickery and deviousness simply to modify the default value of a module parameter! :) While entertaining, and a challenging problem, definitely not an example of good module design.

    From On Interfaces and APIs, the most relevant point is probably this simple tip for Perl module designers from TheDamian:

    • Make common usage the default; allow uncommon usage via optional attributes.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-23 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found