Pat Hourigan has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Being a perl novice and all round first timer with the monks site, here goes....

Coming from a java background, I have a component which I have designed so that the arguments that must be passed to the component are defined on an annotation. Therefore I enforce the documentation of the code alongside the injection of valid program arguments. Simply put, unless the developer annotate their component impl with the defined argument, then the argument will not be injected into the class. In the java space, this is all done through a pattern, so component implementations have intrinsic access to their args, once the class is loaded.

Now I want to take a similar paradigm and apply it to the Perl Space

Any opinions on the best path forward? Can I use the standard perldoc on an instance of MyComponent, inpect that components perldoc and use it to validate and inject the arguments?

Any steers will be helpful, I can try it out and post my result up here if people find it useful.

Yours in interpreted heaven..p
  • Comment on Using PerlDoc to define the program arguments

Replies are listed 'Best First'.
Re: Using PerlDoc to define the program arguments
by Corion (Patriarch) on Mar 29, 2012 at 14:27 UTC

    See Pod::Usage.

    As a side note, at least I can't do much with phrases like "annotate their component impl with the defined argument" and "then the argument will not be injected into the class.". If you can make it more clear what it should mean (unless it applies to Pod::Usage), that can help us help you better. The terms "component" and "injection" are not well-defined when talking about Perl objects.

    If you want to "enforce" parameters in a Java style, including the horrible, overly verbose and completely unhelpful backtraces, Params::Validate provides all of these features.

      thanks for the info. will check it out. A little knowledge is a very dangerous thing. I'll create something and post it here.

      hang on to your hat!!

Re: Using PerlDoc to define the program arguments
by chromatic (Archbishop) on Mar 29, 2012 at 17:56 UTC