Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Is what you want available?

by shmem (Chancellor)
on Jun 09, 2017 at 18:24 UTC ( [id://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/Number.pm, 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?
Username:
Password:

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

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

    No recent polls found