in reply to code tidying - re-inventing the wheel?
You might want to look into Params::Validate which does something somewhat similar.