Help for this page

Select Code to Download


  1. or download this
    # in package MyModule::Types
    declare DBPrefix, as Optional[StrMatch[ qr/ \w+_ /x ]],
    ...
    #    "Optional[StrMatch[(?^x: \w+_ )]]" constrains $_[0] with "StrMatc
    +h[(?^x: \w+_ )]" if it exists
    #    Value "bar" did not pass type constraint "StrMatch[(?^x: \w+_ )]"
    + (in $_[0])
    #    "StrMatch[(?^x: \w+_ )]" is defined as: do { !ref($_) and $_ =~ $
    +Types::Standard::_StrMatch{"(?^x: \\w+_ )"} }
    
  2. or download this
    state $validate = compile(slurpy Dict[ prefix => DBPrefix ]); #per the
    + docs for named args
    my ($param) = $validate->( @_ );
    ...
    
    # output :
    # Reference {"prefix" => "bar"} did not pass type constraint "Dict[pre
    +fix=>DBPrefix]" (in $SLURPY) at ./foo.pl line 11