Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Is what you want available?

by shmem (Chancellor)
on Jun 09, 2017 at 18:24 UTC ( #1192438=note: print w/replies, xml ) Need Help??

in reply to Is what you want available?

However, sometimes, what is available is a little less than what is wanted.

Whenever you encounter a module which provides a little less, you have 3 ways to add the missing bits (using Number::Format and Util::Number in the following):

  1. copy the source of Number::Format to Util/, add the missing subroutine and use your renamed private copy (brittle)
  2. write Util::Number as a subclass which uses Number::Format and extends its functionality with your own subs (better)
  3. switch packages in your code and add the enhanced subroutines there (hack)

The first decouples you from the development of Number::Format. You'd have to update your private module if you want to benefit from the improvements of Number::Format as it developes.

The second possibility places on you the tiny burden of writing tests for your module, but only for those bits you have added.

The third may be used if and only if a) you use Number::Format only in one place, b) the added bits are trivial, c) you know where to look when things break.

So, I'd go with number 2.

package Util::Number; use parent Number::Format; sub pretty_number { ... } 1;
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: Is what you want available?
by SuicideJunkie (Vicar) on Jun 09, 2017 at 20:16 UTC

    Don't forget 4) Offer the module owner a patch to add the functionality.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2019-09-19 02:27 GMT
Find Nodes?
    Voting Booth?
    The room is dark, and your next move is ...

    Results (238 votes). Check out past polls.