
Hi there, attached is a function I have found useful in some of the OTRS-modules I worked on recently. It is called CheckParams() and its purpose is to offer an intuitive and flexible way of checking the params-hash that has been passed into a method. Currently, many methods contain code like this: # check all needed objects foreach (qw(ConfigObject LogObject DBObject TimeObject MainObject)) { die "Got no $_" if (!$Self->{$_}); } plus more checks for additional parameters that must be passed in via the %Params hash. When using CheckParams, the code looks like this: # check all needed objects CheckParams($Self, sub { 'ConfigObject' => '!Class=Kernel::Config', 'DBObject' => '!Class=Kernel::System::DB', 'LogObject' => '!Class=Kernel::System::Log', 'MainObject' => '!Class=Kernel::System::Main', 'TimeObject' => '!Class=Kernel::System::Time', }); As you can see, you pass CheckParam() the hash-ref that shall be checked and a specification (for performance reasons this should always be an anonymous subroutine). In the specification, you simply declare the supported parameters, whether or not they are required (!) or optional (?) or if they have to be of a specific class (Class=...). CheckParams() supports checking of more complex data structures, too: CheckParams($Params, sub { 'GeneralAttrs' => { 'From' => '!', 'To' => '!', }, 'JobAttrs' => { 'Creator' => '!', 'Changes' => [ { 'Action' => 'm{^(create|change|delete|sync)$}', 'Path' => '!', 'Content' => '?', } ], } }); This code snippet makes sure that the given $Params-hash contains two elements (GeneralAttrs & JobAttrs), each of which has to follow the specified substructures. As I believe this function could be useful throughout OTRS (now that we have the 2.2-branch), I'd like to add it to the framework. I can see two ways of doing that: 1.) non-OO style: add some kind of helper module (e.g. Utils.pm) and add CheckParams() as a *function* to that. 2.) OO style: add a new module Utils/Params.pm which contains a *class-method* Check(), such that you'd have to invoke it like this Utils::Params->Check($Params, sub { ... }); So what do you think? Do you like the idea in general at all? If so, how should that functionality be integrated (OO- or non-OO-style)? Please fire any suggestions or questions to this list or directly my way. cheers, Oliver