Skip Menu |

This queue is for tickets about the Config-Validate CPAN distribution.

Report information
The Basics
Id: 33374
Status: open
Priority: 0/
Queue: Config-Validate

People
Owner: Nobody in particular
Requestors: djerius [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Per item init & cleanup
I would like to take advantage of Config::Validate's parsing of the schema to piggyback type-specific data "normalization" onto the validation process. For example, one could make file or directory paths absolute, or perform measurement unit conversion, etc. I thought the init and cleanup callbacks would be an appropriate way of doing this, but, if I'm parsing the docs and code correctly, the init and cleanup callbacks are invoked upon the entire config hash, not on individual items of the given type. I'd thus need to essentially rescan the config hash to find elements matching the callback's type. Since Config::Validate is already doing this, it seems just a wee bit redundant. The easiest solution is probably to add support for the byreference attribute, in which case one could modify the item in the validation routine (a bit bizarre, but not too horrible). An alternative might be to add additional init/cleanup callbacks which are invoked directly on the item, but that's a lot more intrusive. Thanks, Diab
I think the best route would be to make Config::Validate pass the value into the per item callback by reference, instead of by values. At this point, I don't have any code using the per item callback mechanism, and the module is only recently released to CPAN, so I think now would be the time to make this change, since it will not be backwards compatible. Alternatively, I can expose the byreference functionality and you could define your own validation type that would do this. I was intending to do this long term already. Lastly, and perhaps the best long term solution, I could add a per item init and finish, which would be called before and after the callback. You could then register a new validation type called something like 'normalize_files', which would look for items setup for 'file' validation, and then normalize them pre validation. What are your thoughts?
So I'm thinking the best route is to change all validation callbacks to take the value by reference, and add a item_init and item_finish callback on the type interface. This will break older validation callbacks, but I can't imagine there are too many of those at this point. How does this sound?
On Mon Feb 18 09:10:24 2008, CMO wrote: Show quoted text
> So I'm thinking the best route is to change all validation callbacks to > take the value by reference, and add a item_init and item_finish > callback on the type interface. This will break older validation > callbacks, but I can't imagine there are too many of those at this > point. How does this sound?
That would work, although passing a reference to the validation callback makes it a bit fuzzy as to what the difference between the callbacks is (the pre- and post- callback functionality could be rolled into the validation callback). One way to clarify things is to provide a means of specifying which callbacks are to be invoked. I see two behaviors that would need to be addressed on a per _item_ (rather than per _type_) basis 1. which callbacks get invoked 2. which results are stored in the config hash based back to the user. Assuming that there is control over which callback is invoked on a per item basis, there are 4 possible scenarios: pre | post use? N N Y N Y Y N Y Assuming that the validation routine does *not* modify the item value, then there are the following ways of determining an input item (V)'s returned value: NN: v0 = V; validate(v0) V = v0 YN: v0 = V; v1 = pre(v0) ; validate(v1) V ?= (v0, v1 ) YY: v0 = V; v1 = pre(v0) ; validate(v1); v2 = post(v1) V ?= (v0, v1, v2 ); NY: v0 = V; v1 = validate( v0 ); v2 = post ( v1 ) V ?= (v0, v1, v2 ); where I've used ?= to indicate that V could be set to any of those values. One way is to expose this is to add the options "pre", "post", and "return". The first two are booleans and indicate whether those callbacks should be invoked and the last is an integer indicating which of the above values is copied into the final config hash. For example, I've been trying to figure out a means of using the existing boolean conversion so that the returned config hash has the converted value. Let's say that the conversion code is moved from the validation callback to a pre-validate callback. An item might then have flags pre = yes post = no return = 1 indicating that the converted boolean value be returned. Or, to mimic the current situation, pre = yes post = no return = 0 indicating that the input item value should be passed on as is. There should be a means of specifying default values for these. Does this sound too complicated?
Subject: Re: [rt.cpan.org #33374] Per item init & cleanup
Date: Fri, 22 Feb 2008 20:01:11 -0500
To: bug-Config-Validate [...] rt.cpan.org
From: "Clayton O'Neill" <clayton [...] oneill.net>
So right now I have implemented what I emailed you about on Monday. In addition, it's possible to add a pre or post validation call back per item, even on existing items. However, reading through your email, I'm thinking maybe something more flexible would be better. My current thought would be to allow people to specify a validation chain. So if you wanted filename canonization, then you could do something like "validate => [ 'file_canonzize', 'check_exists' ]". And then you could chain as many of them as you want. I think it'd be possible to do this in a backwards compatible way, but it'd be a lot of work. I'm inclined to finish up what I have done, and release it and then see how things go from there. What are your thoughts on doing validation chains, instead of pre/validate/post hooks per item? On Fri, Feb 22, 2008 at 6:07 PM, Diab Jerius via RT <bug-Config-Validate@rt.cpan.org> wrote: Show quoted text
> > Queue: Config-Validate > > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=33374 > > > On Mon Feb 18 09:10:24 2008, CMO wrote:
> > So I'm thinking the best route is to change all validation callbacks to > > take the value by reference, and add a item_init and item_finish > > callback on the type interface. This will break older validation > > callbacks, but I can't imagine there are too many of those at this > > point. How does this sound?
> > That would work, although passing a reference to the validation > callback makes it a bit fuzzy as to what the difference between the > callbacks is (the pre- and post- callback functionality could be > rolled into the validation callback). > > One way to clarify things is to provide a means of specifying which > callbacks are to be invoked. > > I see two behaviors that would need to be addressed on a per _item_ > (rather than per _type_) basis > > 1. which callbacks get invoked > 2. which results are stored in the config hash based back to the > user. > > Assuming that there is control over which callback is invoked on a per > item basis, there are 4 possible scenarios: > > pre | post > use? N N > Y N > Y Y > N Y > > Assuming that the validation routine does *not* modify the item value, > then there are the following ways of determining an input item (V)'s > returned value: > > > NN: v0 = V; validate(v0) > > V = v0 > > YN: v0 = V; v1 = pre(v0) ; validate(v1) > > V ?= (v0, v1 ) > > YY: v0 = V; v1 = pre(v0) ; validate(v1); v2 = post(v1) > > V ?= (v0, v1, v2 ); > > NY: v0 = V; v1 = validate( v0 ); v2 = post ( v1 ) > > V ?= (v0, v1, v2 ); > > where I've used ?= to indicate that V could be set to any of those values. > > One way is to expose this is to add the options "pre", "post", and > "return". The first two are booleans and indicate whether those > callbacks should be invoked and the last is an integer indicating which > of the above values is copied into the final config hash. > > For example, I've been trying to figure out a means of using the > existing boolean conversion so that the returned config hash has the > converted value. Let's say that the conversion code is moved from the > validation callback to a pre-validate callback. An item might then > have flags > > pre = yes > post = no > return = 1 > > indicating that the converted boolean value be returned. Or, to mimic > the current situation, > > pre = yes > post = no > return = 0 > > indicating that the input item value should be passed on as is. > > There should be a means of specifying default values for these. > > Does this sound too complicated? > > > > > > > >
Subject: Re: [rt.cpan.org #33374] Per item init & cleanup
Date: Fri, 22 Feb 2008 21:03:20 -0500
To: bug-Config-Validate [...] rt.cpan.org
From: Diab Jerius <dj [...] head.cfa.harvard.edu>
On Fri, 2008-02-22 at 20:01 -0500, Clayton O'Neill via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=33374 > > > So right now I have implemented what I emailed you about on Monday. > In addition, it's possible to add a pre or post validation call back > per item, even on existing items. However, reading through your > email, I'm thinking maybe something more flexible would be better. > > My current thought would be to allow people to specify a validation > chain. So if you wanted filename canonization, then you could do > something like "validate => [ 'file_canonzize', 'check_exists' ]". > > And then you could chain as many of them as you want. I think it'd be > possible to do this in a backwards compatible way, but it'd be a lot > of work. I'm inclined to finish up what I have done, and release it > and then see how things go from there. > > What are your thoughts on doing validation chains, instead of > pre/validate/post hooks per item?
To be honest, I'm of two minds. On the one hand it would make it possible to use a library of existing validation "objects" to perform complex work. On the other hand it seems overly complicated. I would imagine that most chains would have only a couple of steps in them. I'm a bit unclear how this scheme works in terms of specifying the final item value. 'canonicalize', 'check', 'uncanonicalize' seems a bit clunky. In my current application I'm moving towards encoding the schema in a Config::General parsed file, so I'd like to see as much control as possible be placed within the schema.
Subject: Re: [rt.cpan.org #33374] Per item init & cleanup
Date: Fri, 22 Feb 2008 21:04:51 -0500
To: bug-Config-Validate [...] rt.cpan.org
From: "Clayton O'Neill" <clayton [...] oneill.net>
Oh, it never occured to me that you'd want to uncanonize the filenames. On Fri, Feb 22, 2008 at 9:03 PM, Diab Jerius via RT <bug-Config-Validate@rt.cpan.org> wrote: Show quoted text
> > Queue: Config-Validate > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=33374 > > > > On Fri, 2008-02-22 at 20:01 -0500, Clayton O'Neill via RT wrote: >
> > So right now I have implemented what I emailed you about on Monday.
> > In addition, it's possible to add a pre or post validation call back > > per item, even on existing items. However, reading through your > > email, I'm thinking maybe something more flexible would be better. > > > > My current thought would be to allow people to specify a validation > > chain. So if you wanted filename canonization, then you could do > > something like "validate => [ 'file_canonzize', 'check_exists' ]". > > > > And then you could chain as many of them as you want. I think it'd be > > possible to do this in a backwards compatible way, but it'd be a lot > > of work. I'm inclined to finish up what I have done, and release it > > and then see how things go from there. > > > > What are your thoughts on doing validation chains, instead of > > pre/validate/post hooks per item?
> > To be honest, I'm of two minds. On the one hand it would make it > possible to use a library of existing validation "objects" to perform > complex work. On the other hand it seems overly complicated. I would > imagine that most chains would have only a couple of steps in them. > > I'm a bit unclear how this scheme works in terms of specifying the final > item value. > > 'canonicalize', 'check', 'uncanonicalize' > > seems a bit clunky. > > In my current application I'm moving towards encoding the schema in a > Config::General parsed file, so I'd like to see as much control as > possible be placed within the schema. > > > >
Subject: Re: [rt.cpan.org #33374] Per item init & cleanup
Date: Fri, 22 Feb 2008 21:20:39 -0500
To: bug-Config-Validate [...] rt.cpan.org
From: "Clayton O'Neill" <clayton [...] oneill.net>
Show quoted text
>Queue: Config-Validate > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=33374 >
Show quoted text
> To be honest, I'm of two minds. On the one hand it would make it > possible to use a library of existing validation "objects" to perform > complex work. On the other hand it seems overly complicated. I would > imagine that most chains would have only a couple of steps in them. > > I'm a bit unclear how this scheme works in terms of specifying the final > item value. > > 'canonicalize', 'check', 'uncanonicalize' > > seems a bit clunky. > > In my current application I'm moving towards encoding the schema in a > Config::General parsed file, so I'd like to see as much control as > possible be placed within the schema.
I tend to think the best thing to do here would be to just implement a new type, rather than try to wrap the fairly trivial existing file check. The reason I suggested the chained validation hooks isn't so much for your scenario, but for another. Long term I'd like to work out a way to have schema be validated at runtime using Config::Validate itself. This requires a good bit more flexibility than what is currently available, and I've been thinking about how to achieve that off and on. If you're not waiting for this functionality, then I think I'm going to think about what a better long term approach is for a few days. Adding the per item pre and post validate code was fairly trivial, but if it's not the right long term approach, I'd rather not release it and have to support it long term.
CC: djerius [...] cpan.org
Subject: Re: [rt.cpan.org #33374] Per item init & cleanup
Date: Fri, 22 Feb 2008 22:59:07 -0500
To: bug-Config-Validate [...] rt.cpan.org
From: Diab Jerius <dj [...] head.cfa.harvard.edu>
On Fri, 2008-02-22 at 21:20 -0500, Clayton O'Neill via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=33374 > >
> >Queue: Config-Validate > > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=33374 >
>
> > To be honest, I'm of two minds. On the one hand it would make it > > possible to use a library of existing validation "objects" to perform > > complex work. On the other hand it seems overly complicated. I would > > imagine that most chains would have only a couple of steps in them. > > > > I'm a bit unclear how this scheme works in terms of specifying the final > > item value. > > > > 'canonicalize', 'check', 'uncanonicalize' > > > > seems a bit clunky. > > > > In my current application I'm moving towards encoding the schema in a > > Config::General parsed file, so I'd like to see as much control as > > possible be placed within the schema.
> > I tend to think the best thing to do here would be to just implement a > new type, rather than try to wrap the fairly trivial existing file > check.
True, it's a bit of a contrived example. Show quoted text
> > The reason I suggested the chained validation hooks isn't so much for > your scenario, but for another. Long term I'd like to work out a way > to have schema be validated at runtime using Config::Validate itself. > This requires a good bit more flexibility than what is currently > available, and I've been thinking about how to achieve that off and > on. If you're not waiting for this functionality, then I think I'm > going to think about what a better long term approach is for a few > days. Adding the per item pre and post validate code was fairly > trivial, but if it's not the right long term approach, I'd rather not > release it and have to support it long term.
Understood. For my application, having the ability to specify the "byreference" flag for a validation callback would suffice.
Subject: Re: [rt.cpan.org #33374] Per item init & cleanup
Date: Fri, 22 Feb 2008 23:01:08 -0500
To: bug-Config-Validate [...] rt.cpan.org
From: "Clayton O'Neill" <clayton [...] oneill.net>
On Fri, Feb 22, 2008 at 10:59 PM, Diab Jerius via RT <bug-Config-Validate@rt.cpan.org> wrote: Show quoted text
> > The reason I suggested the chained validation hooks isn't so much for > > your scenario, but for another. Long term I'd like to work out a way > > to have schema be validated at runtime using Config::Validate itself. > > This requires a good bit more flexibility than what is currently > > available, and I've been thinking about how to achieve that off and > > on. If you're not waiting for this functionality, then I think I'm > > going to think about what a better long term approach is for a few > > days. Adding the per item pre and post validate code was fairly > > trivial, but if it's not the right long term approach, I'd rather not > > release it and have to support it long term.
> > Understood. For my application, having the ability to specify the > "byreference" flag for a validation callback would suffice.
Yeah, I'm intending to make that the default and remove the flag entirely. It should have been that way from day one. I'll probably do a release with that functionality in the next few days.