Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
three minor comments...
  • Why make the mutators "set_foo" ... why not just overload "foo" (ie: foo with args does a set, and returns true if-and-only-if the args are valid, without args returns whatever the parameter value(s) should be.
  • Frequently when I've needed to use Parameter Objects (or "Keys" as their sometimes called) there are acctually two issues of validity:
    1. Are the individual parameters valid?
    2. is the combination of parameters valid?
    ... you've addressed the first, but not the second. There are lots of examples of when this becomes crucial, but the the most basic is: what if none of the set methods are called?" Typically the easiest solution is to have a unified "isValid" method on all of your Parameter Objects that returns true if-and-only-if all of the required parameters have been set, and there is "internal consistency" among the parameters, then any method that wants to take in a Parameter object doesn't need to do it's own validation, it can just call $param->isValid() However ... in cases where i've seen this done, it works becaue the methods expect a particular sub class of the "Parameter Object" class, and each sub class defines it's own isValid method. Based on your design, I'm not really sure what the best way to do this would be (because whoever calls "new Sub::ParamObject" can pass whatever rules they want.
  • Your example validation for month has a slight bug in it...
    my %params = ( type => qr/Order|Return/, month => sub { my $month = shift; return grep { /$month/ } (1 .. 1 +2) } );
    ..that would allow me to pass '' as a valid month.

In reply to Re: RFC - Parameter Objects by hossman
in thread RFC - Parameter Objects by Ovid

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 How to display code and escape characters are good places to start.
Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-06-22 10:42 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.