Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

Title:
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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2024-04-23 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found