Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

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

You're right about being almost a CPAN module. But for the minimal case of encoding one string format to another, there is no reason for OOP.

If you provide a way to work with data sets in the abstract, an OOP approach starts to make sense.

  • Encoder object keeps an array of series. Series are just arrays of numbers.
  • Series can be managed using array-function like methods: push, pop, splice, etc.
  • Provide a from_string method that takes decimal comma/pipe delimited decimal strings and makes objects.
  • Provide a to_string method that generates comma/pipe delimited decimal strings from the object.
  • Provide an encode method that generates an encoded string from the data series in the object.
  • Provide a decode method that takes a maximum value and an encoded string and gets an approximation of the raw data.
  • Provide a decode_scaled method that takesan encoded string and decodes it to values between 0 and 4095.

Note that you could just as easily expose a few functions and handle everything as native structures and go 100% procedural here, as well. OOP could be a nice win if you have a group of similar encodings that use scaling functions and serialization in similar ways. Then you'll actually be able to benefit from inheritance (at least if you designed your class to support the correct abstractions).

An even better choice would be to check CPAN and see if there are any multi-front-end charting libraries that could be extended to include this output format. What you do then will depend on the charting API's needs.

Oh, BTW, don't do bless( $self );, it silently breaks inheritance. Use 2 argument bless instead. The invoking class name is available as the first argument to your constructor. bless $self, $class;

TGI says moo

In reply to Re^2: Perl and Google Charts extended encoding by TGI
in thread Perl and Google Charts extended encoding by PoliceCoP

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2021-06-13 14:58 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (57 votes). Check out past polls.