Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re(4): RFC - Parameter Objects (validation)

by hossman (Prior)
on May 14, 2003 at 21:35 UTC ( [id://258263]=note: print w/replies, xml ) Need Help??


in reply to Re(4): RFC - Parameter Objects (validation)
in thread RFC - Parameter Objects

Perhaps the contructor could be modified. The current hashref would fall under a key named "params" and a different key named "groups" would list group validations. Then, as soon as an accessor is called, the "group" validations would be checked. This would eliminate the order dependence. Workable?

This still leaves it up to the person constructing the Params object ot specify what the overall validation function is ... maybe the %params hash is some global that gets re-used by all of the clients -- because if they don't then the method they are passing the Params too will fail when it tries to access things with a certian name -- but they can allways just choose to not pass a "groups" test and circumvent the tests.

I would recommend approaching this problem form a different direction -- seperate the "definition" of what a valid Param object is for a given context, from the "instantiation" of a particular instance.

Consider something like this...

#### in the library code ### Sub::Param::make_new_param_type($param_type_name \%param_definitions, \&validity_function); ... sub some_method { my $param = shift; die "die" unless $param->isValid($param_type_name); ... } sub some_other_method { my $param = shift; die "die" unless $param->isValid($param_type_name); ... } ... ### in some client ... my $p = new Sub::Param($param_type_name); $p->foo(1); $p->bar('Toledo'); SomeLibrary::some_method($p); ...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-06-14 12:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    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.