See also Getopt::Flex, Getopt::Valid, FormValidator::Simple, CGI, App::Cmd, App::CLI

Kind of silly , but you could write

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; use CGI; use Getopt::Long; use FormValidator::Simple; Fudge(qw[ -i 3 --input=6 --input=9 ]); Fudge('-i', '__FILE__' ); sub Fudge { local @ARGV = @_; my $query = CGI->new({}); my $queryer = sub { my( $name, $value ) = @_; my @vals = $query->param( $name ); $query->param( $name, $value, @vals ); return; }; GetOptions( 'input|i=s' => $queryer, ); my $rules = [ input => [ qw[ NOT_BLANK ASCII SINGLE ], ['REGEX' => qr/^\w+$/ +], ], ]; my $results = FormValidator::Simple->check( $query => $rules ); if ( $results->has_error ) { foreach my $key ( @{ $results->error() } ) { dd $results->record( $key )->data; foreach my $type ( @{ $results->error($key) } ) { print "invalid: $key - $type \n"; } print "\n"; } } else { print "valid input: ", $results->record('input')->data, "\n"; } } sub FormValidator::Simple::Validator::SINGLE { package FormValidator::Simple::Validator; my ($self, $params, $validatorArgs) = @_; my $data = $params->[0]; my $selected = ref $data ? $data : [$data]; return scalar(@$selected) == 1 ? TRUE : FALSE; } __END__ [9, 6, 3] invalid: input - SINGLE invalid: input - REGEX valid input: __FILE__

SINGLE is "monkeypatched" instead of a plugin


In reply to Re: getopts and duplicit params (multiple / FormValidator::Simple::Validator::SINGLE ) by Anonymous Monk
in thread getopts and duplicit params by cOreey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.