Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

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

Dear brothers and sisters,

I am looking for a lightweight class that I can wrap around numeric values.

Granted, as wheels go, this looks like a pretty easy one to re-invent... For my immediate needs, this may be enough:

# !!! UNTESTED !!! package MyNumberWrapper; use Scalar::Util 'looks_like_number'; sub new { my $class = shift; my $value; if ( @_ == 1 and defined $_[ 0 ] and looks_like_number( $_[ 0 ] ) { $value = 0 + shift; } else { # raise hell } return bless \$value, $class; } sub value { my $self = shift; return $$self + 0; } 1; __END__
But from bitter experience I've learned to resist as much as possible these seemingly trivial wheel re-invention projects. Hence I come to you for wisdom and guidance. Do you know of a well-tested class in CPAN that could serve this purpose?

the lowliest monk

PS: The reason behind this quest is convoluted, and I'd hate to bore you with it, but if you must know, here it is. The Storable module does dastardly things to numeric values, and my code must JSON-encode and transmit stuff that has been through one Storable::store/Storable::retrieve cycle. The purpose of this wrapper class is to selectively tag those data items that I want treated as numbers by JSON::XS before committing them to Storable::store, and then replace them with their underlying values once the whole thing has been Storable::retrieve'd. If there's a better way around this annoyance, please let me know.


In reply to ISO lightweight wrapper class for numbers by tlm

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 having an uproarious good time at the Monastery: (14)
    As of 2014-12-22 13:41 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (118 votes), past polls