Giter Club home page Giter Club logo

params-validate's Introduction

NAME

Params::Validate - Validate method/function parameters

VERSION

version 1.31

SYNOPSIS

use Params::Validate qw(:all);

# takes named params (hash or hashref)
sub foo {
    validate(
        @_, {
            foo => 1,    # mandatory
            bar => 0,    # optional
        }
    );
}

# takes positional params
sub bar {
    # first two are mandatory, third is optional
    validate_pos( @_, 1, 1, 0 );
}

sub foo2 {
    validate(
        @_, {
            foo =>
                # specify a type
                { type => ARRAYREF },
            bar =>
                # specify an interface
                { can => [ 'print', 'flush', 'frobnicate' ] },
            baz => {
                type      => SCALAR,     # a scalar ...
                                         # ... that is a plain integer ...
                regex     => qr/^\d+$/,
                callbacks => {           # ... and smaller than 90
                    'less than 90' => sub { shift() < 90 },
                },
            }
        }
    );
}

sub callback_with_custom_error {
    validate(
        @_,
        {
            foo => {
                callbacks => {
                    'is an integer' => sub {
                        return 1 if $_[0] =~ /^-?[1-9][0-9]*$/;
                        die "$_[0] is not a valid integer value";
                    },
                },
            }
        }
    );
}

sub with_defaults {
    my %p = validate(
        @_, {
            # required
            foo => 1,
            # $p{bar} will be 99 if bar is not given. bar is now
            # optional.
            bar => { default => 99 }
        }
    );
}

sub pos_with_defaults {
    my @p = validate_pos( @_, 1, { default => 99 } );
}

sub sets_options_on_call {
    my %p = validate_with(
        params => \@_,
        spec   => { foo => { type => SCALAR, default => 2 } },
        normalize_keys => sub { $_[0] =~ s/^-//; lc $_[0] },
    );
}

DESCRIPTION

I would recommend you consider using Params::ValidationCompiler instead. That module, despite being pure Perl, is significantly faster than this one, at the cost of having to adopt a type system such as Specio, Type::Tiny, or the one shipped with Moose.

This module allows you to validate method or function call parameters to an arbitrary level of specificity. At the simplest level, it is capable of validating the required parameters were given and that no unspecified additional parameters were passed in.

It is also capable of determining that a parameter is of a specific type, that it is an object of a certain class hierarchy, that it possesses certain methods, or applying validation callbacks to arguments.

EXPORT

The module always exports the validate() and validate_pos() functions.

It also has an additional function available for export, validate_with, which can be used to validate any type of parameters, and set various options on a per-invocation basis.

In addition, it can export the following constants, which are used as part of the type checking. These are SCALAR, ARRAYREF, HASHREF, CODEREF, GLOB, GLOBREF, and SCALARREF, UNDEF, OBJECT, BOOLEAN, and HANDLE. These are explained in the section on Type Validation.

The constants are available via the export tag :types. There is also an :all tag which includes all of the constants as well as the validation_options() function.

PARAMETER VALIDATION

The validation mechanisms provided by this module can handle both named or positional parameters. For the most part, the same features are available for each. The biggest difference is the way that the validation specification is given to the relevant subroutine. The other difference is in the error messages produced when validation checks fail.

When handling named parameters, the module will accept either a hash or a hash reference.

Subroutines expecting named parameters should call the validate() subroutine like this:

validate(
    @_, {
        parameter1 => validation spec,
        parameter2 => validation spec,
        ...
    }
);

Subroutines expecting positional parameters should call the validate_pos() subroutine like this:

validate_pos( @_, { validation spec }, { validation spec } );

Mandatory/Optional Parameters

If you just want to specify that some parameters are mandatory and others are optional, this can be done very simply.

For a subroutine expecting named parameters, you would do this:

validate( @_, { foo => 1, bar => 1, baz => 0 } );

This says that the "foo" and "bar" parameters are mandatory and that the "baz" parameter is optional. The presence of any other parameters will cause an error.

For a subroutine expecting positional parameters, you would do this:

validate_pos( @_, 1, 1, 0, 0 );

This says that you expect at least 2 and no more than 4 parameters. If you have a subroutine that has a minimum number of parameters but can take any maximum number, you can do this:

validate_pos( @_, 1, 1, (0) x (@_ - 2) );

This will always be valid as long as at least two parameters are given. A similar construct could be used for the more complex validation parameters described further on.

Please note that this:

validate_pos( @_, 1, 1, 0, 1, 1 );

makes absolutely no sense, so don't do it. Any zeros must come at the end of the validation specification.

In addition, if you specify that a parameter can have a default, then it is considered optional.

Type Validation

This module supports the following simple types, which can be exported as constants:

  • SCALAR

    A scalar which is not a reference, such as 10 or 'hello'. A parameter that is undefined is not treated as a scalar. If you want to allow undefined values, you will have to specify SCALAR | UNDEF.

  • ARRAYREF

    An array reference such as [1, 2, 3] or \@foo.

  • HASHREF

    A hash reference such as { a => 1, b => 2 } or \%bar.

  • CODEREF

    A subroutine reference such as \&foo_sub or sub { print "hello" }.

  • GLOB

    This one is a bit tricky. A glob would be something like *FOO, but not \*FOO, which is a glob reference. It should be noted that this trick:

      my $fh = do { local *FH; };
    

    makes $fh a glob, not a glob reference. On the other hand, the return value from Symbol::gensym is a glob reference. Either can be used as a file or directory handle.

  • GLOBREF

    A glob reference such as \*FOO. See the GLOB entry above for more details.

  • SCALARREF

    A reference to a scalar such as \$x.

  • UNDEF

    An undefined value

  • OBJECT

    A blessed reference.

  • BOOLEAN

    This is a special option, and is just a shortcut for UNDEF | SCALAR.

  • HANDLE

    This option is also special, and is just a shortcut for GLOB | GLOBREF. However, it seems likely that most people interested in either globs or glob references are likely to really be interested in whether the parameter in question could be a valid file or directory handle.

To specify that a parameter must be of a given type when using named parameters, do this:

validate(
    @_, {
        foo => { type => SCALAR },
        bar => { type => HASHREF }
    }
);

If a parameter can be of more than one type, just use the bitwise or (|) operator to combine them.

validate( @_, { foo => { type => GLOB | GLOBREF } );

For positional parameters, this can be specified as follows:

validate_pos( @_, { type => SCALAR | ARRAYREF }, { type => CODEREF } );

Interface Validation

To specify that a parameter is expected to have a certain set of methods, we can do the following:

   validate(
       @_, {
           foo =>
               # just has to be able to ->bar
               { can => 'bar' }
       }
   );

... or ...

   validate(
       @_, {
           foo =>
               # must be able to ->bar and ->print
               { can => [qw( bar print )] }
       }
   );

Class Validation

A word of warning. When constructing your external interfaces, it is probably better to specify what methods you expect an object to have rather than what class it should be of (or a child of). This will make your API much more flexible.

With that said, if you want to validate that an incoming parameter belongs to a class (or child class) or classes, do:

   validate(
       @_,
       { foo => { isa => 'My::Frobnicator' } }
   );

... or ...

   validate(
       @_,
       # must be both, not either!
       { foo => { isa => [qw( My::Frobnicator IO::Handle )] } }
   );

Regex Validation

If you want to specify that a given parameter must match a specific regular expression, this can be done with "regex" spec key. For example:

validate(
    @_,
    { foo => { regex => qr/^\d+$/ } }
);

The value of the "regex" key may be either a string or a pre-compiled regex created via qr.

If the value being checked against a regex is undefined, the regex is explicitly checked against the empty string ('') instead, in order to avoid "Use of uninitialized value" warnings.

The Regexp::Common module on CPAN is an excellent source of regular expressions suitable for validating input.

Callback Validation

If none of the above are enough, it is possible to pass in one or more callbacks to validate the parameter. The callback will be given the value of the parameter as its first argument. Its second argument will be all the parameters, as a reference to either a hash or array. Callbacks are specified as hash reference. The key is an id for the callback (used in error messages) and the value is a subroutine reference, such as:

validate(
    @_,
    {
        foo => {
            callbacks => {
                'smaller than a breadbox' => sub { shift() < $breadbox },
                'green or blue'           => sub {
                    return 1 if $_[0] eq 'green' || $_[0] eq 'blue';
                    die "$_[0] is not green or blue!";
                }
            }
        }
    }
);

validate(
    @_, {
        foo => {
            callbacks => {
                'bigger than baz' => sub { $_[0] > $_[1]->{baz} }
            }
        }
    }
);

The callback should return a true value if the value is valid. If not, it can return false or die. If you return false, a generic error message will be thrown by Params::Validate.

If your callback dies instead you can provide a custom error message. If the callback dies with a plain string, this string will be appended to an exception message generated by Params::Validate. If the callback dies with a reference (blessed or not), then this will be rethrown as-is by Params::Validate.

Untainting

If you want values untainted, set the "untaint" key in a spec hashref to a true value, like this:

my %p = validate(
    @_, {
        foo => { type => SCALAR, untaint => 1 },
        bar => { type => ARRAYREF }
    }
);

This will untaint the "foo" parameter if the parameters are valid.

Note that untainting is only done if all parameters are valid. Also, only the return values are untainted, not the original values passed into the validation function.

Asking for untainting of a reference value will not do anything, as Params::Validate will only attempt to untaint the reference itself.

Mandatory/Optional Revisited

If you want to specify something such as type or interface, plus the fact that a parameter can be optional, do this:

validate(
    @_, {
        foo => { type => SCALAR },
        bar => { type => ARRAYREF, optional => 1 }
    }
);

or this for positional parameters:

validate_pos(
    @_,
    { type => SCALAR },
    { type => ARRAYREF, optional => 1 }
);

By default, parameters are assumed to be mandatory unless specified as optional.

Dependencies

It also possible to specify that a given optional parameter depends on the presence of one or more other optional parameters.

validate(
    @_, {
        cc_number => {
            type     => SCALAR,
            optional => 1,
            depends  => [ 'cc_expiration', 'cc_holder_name' ],
        },
        cc_expiration  => { type => SCALAR, optional => 1 },
        cc_holder_name => { type => SCALAR, optional => 1 },
    }
);

In this case, "cc_number", "cc_expiration", and "cc_holder_name" are all optional. However, if "cc_number" is provided, then "cc_expiration" and "cc_holder_name" must be provided as well.

This allows you to group together sets of parameters that all must be provided together.

The validate_pos() version of dependencies is slightly different, in that you can only depend on one other parameter. Also, if for example, the second parameter 2 depends on the fourth parameter, then it implies a dependency on the third parameter as well. This is because if the fourth parameter is required, then the user must also provide a third parameter so that there can be four parameters in total.

Params::Validate will die if you try to depend on a parameter not declared as part of your parameter specification.

Specifying defaults

If the validate() or validate_pos() functions are called in a list context, they will return a hash or containing the original parameters plus defaults as indicated by the validation spec.

If the function is not called in a list context, providing a default in the validation spec still indicates that the parameter is optional.

The hash or array returned from the function will always be a copy of the original parameters, in order to leave @_ untouched for the calling function.

Simple examples of defaults would be:

my %p = validate( @_, { foo => 1, bar => { default => 99 } } );

my @p = validate_pos( @_, 1, { default => 99 } );

In scalar context, a hash reference or array reference will be returned, as appropriate.

USAGE NOTES

Validation failure

By default, when validation fails Params::Validate calls Carp::confess(). This can be overridden by setting the on_fail option, which is described in the "GLOBAL" OPTIONS section.

Method calls

When using this module to validate the parameters passed to a method call, you will probably want to remove the class/object from the parameter list before calling validate() or validate_pos(). If your method expects named parameters, then this is necessary for the validate() function to actually work, otherwise @_ will not be usable as a hash, because it will first have your object (or class) followed by a set of keys and values.

Thus the idiomatic usage of validate() in a method call will look something like this:

sub method {
    my $self = shift;

    my %params = validate(
        @_, {
            foo => 1,
            bar => { type => ARRAYREF },
        }
    );
}

Speeding Up Validation

In most cases, the validation spec will remain the same for each call to a subroutine. In that case, you can speed up validation by defining the validation spec just once, rather than on each call to the subroutine:

my %spec = ( ... );
sub foo {
    my %params = validate( @_, \%spec );
}

You can also use the state feature to do this:

use feature 'state';

sub foo {
    state $spec = { ... };
    my %params = validate( @_, $spec );
}

"GLOBAL" OPTIONS

Because the API for the validate() and validate_pos() functions does not make it possible to specify any options other than the validation spec, it is possible to set some options as pseudo-'globals'. These allow you to specify such things as whether or not the validation of named parameters should be case sensitive, for one example.

These options are called pseudo-'globals' because these settings are only applied to calls originating from the package that set the options.

In other words, if I am in package Foo and I call validation_options(), those options are only in effect when I call validate() from package Foo.

While this is quite different from how most other modules operate, I feel that this is necessary in able to make it possible for one module/application to use Params::Validate while still using other modules that also use Params::Validate, perhaps with different options set.

The downside to this is that if you are writing an app with a standard calling style for all functions, and your app has ten modules, each module must include a call to validation_options(). You could of course write a module that all your modules use which uses various trickery to do this when imported.

Options

  • normalize_keys => $callback

    This option is only relevant when dealing with named parameters.

    This callback will be used to transform the hash keys of both the parameters and the parameter spec when validate() or validate_with() are called.

    Any alterations made by this callback will be reflected in the parameter hash that is returned by the validation function. For example:

      sub foo {
          return validate_with(
              params => \@_,
              spec   => { foo => { type => SCALAR } },
              normalize_keys =>
                  sub { my $k = shift; $k =~ s/^-//; return uc $k },
          );
    
      }
    
      %p = foo( foo => 20 );
    
      # $p{FOO} is now 20
    
      %p = foo( -fOo => 50 );
    
      # $p{FOO} is now 50
    

    The callback must return a defined value.

    If a callback is given then the deprecated "ignore_case" and "strip_leading" options are ignored.

  • allow_extra => $boolean

    If true, then the validation routine will allow extra parameters not named in the validation specification. In the case of positional parameters, this allows an unlimited number of maximum parameters (though a minimum may still be set). Defaults to false.

  • on_fail => $callback

    If given, this callback will be called whenever a validation check fails. It will be called with a single parameter, which will be a string describing the failure. This is useful if you wish to have this module throw exceptions as objects rather than as strings, for example.

    This callback is expected to die() internally. If it does not, the validation will proceed onwards, with unpredictable results.

    The default is to simply use the Carp module's confess() function.

  • stack_skip => $number

    This tells Params::Validate how many stack frames to skip when finding a subroutine name to use in error messages. By default, it looks one frame back, at the immediate caller to validate() or validate_pos(). If this option is set, then the given number of frames are skipped instead.

  • ignore_case => $boolean

    DEPRECATED

    This is only relevant when dealing with named parameters. If it is true, then the validation code will ignore the case of parameter names. Defaults to false.

  • strip_leading => $characters

    DEPRECATED

    This too is only relevant when dealing with named parameters. If this is given then any parameters starting with these characters will be considered equivalent to parameters without them entirely. For example, if this is specified as '-', then -foo and foo would be considered identical.

PER-INVOCATION OPTIONS

The validate_with() function can be used to set the options listed above on a per-invocation basis. For example:

my %p = validate_with(
    params => \@_,
    spec   => {
        foo => { type    => SCALAR },
        bar => { default => 10 }
    },
    allow_extra => 1,
);

In addition to the options listed above, it is also possible to set the option "called", which should be a string. This string will be used in any error messages caused by a failure to meet the validation spec.

This subroutine will validate named parameters as a hash if the "spec" parameter is a hash reference. If it is an array reference, the parameters are assumed to be positional.

my %p = validate_with(
    params => \@_,
    spec   => {
        foo => { type    => SCALAR },
        bar => { default => 10 }
    },
    allow_extra => 1,
    called      => 'The Quux::Baz class constructor',
);

my @p = validate_with(
    params => \@_,
    spec   => [
        { type    => SCALAR },
        { default => 10 }
    ],
    allow_extra => 1,
    called      => 'The Quux::Baz class constructor',
);

DISABLING VALIDATION

If the environment variable PERL_NO_VALIDATION is set to something true, then validation is turned off. This may be useful if you only want to use this module during development but don't want the speed hit during production.

The only error that will be caught will be when an odd number of parameters are passed into a function/method that expects a hash.

If you want to selectively turn validation on and off at runtime, you can directly set the $Params::Validate::NO_VALIDATION global variable. It is strongly recommended that you localize any changes to this variable, because other modules you are using may expect validation to be on when they execute. For example:

{
    local $Params::Validate::NO_VALIDATION = 1;

    # no error
    foo( bar => 2 );
}

# error
foo( bar => 2 );

sub foo {
    my %p = validate( @_, { foo => 1 } );
    ...;
}

But if you want to shoot yourself in the foot and just turn it off, go ahead!

SPECIFYING AN IMPLEMENTATION

This module ships with two equivalent implementations, one in XS and one in pure Perl. By default, it will try to load the XS version and fall back to the pure Perl implementation as needed. If you want to request a specific version, you can set the PARAMS_VALIDATE_IMPLEMENTATION environment variable to either XS or PP. If the implementation you ask for cannot be loaded, then this module will die when loaded.

TAINT MODE

The XS implementation of this module has some problems Under taint mode with versions of Perl before 5.14. If validation fails, then instead of getting the expected error message you'll get a message like "Insecure dependency in eval_sv". This can be worked around by either untainting the arguments yourself, using the pure Perl implementation, or upgrading your Perl.

LIMITATIONS

Right now there is no way (short of a callback) to specify that something must be of one of a list of classes, or that it must possess one of a list of methods. If this is desired, it can be added in the future.

Ideally, there would be only one validation function. If someone figures out how to do this, please let me know.

SUPPORT

Bugs may be submitted at https://github.com/houseabsolute/Params-Validate/issues.

SOURCE

The source code repository for Params-Validate can be found at https://github.com/houseabsolute/Params-Validate.

DONATIONS

If you'd like to thank me for the work I've done on this module, please consider making a "donation" to me via PayPal. I spend a lot of free time creating free software, and would appreciate any support you'd care to offer.

Please note that I am not suggesting that you must do this in order for me to continue working on this particular software. I will continue to do so, inasmuch as I have in the past, for as long as it interests me.

Similarly, a donation made in this way will probably not make me work on this software much more, unless I get so many donations that I can consider working on free software full time (let's all have a chuckle at that together).

To donate, log into PayPal and send money to [email protected], or use the button at https://houseabsolute.com/foss-donations/.

AUTHORS

CONTRIBUTORS

COPYRIGHT AND LICENSE

This software is Copyright (c) 2001 - 2022 by Dave Rolsky and Ilya Martynov.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

The full text of the license can be found in the LICENSE file included with this distribution.

params-validate's People

Contributors

andygrundman avatar autarch avatar bessarabov avatar choroba avatar djerius avatar dolmen avatar haarg avatar karenetheridge avatar tonycoz avatar vpit avatar zhtwn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

params-validate's Issues

Error when trying to XS-load

Migrated from rt.cpan.org #43358 (status was 'stalled')

Requestors:

From [email protected] on 2009-02-17 15:10:36
:

When using Params::Validate I get, on Windows, running ActivePerl
v5.8.8, build 820, and having installed Params::Validate v0.91 through
PPM, a message box with an error:


perl.exe - Entry Point Not Found

The procedure entry point Perl_sv_2iv_flags could not be located in the
dynamic link library perl58.dll.

OK

Clicking OK lets my script continue, apparently without error.

I have located the error to come from Params::ValidateXS line 7:

XSLoader::load( 'Params::Validate', $Params::Validate::VERSION );

I expect the script then just uses the PP version...

/Henning

"validate" crashes on a closed IO::Scalar object

Migrated from rt.cpan.org #127811 (status was 'stalled')

Requestors:

From [email protected] on 2018-11-26 17:59:36
:

Hi!

I would like to use Params::Validate's "validate" function to validate an IO::Scalar object. However when an IO::Scalar object is closed, "validate" will always crash regardless of whatever actual validation callbacks are defined.

Here is a minimal code that demonstrates the bug and the results of its execution:

$ cat test.pl
#!/usr/bin/perl

use Data::Dumper;
use IO::Scalar;
use Params::Validate qw(:all);

sub test {
print Dumper @;
validate(@
, { arg => {} });
}

my $var = new IO::Scalar;
$var->close;
test({ arg => $var });
$ ./test.pl
$VAR1 = [
{
'arg' => bless( *IO::Scalar::FH, 'IO::Scalar' )
}
];
Can't use an undefined value as a SCALAR reference at /usr/local/share/perl5/IO/Scalar.pm line 157.
$ echo $?
255

I confirmed it to crash at least since version 1.23. I have got the latest version of IO::Scalar (2.111) installed as well.

I would very much appreciate if this problem could be addressed in the next version of this excellent package.

Many thanks!

Best regards,
Pawel Krol.

XS problem with perl 5.10.0 on Fedora Linux

I'm seeing XS-related failures for all Fedora versions with perl 5.10.0 (Fedora 9 to 12 inclusive):

$ ./Build test
t/00-compile.t .......................... ok
# 
# Versions for all modules listed in MYMETA.json (including optional ones):
# 
# === Configure Requires ===
# 
#     Module        Want   Have
#     ------------- ---- ------
#     Module::Build 0.28 0.4210
# 
# === Build Requires ===
# 
#     Module             Want     Have
#     ------------------ ---- --------
#     ExtUtils::CBuilder  any 0.280220
#     Module::Build      0.28   0.4210
# 
# === Test Requires ===
# 
#     Module              Want   Have
#     ------------------- ---- ------
#     Devel::Peek          any   1.04
#     ExtUtils::MakeMaker  any   6.42
#     File::Spec           any   3.30
#     File::Temp           any   0.21
#     IO::Handle           any   1.27
#     IPC::Open3           any   1.02
#     Test::Fatal          any  0.014
#     Test::More          0.88   0.92
#     Test::Requires       any   0.08
#     Tie::Array           any   1.03
#     Tie::Hash            any   1.02
#     base                 any   2.13
#     lib                  any 0.5565
#     overload             any   1.06
# 
# === Test Recommends ===
# 
#     Module         Want     Have
#     ---------- -------- --------
#     CPAN::Meta 2.120900 2.143240
# 
# === Runtime Requires ===
# 
#     Module                 Want Have
#     ---------------------- ---- ----
#     Attribute::Handlers    0.79 0.79
#     Carp                    any 1.08
#     Exporter                any 5.62
#     Module::Implementation  any 0.09
#     Scalar::Util           1.10 1.21
#     XSLoader                any 0.08
#     attributes              any 0.08
#     strict                  any 1.04
#     vars                    any 1.01
#     warnings                any 1.06
# 
t/00-report-prereqs.t ................... ok

#   Failed test 'expect error with sub10'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^The 'foo' parameter \("20"\) to [\w:]+sub10 did not pass the 'less than 20' callback)'

#   Failed test 'expect error with sub11'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^The 'foo' parameter \("20"\) to [\w:]+sub11 did not pass the 'less than 20' callback)'

#   Failed test 'expect error with sub11'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^The 'foo' parameter \("0"\) to [\w:]+sub11 did not pass the 'more than 0' callback)'

#   Failed test 'expect error with sub12'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^The 'foo' parameter \("ARRAY\(0x[a-f0-9]+\)"\) to [\w:]+sub12 did not pass the '5 elements' callback)'

#   Failed test 'expect error with sub13'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^Parameter #2 \("ARRAY\(0x[a-f0-9]+\)"\) to .* did not pass the '5 elements' callback)'

#   Failed test 'expect error with sub17b'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^2 parameters were passed .* but 3 - 4 were expected)'
# Looks like you failed 6 tests of 93.
t/01-validate.t ......................... 
Dubious, test returned 6 (wstat 1536, 0x600)
Failed 6/93 subtests 
t/02-noop.t ............................. ok

#   Failed test 'Check exception thrown from baz( foo => [1,2,3,4] )'
#   at t/03-attribute.t line 70.
#                   ''
#     doesn't match '(?-xism:The 'foo' parameter .* did not pass the '5 elements' callback)'

#   Failed test 'Check return value from baz( foo => [5,4,3,2,1] )'
#   at t/03-attribute.t line 82.
#          got: undef
#     expected: '5'
# Looks like you failed 2 tests of 10.
t/03-attribute.t ........................ 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/10 subtests 
t/04-defaults.t ......................... ok
t/05-noop_default.t ..................... ok
t/06-options.t .......................... ok
t/07-with.t ............................. ok
t/08-noop_with.t ........................ ok
t/09-regex.t ............................ ok
t/10-noop_regex.t ....................... ok

#   Failed test at t/lib/PVTests/Callbacks.pm line 45.
#                   ''
#     doesn't match '(?-xism:is_allowed)'
# Looks like you failed 1 test of 3.
t/11-cb.t ............................... 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/3 subtests 
t/12-noop_cb.t .......................... ok

#   Failed test 'expect error with sub10'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^The 'foo' parameter \("20"\) to [\w:]+sub10 did not pass the 'less than 20' callback)'

#   Failed test 'expect error with sub11'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^The 'foo' parameter \("20"\) to [\w:]+sub11 did not pass the 'less than 20' callback)'

#   Failed test 'expect error with sub11'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^The 'foo' parameter \("0"\) to [\w:]+sub11 did not pass the 'more than 0' callback)'

#   Failed test 'expect error with sub12'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^The 'foo' parameter \("ARRAY\(0x[a-f0-9]+\)"\) to [\w:]+sub12 did not pass the '5 elements' callback)'

#   Failed test 'expect error with sub13'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^Parameter #2 \("ARRAY\(0x[a-f0-9]+\)"\) to .* did not pass the '5 elements' callback)'

#   Failed test 'expect error with sub17b'
#   at t/lib/PVTests/Standard.pm line 666.
#                   ''
#     doesn't match '(?-xism:^2 parameters were passed .* but 3 - 4 were expected)'
# Looks like you failed 6 tests of 93.
t/13-taint.t ............................ 
Dubious, test returned 6 (wstat 1536, 0x600)
Failed 6/93 subtests 
t/14-no_validate.t ...................... ok
t/15-case.t ............................. ok
t/16-normalize.t ........................ ok

#   Failed test at t/17-callbacks.t line 24.
#                   ''
#     doesn't match '(?-xism:bigger than bar)'

#   Failed test at t/17-callbacks.t line 59.
#                   ''
#     doesn't match '(?-xism:bigger than \[1\])'
# Looks like you failed 2 tests of 4.
t/17-callbacks.t ........................ 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/4 subtests 
t/18-depends.t .......................... ok
t/19-untaint.t .......................... ok
t/21-can.t .............................. ok
t/22-overload-can-bug.t ................. ok
t/23-readonly.t ......................... ok
t/24-tied.t ............................. ok
t/25-undef-regex.t ...................... ok
t/26-isa.t .............................. ok
t/27-string-as-type.t ................... ok
t/28-readonly-return.t .................. ok
t/29-taint-mode.t ....................... ok
t/30-hashref-alteration.t ............... ok
t/31-incorrect-spelling.t ............... skipped: Spec validation is disabled for now
t/32-regex-as-value.t ................... ok
t/33-keep-errsv.t ....................... ok
t/34-recursive-validation.t ............. ok
t/35-default-xs-bug.t ................... ok
Assertion ((svtype)((((*({GV *const shplep = (GV *) ((*Perl_Ierrgv_ptr(((PerlInterpreter *)pthread_getspecific((*Perl_Gthr_key_ptr(((void *)0)))))))); ((((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVGV || ((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVLV) ? ((void) 0) : (Perl_croak_nocontext("Assertion %s failed: file \"" "lib/Params/Validate/XS.xs" "\", line %d", "((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVGV || ((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVLV", 683), (void) 0)); ((((((shplep)->sv_flags & (0x00004000|0x00008000)) == 0x00008000) && (((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVGV || ((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVLV))) ? ((void) 0) : (Perl_croak_nocontext("Assertion %s failed: file \"" "lib/Params/Validate/XS.xs" "\", line %d", "((((shplep)->sv_flags & (0x00004000|0x00008000)) == 0x00008000) && (((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVGV || ((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVLV))", 683), (void) 0)); &((shplep)->sv_u.svu_gp);}))->gp_sv))->sv_flags & 0xff)) >= SVt_PV failed: file "lib/Params/Validate/XS.xs", line 683 at t/36-large-arrays.t line 27.
t/36-large-arrays.t ..................... 
Dubious, test returned 255 (wstat 65280, 0xff00)
No subtests run 
t/37-exports.t .......................... ok

#   Failed test 'got error for bad string'
#   at t/38-callback-message.t line 24.
#                   ''
#     doesn't match '(?-xism:The 'string' parameter \("ARRAY\(.+\)"\) to main::validate1 did not pass the 'string' callback: ARRAY\(.+\) is not a string)'

#   Failed test 'got error for bad pos int (0)'
#   at t/38-callback-message.t line 36.
#                   ''
#     doesn't match '(?-xism:The\ \'pos_int\'\ parameter\ \(\"0\"\)\ to\ main\:\:validate1\ did\ not\ pass\ the\ \'pos_int\'\ callback\:\ 0\ is\ not\ a\ positive\ integer)'

#   Failed test 'got error for bad pos int (bar)'
#   at t/38-callback-message.t line 48.
#                   ''
#     doesn't match '(?-xism:The\ \'pos_int\'\ parameter\ \(\"bar\"\)\ to\ main\:\:validate1\ did\ not\ pass\ the\ \'pos_int\'\ callback\:\ bar\ is\ not\ a\ positive\ integer)'

#   Failed test 'got error for bad string (with $SIG{__DIE__} and $@ set before validate() call)'
#   at t/38-callback-message.t line 66.
#                   ''
#     doesn't match '(?-xism:The 'string' parameter \("ARRAY\(.+\)"\) to main::validate1 did not pass the 'string' callback: ARRAY\(.+\) is not a string)'

#   Failed test 'ref thrown by callback is preserved, not stringified'
#   at t/38-callback-message.t line 91.
#     Structures begin differing at:
#          $got = ''
#     $expected = HASH(0x21b7200)
# Looks like you failed 5 tests of 7.
t/38-callback-message.t ................. 
Dubious, test returned 5 (wstat 1280, 0x500)
Failed 5/7 subtests 
t/author-eol.t .......................... skipped: these tests are for testing by the author
t/author-no-tabs.t ...................... skipped: these tests are for testing by the author
t/author-pod-spell.t .................... skipped: these tests are for testing by the author
t/release-cpan-changes.t ................ skipped: these tests are for release candidate testing
t/release-memory-leak.t ................. skipped: these tests are for release candidate testing
t/release-pod-coverage.t ................ skipped: these tests are for release candidate testing
t/release-pod-linkcheck.t ............... skipped: these tests are for release candidate testing
t/release-pod-no404s.t .................. skipped: these tests are for release candidate testing
t/release-pod-syntax.t .................. skipped: these tests are for release candidate testing
t/release-portability.t ................. skipped: these tests are for release candidate testing
t/release-pp-01-validate.t .............. skipped: these tests are for release testing
t/release-pp-02-noop.t .................. skipped: these tests are for release testing
t/release-pp-03-attribute.t ............. skipped: these tests are for release testing
t/release-pp-04-defaults.t .............. skipped: these tests are for release testing
t/release-pp-05-noop_default.t .......... skipped: these tests are for release testing
t/release-pp-06-options.t ............... skipped: these tests are for release testing
t/release-pp-07-with.t .................. skipped: these tests are for release testing
t/release-pp-08-noop_with.t ............. skipped: these tests are for release testing
t/release-pp-09-regex.t ................. skipped: these tests are for release testing
t/release-pp-10-noop_regex.t ............ skipped: these tests are for release testing
t/release-pp-11-cb.t .................... skipped: these tests are for release testing
t/release-pp-12-noop_cb.t ............... skipped: these tests are for release testing
t/release-pp-13-taint.t ................. skipped: these tests are for release testing
t/release-pp-14-no_validate.t ........... skipped: these tests are for release testing
t/release-pp-15-case.t .................. skipped: these tests are for release testing
t/release-pp-16-normalize.t ............. skipped: these tests are for release testing
t/release-pp-17-callbacks.t ............. skipped: these tests are for release testing
t/release-pp-18-depends.t ............... skipped: these tests are for release testing
t/release-pp-19-untaint.t ............... skipped: these tests are for release testing
t/release-pp-21-can.t ................... skipped: these tests are for release testing
t/release-pp-22-overload-can-bug.t ...... skipped: these tests are for release testing
t/release-pp-23-readonly.t .............. skipped: these tests are for release testing
t/release-pp-24-tied.t .................. skipped: these tests are for release testing
t/release-pp-25-undef-regex.t ........... skipped: these tests are for release testing
t/release-pp-26-isa.t ................... skipped: these tests are for release testing
t/release-pp-27-string-as-type.t ........ skipped: these tests are for release testing
t/release-pp-28-readonly-return.t ....... skipped: these tests are for release testing
t/release-pp-29-taint-mode.t ............ skipped: these tests are for release testing
t/release-pp-30-hashref-alteration.t .... skipped: these tests are for release testing
t/release-pp-31-incorrect-spelling.t .... skipped: these tests are for release testing
t/release-pp-32-regex-as-value.t ........ skipped: these tests are for release testing
t/release-pp-33-keep-errsv.t ............ skipped: these tests are for release testing
t/release-pp-34-recursive-validation.t .. skipped: these tests are for release testing
t/release-pp-35-default-xs-bug.t ........ skipped: these tests are for release testing
t/release-pp-36-large-arrays.t .......... skipped: these tests are for release testing
t/release-pp-37-exports.t ............... skipped: these tests are for release testing
t/release-pp-38-callback-message.t ...... skipped: these tests are for release testing
t/release-pp-is-loaded.t ................ skipped: these tests are for release candidate testing
t/release-synopsis.t .................... skipped: these tests are for release candidate testing
t/release-xs-is-loaded.t ................ skipped: these tests are for release candidate testing
t/release-xs-segfault.t ................. skipped: these tests are for release candidate testing

Test Summary Report
-------------------
t/01-validate.t                       (Wstat: 1536 Tests: 93 Failed: 6)
  Failed tests:  44, 46-47, 49, 52, 68
  Non-zero exit status: 6
t/03-attribute.t                      (Wstat: 512 Tests: 10 Failed: 2)
  Failed tests:  6, 8
  Non-zero exit status: 2
t/11-cb.t                             (Wstat: 256 Tests: 3 Failed: 1)
  Failed test:  2
  Non-zero exit status: 1
t/13-taint.t                          (Wstat: 1536 Tests: 93 Failed: 6)
  Failed tests:  44, 46-47, 49, 52, 68
  Non-zero exit status: 6
t/17-callbacks.t                      (Wstat: 512 Tests: 4 Failed: 2)
  Failed tests:  1, 3
  Non-zero exit status: 2
t/34-recursive-validation.t           (Wstat: 0 Tests: 1 Failed: 0)
  TODO passed:   1
t/36-large-arrays.t                   (Wstat: 65280 Tests: 0 Failed: 0)
  Non-zero exit status: 255
  Parse errors: No plan found in TAP output
t/38-callback-message.t               (Wstat: 1280 Tests: 7 Failed: 5)
  Failed tests:  2-5, 7
  Non-zero exit status: 5
Files=90, Tests=539,  2 wallclock secs ( 0.26 usr  0.12 sys +  2.13 cusr  0.32 csys =  2.83 CPU)
Result: FAIL
Failed 7/90 test programs. 22/539 subtests failed.

Older and newer versions of Fedora pass OK.

If I set PARAMS_VALIDATE_IMPLEMENTATION=PP, the tests pass.

Any ideas? This looks to be Fedora-specific as I see test passes for 5.10.0 on cpantesters.

Here's perl -V for Fedora 12 (x86_64):

$ perl -V
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.6.32-72.el6.bz634452.x86_64, archname=x86_64-linux-thread-multi
    uname='linux x86-05.phx2.fedoraproject.org 2.6.32-72.el6.bz634452.x86_64 #1 smp fri sep 17 06:52:25 edt 2010 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Accflags=-DPERL_USE_SAFE_PUTENV -Dccdlflags=-Wl,--enable-new-dtags -Dversion=5.10.0 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dprivlib=/usr/lib/perl5/5.10.0 -Dsitelib=/usr/local/lib/perl5/site_perl/5.10.0 -Dvendorlib=/usr/lib/perl5/vendor_perl/5.10.0 -Darchlib=/usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi -Dsitearch=/usr/local/lib64/perl5/site_perl/5.10.0/x86_64-linux-thread-multi -Dvendorarch=/usr/lib64/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi -Dinc_version_list=none -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin -Dotherlibdirs=/usr/lib/perl5/site_perl'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='4.4.4 20100630 (Red Hat 4.4.4-10)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =''
    libpth=/usr/local/lib64 /lib64 /usr/lib64
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.11.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,--enable-new-dtags -Wl,-rpath,/usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'


Characteristics of this binary (from libperl): 
  Compile-time options: DEBUGGING MULTIPLICITY PERL_DONT_CREATE_GVSV
                        PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
                        PERL_TRACK_MEMPOOL PERL_USE_SAFE_PUTENV
                        USE_64_BIT_ALL USE_64_BIT_INT USE_ITHREADS
                        USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API
  Built under linux
  Compiled at Oct 12 2010 16:07:51
  @INC:
    /usr/local/lib64/perl5/site_perl/5.10.0/x86_64-linux-thread-multi
    /usr/local/lib/perl5/site_perl/5.10.0
    /usr/lib64/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.10.0
    /usr/lib/perl5/vendor_perl
    /usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi
    /usr/lib/perl5/5.10.0
    /usr/lib/perl5/site_perl
    .

Building Params-Validate

I am trying to build Params-Validate under msys2. I will confess to not being much clear on the Build.PL approach. Most of the other tools use Makefile.PL

I get an error:
fatal error: xlocale.h
#include <xlocale.h>

Suggestions?

Random order of parameters in "Mandatory parameters missing" message

Migrated from rt.cpan.org #115241 (status was 'open')

Requestors:

From [email protected] on 2016-06-10 15:13:23
:

When I get this message:

Mandatory parameters 'x', 'y', 'z' missing in call to Foo::bar

The order of 'x', 'y', 'z' changes each time I run the code. It would be nice if it was sorted so it could be more easily checked in tests.

Using perl 5.22.2, an example:

use Params::Validate qw(:all);
my @in = ();
my %params = validate( @in, {
x => { type => SCALAR },
y => { type => SCALAR },
z => { type => SCALAR },
});

Output on different runs:

Mandatory parameters 'y', 'x', 'z' missing in call to (unknown)
at ./test.pl line 3.

Mandatory parameters 'z', 'x', 'y' missing in call to (unknown)
at ./test.pl line 3.

Mandatory parameters 'x', 'y', 'z' missing in call to (unknown)
at ./test.pl line 3.

Params::Validate 1.25 fails to build on Windows with VC compiled perl

C:\...\Params-Validate-1.25> perl Makefile.PL
you are using MSVC... we may not have gotten some options quite right. at Makefile.PL line 101.
you are using MSVC... we may not have gotten some options quite right. at Makefile.PL line 101.
Generating a nmake-style Makefile
Writing Makefile for Params::Validate
Writing MYMETA.yml and MYMETA.json

C:\Users\sinan\.cpanm\work\1474974679.3012\Params-Validate-1.25> nmake test

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Running Mkbootstrap for XS ()
        "C:\opt\perl\5.25.4\bin\perl.exe" -MExtUtils::Command -e chmod -- 644 "XS.bs"
        "C:\opt\perl\5.25.4\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- XS.bs blib\arch\auto\Params/Validate/XS\XS.bs 644
        cl -c  -I.  -nologo -GF -W3 -O2 -favor:INTEL64 -Qpar -MD -Zi -DNDEBUG -GL -fp:precise -DWIN32 -D_CONSOLE -DNO_STRICT -DWIN64 -DCONSERVATIVE -D_CRT_SECU
RE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DWIN32_NO_REGISTRY -O2 -favor:INTEL64 -Qpar -M
D -Zi -DNDEBUG -GL -fp:precise    -DVERSION=\"1.25\"  -DXS_VERSION=\"1.25\" /Folib/Params/Validate/XS.obj  "-IC:\opt\perl\5.25.4\lib\CORE"   lib/Params/Validat
e/XS.c
XS.c
lib/Params/Validate/XS.xs(335) : warning C4244: 'function' : conversion from 'IV' to 'I32', possible loss of data
lib/Params/Validate/XS.xs(824) : warning C4244: '=' : conversion from '__int64' to 'I32', possible loss of data
lib/Params/Validate/XS.xs(1075) : warning C4267: 'function' : conversion from 'size_t' to 'I32', possible loss of data
lib/Params/Validate/XS.xs(1082) : warning C4267: 'function' : conversion from 'size_t' to 'I32', possible loss of data
        "C:\opt\perl\5.25.4\bin\perl.exe" -MExtUtils::Mksymlists  -e "Mksymlists('NAME'=>\"Params::Validate\", 'DLBASE' => 'XS', 'DL_FUNCS' => {  }, 'FUNCLIST'
 => [], 'IMPORTS' => {  }, 'DL_VARS' => []);"
        link -out:blib\arch\auto\Params/Validate/XS\XS.dll -dll -nologo -nodefaultlib -debug -opt:ref,icf -ltcg  -libpath:"c:\opt\perl\5.25.4\lib\CORE"  -machi
ne:AMD64 -subsystem:console,"5.02" lib/Params/Validate/XS.obj   "C:\opt\perl\5.25.4\lib\CORE\perl525.lib" oldnames.lib kernel32.lib user32.lib gdi32.lib winspo
ol.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib c
omctl32.lib msvcrt.lib -def:XS.def
LINK : fatal error LNK1104: cannot open file 'XS.def'
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\link.EXE"' : return code '0x450'
Stop.                                                                                                                                                        ```

Perl 5.38: Bareword "UNDEF/GLOB/SCALAR/OBJECT/UNKNOWN" not allowed while "strict subs" in use

We recently installed Perl 5.38 and tried to install all the CPAN modules we use under our older Perl installation. Our tests with Params::Validate::PP (version 1.31) revealed the following compilation error when trying to use it:

Bareword "UNDEF" not allowed while "strict subs" in use at /usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm line 614.
Bareword "GLOB" not allowed while "strict subs" in use at /usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm line 620.
Bareword "SCALAR" not allowed while "strict subs" in use at /usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm line 621.
Bareword "OBJECT" not allowed while "strict subs" in use at /usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm line 627.
Bareword "UNKNOWN" not allowed while "strict subs" in use at /usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm line 631.
Bareword "ARRAYREF" not allowed while "strict subs" in use at /usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm line 603.
Bareword "HASHREF" not allowed while "strict subs" in use at /usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm line 603.
Bareword "CODEREF" not allowed while "strict subs" in use at /usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm line 603.
Bareword "GLOBREF" not allowed while "strict subs" in use at /usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm line 603.
Bareword "SCALARREF" not allowed while "strict subs" in use at /usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm line 603.
/usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm has too many errors.
Compilation failed in require.
BEGIN failed--compilation aborted.

I fixed this by making the following changes (adding no strict "subs"; and removing the parentheses after the constants on the indicated lines):

--- /usr/local/perl5/5.38.0/lib/site_perl/5.38.0/x86_64-linux/Params/Validate/PP.pm    2023-08-07 16:57:51.000000000 -0400
+++ PP.pm 2023-08-14 18:41:45.068623000 -0400
@@ -3,0 +4 @@
+no strict 'subs';
@@ -637,10 +638,10 @@
-        SCALAR()    => 'scalar',
-        ARRAYREF()  => 'arrayref',
-        HASHREF()   => 'hashref',
-        CODEREF()   => 'coderef',
-        GLOB()      => 'glob',
-        GLOBREF()   => 'globref',
-        SCALARREF() => 'scalarref',
-        UNDEF()     => 'undef',
-        OBJECT()    => 'object',
-        UNKNOWN()   => 'unknown',
+        SCALAR    => 'scalar',
+        ARRAYREF  => 'arrayref',
+        HASHREF   => 'hashref',
+        CODEREF   => 'coderef',
+        GLOB      => 'glob',
+        GLOBREF   => 'globref',
+        SCALARREF => 'scalarref',
+        UNDEF     => 'undef',
+        OBJECT    => 'object',
+        UNKNOWN   => 'unknown',

So you're probably asking "Why is this person using Params::Validate::PP and not Params::Validate (or even Params::ValidationCompiler)?" Well, it's complicated, but, long ago, I found it easier to extend Params::Validate::PP because, well, it's pure Perl.

Would you like me to submit a PR?

Crash bug

Migrated from rt.cpan.org #61692 (status was 'stalled')

Requestors:

From [email protected] (@dams) on 2010-09-27 13:05:25
:

I'm using Params::ValidatePP in conjonction with Log4Perl in this
situation :

I use Params::Validate from my module Foo, with the option allow_extra => 0.
when a parameter validation fails, I catch the DIE signal to log the
error to file, using Log4Perl. Log4Perl, in some methods, uses
Param::Validate to check parameters, with configuration allow_extra => 1.

The clever mechanism to have the Params::Validate configuration per
module is short-circuited with this line which appears in multiple
places, e.g. in the sub validate (line 213) :

local $options = _get_options( (caller(0))[0] ) unless defined $options;

In my case, $options is already set, but that's the setting of the
original module where the first error originated : Foo. These settings
are however used when validating params for a call from Log4Perl.

So, settings fro Foo are used instead of settings for Log4Perl. It then
crashes, because allow_extra is 0, instead of 1.

I think that not using 'local', and passing around the $options variable
should fix the issue.

Params::Validate install error

Migrated from rt.cpan.org #131303 (status was 'stalled')

Requestors:

From [email protected] on 2019-12-30 19:58:33
:

Hi�I want install you package Params::Validate,but I don�t know how to solve the problem -> �ld.exe: cannot find -lperl530�; my system is windows,command is cpanm Params::Validate,and add �force is not help,hope you can teach me solve this problem.

Errors are shown below:


C:\Users\wenger>cpanm Params::Validate
--> Working on Params::Validate
Fetching http://www.cpan.org/authors/id/D/DR/DROLSKY/Params-Validate-1.29.tar.gz ... OK
Configuring Params-Validate-1.29 ... OK
Building and testing Params-Validate-1.29 ... FAIL
! Installing Params::Validate failed. See C:\Users\wenger.cpanm\work\1577735160.9132\build.log for details. Retry with --force to force install it.


The build file�

cpanm (App::cpanminus) 1.7044 on perl 5.030001 built for MSWin32-x64-multi-thread
Work directory is C:\Users\wenger/.cpanm/work/1577734257.11428
You have make D:\PERL\c\bin\gmake.exe
You have LWP 6.42
You have C:\windows\system32\tar.exe, D:\latex\TEXLIVE\bin\win32\gzip.exe and D:\Git\mingw64\bin\bzip2.exe
You have D:\latex\TEXLIVE\bin\win32\unzip.exe
Searching Params::Validate () on cpanmetadb ...
--> Working on Params::Validate
Fetching http://www.cpan.org/authors/id/D/DR/DROLSKY/Params-Validate-1.29.tar.gz
-> OK
Unpacking Params-Validate-1.29.tar.gz
Entering Params-Validate-1.29
Checking configure dependencies from META.json
Checking if you have ExtUtils::Install 1.46 ... Yes (2.14)
Checking if you have Module::Build 0.38 ... Yes (0.4229)
Configuring Params-Validate-1.29
Running Build.PL
D:/PERL/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lperl530
collect2.exe: error: ld returned 1 exit status
D:/PERL/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lperl530
collect2.exe: error: ld returned 1 exit status
Created MYMETA.yml and MYMETA.json
Creating new 'Build' script for 'Params-Validate' version '1.29'
-> OK
Checking dependencies from MYMETA.json ...
Checking if you have strict 0 ... Yes (1.11)
Checking if you have Exporter 0 ... Yes (5.73)
Checking if you have lib 0 ... Yes (0.65)
Checking if you have Tie::Array 0 ... Yes (1.07)
Checking if you have base 0 ... Yes (2.27)
Checking if you have File::Temp 0 ... Yes (0.2309)
Checking if you have Tie::Hash 0 ... Yes (1.05)
Checking if you have Carp 0 ... Yes (1.50)
Checking if you have Scalar::Util 1.10 ... Yes (1.53)
Checking if you have Test::Requires 0 ... Yes (0.10)
Checking if you have Test::Fatal 0 ... Yes (0.014)
Checking if you have File::Spec 0 ... Yes (3.78)
Checking if you have vars 0 ... Yes (1.05)
Checking if you have warnings 0 ... Yes (1.44)
Checking if you have ExtUtils::MakeMaker 0 ... Yes (7.38)
Checking if you have Test::More 0.96 ... Yes (1.302169)
Checking if you have ExtUtils::CBuilder 0 ... Yes (0.280231)
Checking if you have Module::Build 0.28 ... Yes (0.4229)
Checking if you have XSLoader 0 ... Yes (0.30)
Checking if you have Module::Implementation 0 ... Yes (0.09)
Checking if you have overload 0 ... Yes (1.30)
Checking if you have Devel::Peek 0 ... Yes (1.28)
Building and testing Params-Validate-1.29
Building Params-Validate
gcc -c -I"c" -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -D__USE_MINGW_ANSI_STDIO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields -s -O2 "-DVERSION="1.29"" "-DXS_VERSION="1.29"" -I"C:\strawberry\perl\lib\CORE" -I"C:\strawberry\c\include" -o "lib\Params\Validate\XS.o" "lib\Params\Validate\XS.c"
lib\Params\Validate\XS.xs:3:10: fatal error: EXTERN.h: No such file or directory
#include "EXTERN.h"
^~~~~~~~~~
compilation terminated.
error building xs.dll file from 'lib\Params\Validate\XS.c' at D:/PERL/perl/lib/ExtUtils/CBuilder/Platform/Windows.pm line 128.
-> FAIL Installing Params::Validate failed. See C:\Users\wenger.cpanm\work\1577734257.11428\build.log for details. Retry with --force to force install it.

��� Windows 10 ��件https://go.microsoft.com/fwlink/?LinkId=550986��

Strange XS return value

Migrated from rt.cpan.org #106709 (status was 'stalled')

Requestors:

Attachments:

From [email protected] on 2015-08-28 14:29:29
:

Hello ,

I work with Params ::Validate quite a lot, and got recently a strange
behavior with one callback checking.

Somewhere on my program, I call validate with a callback check who can call
thousands line of code, and use a lot of library.

In 99% of case, all work fine. But there is a very much particular (I can
reproduce) which lead validate returning undef without failing. In that
case, the callback do return 1.

Plus, when I call Data::Dumper on $_[1] inside that callback, it is recalled
just after it ends infinitely.

So I wonder, do validate is a safely reentrant method ? Or is that something
else I do wrong ?

I�m sorry I can�t put some code here, for some obvious reason. Here is some
information about the system :

Perl version 5.16.3

Some module used :

  •      Rose::DB and Rose::DB::Object
    
  •      Log4perl
    
  •      DBI
    
  •      JSON
    

Note : that using the PP implementation works fine.

David IMBS

Réalisteur

Tél : 02.99.12.54.06 - 02.99.12.71.71

Fax : 02.99.12.71.72

12 L Rue du Patis Tatelin � 35700 RENNES

mailto:[email protected] [email protected]

Description : cid:[email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.