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

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

by cavac (Priest)
on Mar 09, 2022 at 14:30 UTC ( #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 (Bishop) 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 (Bishop) 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? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2022-08-13 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?