From e3f76a2d0f8707d64d7735585f045b10a6e68e4f Mon Sep 17 00:00:00 2001 From: Jens Rehsack Date: Sat, 2 May 2026 14:07:45 +0200 Subject: [PATCH 1/8] Add _CLASSCAN, _INSTANCECAN and _INVOCANTCAN predicates Resolve the `UNIVERSAL::can` debacle by providing predicates that call `->can` as a method rather than as a function, respecting any overridden `can()` in the invocant's class hierarchy. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Jens Rehsack --- Util.xs | 48 +++++++++++++++++++++++++++++ lib/Params/Util.pm | 32 +++++++++++++++++--- lib/Params/Util/PP.pm | 17 +++++++++++ t/pp/02_main.t | 70 ++++++++++++++++++++++++++++++++++++++++++- t/xs/02_main.t | 70 ++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 231 insertions(+), 6 deletions(-) diff --git a/Util.xs b/Util.xs index 4ec6ca7..9548247 100644 --- a/Util.xs +++ b/Util.xs @@ -367,6 +367,54 @@ CODE: XSRETURN_UNDEF; } +void +_INSTANCECAN(ref,method) + SV *ref; + char *method; +PROTOTYPE: $$ +CODE: +{ + STRLEN len; + if( SvMAGICAL(ref) ) + mg_get(ref); + if( SvROK(ref) && method && ( ( len = strlen(method) ) > 0 ) ) + { + if( sv_isobject(ref) ) + { + I32 has_method = 0; + int count; + + ENTER; + SAVETMPS; + PUSHMARK(SP); + XPUSHs( sv_2mortal( newSVsv( ref ) ) ); + XPUSHs( sv_2mortal( newSVpv( method, len ) ) ); + PUTBACK; + + if( ( count = call_method("can", G_SCALAR) ) ) + { + I32 oldax = ax; + SPAGAIN; + SP -= count; + ax = (SP - PL_stack_base) + 1; + has_method = SvTRUE(ST(0)); + ax = oldax; + } + + PUTBACK; + FREETMPS; + LEAVE; + + if( has_method ) + { + ST(0) = ref; + XSRETURN(1); + } + } + } + XSRETURN_UNDEF; +} + void _XScompiled () CODE: diff --git a/lib/Params/Util.pm b/lib/Params/Util.pm index bab5bf3..e50e65d 100755 --- a/lib/Params/Util.pm +++ b/lib/Params/Util.pm @@ -69,13 +69,14 @@ XSLoader::load("Params::Util", $VERSION) unless $ENV{PERL_PARAMS_UTIL_PP}; our @EXPORT_OK = qw{ _STRING _IDENTIFIER - _CLASS _CLASSISA _SUBCLASS _DRIVER _CLASSDOES + _CLASS _CLASSISA _CLASSCAN _SUBCLASS _DRIVER _CLASSDOES _NUMBER _POSINT _NONNEGINT _SCALAR _SCALAR0 _ARRAY _ARRAY0 _ARRAYLIKE _HASH _HASH0 _HASHLIKE _CODE _CODELIKE - _INVOCANT _REGEX _INSTANCE _INSTANCEDOES + _INVOCANT _INVOCANTCAN + _REGEX _INSTANCE _INSTANCEDOES _INSTANCECAN _SET _SET0 _HANDLE }; @@ -157,6 +158,17 @@ This routine behaves exactly like C>, but checks with C<< ->DOES 5.10 or later, when L has been implemented. +=head2 _CLASSCAN $string, $method + +The C<_CLASSCAN> function tests whether a value is a valid class name that +provides a particular method via C<< ->can >>. + +This avoids calling C as a function, which is considered +problematic because it bypasses any overridden C method. + +Returns the string as a convenience if it is a valid class name that provides +the method, or C if not. + =head2 _SUBCLASS $string, $class The C<_SUBCLASS> function is intended to be imported into your @@ -373,6 +385,20 @@ This routine behaves exactly like C>, but checks with C<< ->DOES 5.10 or later, when L has been implemented. +=head2 _INSTANCECAN $object, $method + +This routine behaves exactly like C>, but checks with C<< ->can +>> rather than C<< ->isa >>. Returns the object as a convenience if it is +blessed and provides the specified method, or C if not. + +=head2 _INVOCANTCAN $value, $method + +Tests whether the given value is a valid method invocant (class name or +blessed object) that provides a particular method via C<< ->can >>. + +Returns the value itself as a convenience, or C if the value is not +a valid invocant or does not provide the method. + =head2 _REGEX $value The C<_REGEX> function is intended to be imported into your package, @@ -446,8 +472,6 @@ or the class fails the isa test. =head1 TO DO -- Add _CAN to help resolve the UNIVERSAL::can debacle - - Implement an assertion-like version of this module, that dies on error. diff --git a/lib/Params/Util/PP.pm b/lib/Params/Util/PP.pm index 1c7f758..e024294 100644 --- a/lib/Params/Util/PP.pm +++ b/lib/Params/Util/PP.pm @@ -70,6 +70,11 @@ sub _CLASSDOES ($$) return (defined $_[0] and not ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s and $_[0]->DOES($_[1])) ? $_[0] : undef; } +sub _CLASSCAN ($$) +{ + return (defined $_[0] and not ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s and $_[0]->can($_[1])) ? $_[0] : undef; +} + sub _SUBCLASS ($$) { return (defined $_[0] and not ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s and $_[0] ne $_[1] and $_[0]->isa($_[1])) @@ -178,6 +183,18 @@ sub _INSTANCEDOES ($$) return (Scalar::Util::blessed($_[0]) and $_[0]->DOES($_[1])) ? $_[0] : undef; } +sub _INSTANCECAN ($$) +{ + return (Scalar::Util::blessed($_[0]) and $_[0]->can($_[1])) ? $_[0] : undef; +} + +sub _INVOCANTCAN ($$) +{ + return (defined $_[0] and (Scalar::Util::blessed($_[0]) or _CLASS($_[0])) and $_[0]->can($_[1])) + ? $_[0] + : undef; +} + sub _REGEX ($) { return (defined $_[0] and 'Regexp' eq ref($_[0])) ? $_[0] : undef; diff --git a/t/pp/02_main.t b/t/pp/02_main.t index 14ae307..55ad569 100644 --- a/t/pp/02_main.t +++ b/t/pp/02_main.t @@ -9,7 +9,7 @@ BEGIN $ENV{PERL_PARAMS_UTIL_PP} ||= 1; } -use Test::More tests => 720; +use Test::More tests => 770; use File::Spec::Functions ':ALL'; use Scalar::Util 'refaddr'; use Params::Util (); @@ -726,6 +726,74 @@ SKIP: } } +##################################################################### +# Tests for _CLASSCAN + +use_ok('Params::Util', '_CLASSCAN'); +ok(defined *_CLASSCAN{CODE}, '_CLASSCAN imported ok'); + +# Bad values +null(_CLASSCAN(undef, 'foo'), '_CLASSCAN(undef, method) returns undef'); +null(_CLASSCAN('', 'foo'), '_CLASSCAN(empty, method) returns undef'); +null(_CLASSCAN({}, 'foo'), '_CLASSCAN(HASH, method) returns undef'); +null(_CLASSCAN([], 'foo'), '_CLASSCAN(ARRAY, method) returns undef'); +null(_CLASSCAN('4bad', 'foo'), '_CLASSCAN(bad class, method) returns undef'); + +# Class without the method +null(_CLASSCAN('Bad', 'foo'), '_CLASSCAN(Bad, foo) returns undef'); + +# Class with the method +is(_CLASSCAN('Foo', 'foo'), 'Foo', '_CLASSCAN(Foo, foo) returns class name'); +is(_CLASSCAN('Bar', 'foo'), 'Bar', '_CLASSCAN(Bar, foo) returns class name (inherited)'); + +##################################################################### +# Tests for _INSTANCECAN + +use_ok('Params::Util', '_INSTANCECAN'); +ok(defined *_INSTANCECAN{CODE}, '_INSTANCECAN imported ok'); + +# Bad values +null(_INSTANCECAN(undef, 'foo'), '_INSTANCECAN(undef, method) returns undef'); +null(_INSTANCECAN('Foo', 'foo'), '_INSTANCECAN(class string, method) returns undef'); +null(_INSTANCECAN({}, 'foo'), '_INSTANCECAN(unblessed HASH, method) returns undef'); +null(_INSTANCECAN(bless({}, 'Bad'), 'foo'), '_INSTANCECAN(bad object, foo) returns undef'); + +# Baz fakes isa('Foo') but does not actually provide 'foo' +null(_INSTANCECAN(bless({}, 'Baz'), 'foo'), '_INSTANCECAN(Baz object, foo) returns undef'); + +# Good values - only objects whose class genuinely provides 'foo' +foreach my $object (grep { $_->can('foo') } @objects) +{ + ok(_INSTANCECAN($object, 'foo'), '_INSTANCECAN(object, foo) returns true when expected'); + is(refaddr(_INSTANCECAN($object, 'foo')), refaddr($object), '_INSTANCECAN(object, foo) returns the same object'); +} + +##################################################################### +# Tests for _INVOCANTCAN + +use_ok('Params::Util', '_INVOCANTCAN'); +ok(defined *_INVOCANTCAN{CODE}, '_INVOCANTCAN imported ok'); + +# Bad values +null(_INVOCANTCAN(undef, 'foo'), '_INVOCANTCAN(undef, method) returns undef'); +null(_INVOCANTCAN('', 'foo'), '_INVOCANTCAN(empty, method) returns undef'); +null(_INVOCANTCAN({}, 'foo'), '_INVOCANTCAN(unblessed HASH, method) returns undef'); +null(_INVOCANTCAN('Bad', 'foo'), '_INVOCANTCAN(Bad, foo) returns undef'); +null(_INVOCANTCAN(bless({}, 'Bad'), 'foo'), '_INVOCANTCAN(bad object, foo) returns undef'); + +# Good values - class +is(_INVOCANTCAN('Foo', 'foo'), 'Foo', '_INVOCANTCAN(Foo class, foo) returns class name'); + +# Baz fakes isa but does not provide 'foo' +null(_INVOCANTCAN(bless({}, 'Baz'), 'foo'), '_INVOCANTCAN(Baz object, foo) returns undef'); + +# Good values - object +foreach my $object (grep { $_->can('foo') } @objects) +{ + ok(_INVOCANTCAN($object, 'foo'), '_INVOCANTCAN(object, foo) returns true when expected'); + is(refaddr(_INVOCANTCAN($object, 'foo')), refaddr($object), '_INVOCANTCAN(object, foo) returns the same object'); +} + ##################################################################### # Tests for _REGEX diff --git a/t/xs/02_main.t b/t/xs/02_main.t index bb05c4a..e75ee91 100644 --- a/t/xs/02_main.t +++ b/t/xs/02_main.t @@ -9,7 +9,7 @@ BEGIN $ENV{PERL_PARAMS_UTIL_PP} ||= 0; } -use Test::More tests => 720; +use Test::More tests => 770; use File::Spec::Functions ':ALL'; use Scalar::Util 'refaddr'; use Params::Util (); @@ -726,6 +726,74 @@ SKIP: } } +##################################################################### +# Tests for _CLASSCAN + +use_ok('Params::Util', '_CLASSCAN'); +ok(defined *_CLASSCAN{CODE}, '_CLASSCAN imported ok'); + +# Bad values +null(_CLASSCAN(undef, 'foo'), '_CLASSCAN(undef, method) returns undef'); +null(_CLASSCAN('', 'foo'), '_CLASSCAN(empty, method) returns undef'); +null(_CLASSCAN({}, 'foo'), '_CLASSCAN(HASH, method) returns undef'); +null(_CLASSCAN([], 'foo'), '_CLASSCAN(ARRAY, method) returns undef'); +null(_CLASSCAN('4bad', 'foo'), '_CLASSCAN(bad class, method) returns undef'); + +# Class without the method +null(_CLASSCAN('Bad', 'foo'), '_CLASSCAN(Bad, foo) returns undef'); + +# Class with the method +is(_CLASSCAN('Foo', 'foo'), 'Foo', '_CLASSCAN(Foo, foo) returns class name'); +is(_CLASSCAN('Bar', 'foo'), 'Bar', '_CLASSCAN(Bar, foo) returns class name (inherited)'); + +##################################################################### +# Tests for _INSTANCECAN + +use_ok('Params::Util', '_INSTANCECAN'); +ok(defined *_INSTANCECAN{CODE}, '_INSTANCECAN imported ok'); + +# Bad values +null(_INSTANCECAN(undef, 'foo'), '_INSTANCECAN(undef, method) returns undef'); +null(_INSTANCECAN('Foo', 'foo'), '_INSTANCECAN(class string, method) returns undef'); +null(_INSTANCECAN({}, 'foo'), '_INSTANCECAN(unblessed HASH, method) returns undef'); +null(_INSTANCECAN(bless({}, 'Bad'), 'foo'), '_INSTANCECAN(bad object, foo) returns undef'); + +# Baz fakes isa('Foo') but does not actually provide 'foo' +null(_INSTANCECAN(bless({}, 'Baz'), 'foo'), '_INSTANCECAN(Baz object, foo) returns undef'); + +# Good values - only objects whose class genuinely provides 'foo' +foreach my $object (grep { $_->can('foo') } @objects) +{ + ok(_INSTANCECAN($object, 'foo'), '_INSTANCECAN(object, foo) returns true when expected'); + is(refaddr(_INSTANCECAN($object, 'foo')), refaddr($object), '_INSTANCECAN(object, foo) returns the same object'); +} + +##################################################################### +# Tests for _INVOCANTCAN + +use_ok('Params::Util', '_INVOCANTCAN'); +ok(defined *_INVOCANTCAN{CODE}, '_INVOCANTCAN imported ok'); + +# Bad values +null(_INVOCANTCAN(undef, 'foo'), '_INVOCANTCAN(undef, method) returns undef'); +null(_INVOCANTCAN('', 'foo'), '_INVOCANTCAN(empty, method) returns undef'); +null(_INVOCANTCAN({}, 'foo'), '_INVOCANTCAN(unblessed HASH, method) returns undef'); +null(_INVOCANTCAN('Bad', 'foo'), '_INVOCANTCAN(Bad, foo) returns undef'); +null(_INVOCANTCAN(bless({}, 'Bad'), 'foo'), '_INVOCANTCAN(bad object, foo) returns undef'); + +# Good values - class +is(_INVOCANTCAN('Foo', 'foo'), 'Foo', '_INVOCANTCAN(Foo class, foo) returns class name'); + +# Baz fakes isa but does not provide 'foo' +null(_INVOCANTCAN(bless({}, 'Baz'), 'foo'), '_INVOCANTCAN(Baz object, foo) returns undef'); + +# Good values - object +foreach my $object (grep { $_->can('foo') } @objects) +{ + ok(_INVOCANTCAN($object, 'foo'), '_INVOCANTCAN(object, foo) returns true when expected'); + is(refaddr(_INVOCANTCAN($object, 'foo')), refaddr($object), '_INVOCANTCAN(object, foo) returns the same object'); +} + ##################################################################### # Tests for _REGEX From aae6512930c71e1c3c0a02cc0b2e2918f4efb564 Mon Sep 17 00:00:00 2001 From: Jens Rehsack Date: Sat, 2 May 2026 14:29:12 +0200 Subject: [PATCH 2/8] Replace hand-maintained t/pp and t/xs with Test::WriteVariants Maintaining two near-identical test trees violated DRY and SPOT. Canonical tests now live in t/inline/; Sandbox/Tumble.pm generates the backend-specific variants during `perl Makefile.PL`. See lib/Params/Util/ADR-001.pod for the full rationale. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Jens Rehsack --- .gitignore | 2 + MANIFEST.SKIP | 2 +- Makefile.PL | 15 +- Sandbox/Tumble.pm | 60 ++ lib/Params/Util/ADR-001.pod | 86 +++ t/{pp => inline}/01_compile.t | 1 - t/{pp => inline}/02_main.t | 1 - t/{pp => inline}/03_all.t | 1 - t/{xs => inline}/04_codelike.t | 1 - t/{pp => inline}/05_typelike.t | 1 - t/{pp => inline}/06_invocant.t | 1 - t/{pp => inline}/07_handle.t | 1 - t/{xs => inline}/08_driver.t | 1 - t/{pp => inline}/09_insideout.t | 1 - t/pp/04_codelike.t | 130 ----- t/pp/08_driver.t | 118 ---- t/xs/01_compile.t | 22 - t/xs/02_main.t | 944 -------------------------------- t/xs/03_all.t | 56 -- t/xs/05_typelike.t | 127 ----- t/xs/06_invocant.t | 92 ---- t/xs/07_handle.t | 94 ---- t/xs/09_insideout.t | 52 -- xt/perltidy.t | 3 +- xt/spelling.t | 1 + 25 files changed, 165 insertions(+), 1648 deletions(-) create mode 100644 Sandbox/Tumble.pm create mode 100644 lib/Params/Util/ADR-001.pod rename t/{pp => inline}/01_compile.t (91%) mode change 100755 => 100644 rename t/{pp => inline}/02_main.t (99%) rename t/{pp => inline}/03_all.t (97%) mode change 100755 => 100644 rename t/{xs => inline}/04_codelike.t (98%) rename t/{pp => inline}/05_typelike.t (98%) rename t/{pp => inline}/06_invocant.t (98%) rename t/{pp => inline}/07_handle.t (98%) rename t/{xs => inline}/08_driver.t (99%) rename t/{pp => inline}/09_insideout.t (95%) delete mode 100644 t/pp/04_codelike.t delete mode 100644 t/pp/08_driver.t delete mode 100755 t/xs/01_compile.t delete mode 100644 t/xs/02_main.t delete mode 100755 t/xs/03_all.t delete mode 100644 t/xs/05_typelike.t delete mode 100644 t/xs/06_invocant.t delete mode 100644 t/xs/07_handle.t delete mode 100644 t/xs/09_insideout.t diff --git a/.gitignore b/.gitignore index 0d8cfe8..480913d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ pm_to_blib inc/inc_* inc/latest* Params-Util-* +t/pp/ +t/xs/ diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index 7537f13..210a299 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -22,7 +22,7 @@ _Inline/.* ^tmp/ ^testdata/ ^blib/ -^sandbox/ +^[Ss]andbox/ ^pm_to_blib$ ^cover_db/ nytprof*/ diff --git a/Makefile.PL b/Makefile.PL index 96461d4..49d8dfb 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -16,6 +16,17 @@ BEGIN use inc::latest 'Capture::Tiny'; use inc::latest 'Config::AutoConf'; +if (-d 'Sandbox') +{ + eval "use Sandbox::Tumble ();"; + $@ and die $@; + eval "use File::Path ();"; + File::Path->import; + -d 't/pp' and rmtree('t/pp'); + -d 't/xs' and rmtree('t/xs'); + Sandbox::Tumble->tumble(qw(t)); +} + unless (-f "META.yml") { if (inc::latest->can("write")) @@ -98,6 +109,7 @@ WriteMakefile1( 'Test::Pod::Coverage' => 0, 'Test::Pod::Spelling::CommonMistakes' => 0, 'Test::Spelling' => 0, + 'Test::WriteVariants' => '0.014', }, }, configure => { @@ -122,7 +134,8 @@ WriteMakefile1( depend => {'$(FIRST_MAKEFILE)' => '$(VERSION_FROM)'}, test => {TESTS => join(' ', 't/pp/*.t', ($loadable_xs ? 't/xs/*.t' : ()), 'xt/*.t')}, # Otherwise 'cxinc' isn't defined - ($] < 5.012 ? (DEFINE => '-DPERL_EXT') : (),), + ($] < 5.012 ? (DEFINE => '-DPERL_EXT') : (),), + (-d 'Sandbox' ? (realclean => {FILES => join(' ', 't/pp', 't/xs')}) : ()), ); sub WriteMakefile1 diff --git a/Sandbox/Tumble.pm b/Sandbox/Tumble.pm new file mode 100644 index 0000000..e5ff984 --- /dev/null +++ b/Sandbox/Tumble.pm @@ -0,0 +1,60 @@ +package Sandbox::Tumble; + +use strict; +use warnings; + +use Cwd qw(); +use File::Spec qw(); +use Test::WriteVariants 0.014; + +use FindBin qw(); + +$| = 1; + +sub tumble +{ + my ($class, $output_dir) = @_; + + my $template_dir = Cwd::abs_path(File::Spec->catdir($FindBin::RealBin, "t")); + my $test_writer = Test::WriteVariants->new(); + $test_writer->allow_dir_overwrite(1); + $test_writer->allow_file_overwrite(1); + + $test_writer->write_test_variants( + input_tests => $test_writer->find_input_inline_tests( + search_patterns => ["*.t"], + search_dirs => ["t/inline"], + ), + variant_providers => ["PU::TestVariants"], + output_dir => $output_dir, + ); +} + +package PU::TestVariants::Backend; + +use strict; +use warnings; + +sub provider +{ + my ($self, $path, $context, $tests, $variants) = @_; + my $strict = $context->new_module_use(strict => [qw(subs vars refs)]); + my $warnings = $context->new_module_use(warnings => ['all']); + + $variants->{pp} = $context->new( + $context->new_env_var( + PERL_PARAMS_UTIL_PP => 1, + ), + $warnings, + $strict, + ); + $variants->{xs} = $context->new( + $context->new_env_var( + PERL_PARAMS_UTIL_PP => 0, + ), + $warnings, + $strict, + ); +} + +1; diff --git a/lib/Params/Util/ADR-001.pod b/lib/Params/Util/ADR-001.pod new file mode 100644 index 0000000..59f0922 --- /dev/null +++ b/lib/Params/Util/ADR-001.pod @@ -0,0 +1,86 @@ +=head1 ADR-001: DRY and SPOT using Test::WriteVariants + +=head2 Status + +Accepted + +=head2 Context + +Params::Util ships both a Pure-Perl (PP) and an XS implementation. Both +must be tested with the same test logic; the only difference is which +backend is active, controlled via C<$ENV{PERL_PARAMS_UTIL_PP}>. + +Historically the test suite maintained two parallel directory trees +(F and F) with near-identical content. The sole +difference was a single line in each file's C block setting the +environment variable to C<1> or C<0>. + +This violated both DRY (Don't Repeat Yourself) and SPOT (Single Point +of Truth): every test change had to be applied twice, and divergence +between the two trees was a recurring source of subtle bugs and wasted +review effort. + +Hash-Merge (a sibling distribution maintained by the same author) +already solved this problem using L. + +=head2 Decision + +Adopt the L pattern established in Hash-Merge: + +=over 4 + +=item * + +Canonical tests live in F as the single source of truth. + +=item * + +F defines two variants (C and C) that only +differ in the C environment variable. + +=item * + +Running C in a developer checkout (where F +is present) regenerates F and F from the inline tests. + +=item * + +Generated files are excluded from version control (F<.gitignore>) but +included in the distribution tarball (F), so CPAN consumers +do not need L installed. + +=item * + +C excludes the generated directories since their +formatting is determined by L, not the project's +F<.perltidyrc>. + +=back + +=head2 Consequences + +=over 4 + +=item * + +Test logic is maintained in exactly one place; changes automatically +propagate to both backend variants. + +=item * + +Adding a new variant (e.g. a future optional backend) requires only a +new entry in F, not duplicating every test file. + +=item * + +Developer tooling requires L E 0.014 (declared +as a develop prerequisite). + +=item * + +C removes the generated directories so that a fresh +C regenerates them from current inline sources. + +=back + +=cut diff --git a/t/pp/01_compile.t b/t/inline/01_compile.t old mode 100755 new mode 100644 similarity index 91% rename from t/pp/01_compile.t rename to t/inline/01_compile.t index 76aa43d..7f454b7 --- a/t/pp/01_compile.t +++ b/t/inline/01_compile.t @@ -7,7 +7,6 @@ BEGIN { $| = 1; $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 1; } use Test::More tests => 4; diff --git a/t/pp/02_main.t b/t/inline/02_main.t similarity index 99% rename from t/pp/02_main.t rename to t/inline/02_main.t index 55ad569..6b7abf5 100644 --- a/t/pp/02_main.t +++ b/t/inline/02_main.t @@ -6,7 +6,6 @@ BEGIN { $| = 1; $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 1; } use Test::More tests => 770; diff --git a/t/pp/03_all.t b/t/inline/03_all.t old mode 100755 new mode 100644 similarity index 97% rename from t/pp/03_all.t rename to t/inline/03_all.t index 2a28dea..2288b02 --- a/t/pp/03_all.t +++ b/t/inline/03_all.t @@ -6,7 +6,6 @@ BEGIN { $| = 1; $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 1; } use Test::More tests => 26; diff --git a/t/xs/04_codelike.t b/t/inline/04_codelike.t similarity index 98% rename from t/xs/04_codelike.t rename to t/inline/04_codelike.t index 5f36e33..93df19d 100644 --- a/t/xs/04_codelike.t +++ b/t/inline/04_codelike.t @@ -6,7 +6,6 @@ BEGIN { $| = 1; $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 0; } sub _CODELIKE($); diff --git a/t/pp/05_typelike.t b/t/inline/05_typelike.t similarity index 98% rename from t/pp/05_typelike.t rename to t/inline/05_typelike.t index 7a85f4a..1cb3d37 100644 --- a/t/pp/05_typelike.t +++ b/t/inline/05_typelike.t @@ -6,7 +6,6 @@ BEGIN { $| = 1; $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 1; } use Test::More tests => 44; diff --git a/t/pp/06_invocant.t b/t/inline/06_invocant.t similarity index 98% rename from t/pp/06_invocant.t rename to t/inline/06_invocant.t index 4edff56..afa10d3 100644 --- a/t/pp/06_invocant.t +++ b/t/inline/06_invocant.t @@ -6,7 +6,6 @@ BEGIN { $| = 1; $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 1; } use Test::More tests => 11; diff --git a/t/pp/07_handle.t b/t/inline/07_handle.t similarity index 98% rename from t/pp/07_handle.t rename to t/inline/07_handle.t index fe89b57..ec0b798 100644 --- a/t/pp/07_handle.t +++ b/t/inline/07_handle.t @@ -6,7 +6,6 @@ BEGIN { $| = 1; $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 1; } use Test::More tests => 23; diff --git a/t/xs/08_driver.t b/t/inline/08_driver.t similarity index 99% rename from t/xs/08_driver.t rename to t/inline/08_driver.t index 6020c50..687d2db 100644 --- a/t/xs/08_driver.t +++ b/t/inline/08_driver.t @@ -6,7 +6,6 @@ BEGIN { $| = 1; $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 0; } use Test::More tests => 91; diff --git a/t/pp/09_insideout.t b/t/inline/09_insideout.t similarity index 95% rename from t/pp/09_insideout.t rename to t/inline/09_insideout.t index 99a9176..7d9c23f 100644 --- a/t/pp/09_insideout.t +++ b/t/inline/09_insideout.t @@ -9,7 +9,6 @@ BEGIN { $| = 1; $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 1; } use Test::More tests => 2; diff --git a/t/pp/04_codelike.t b/t/pp/04_codelike.t deleted file mode 100644 index 46ea767..0000000 --- a/t/pp/04_codelike.t +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/perl - -use strict; - -BEGIN -{ - $| = 1; - $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 1; -} - -sub _CODELIKE($); - -use Test::More; -use File::Spec::Functions ':ALL'; -use Scalar::Util qw( - blessed - reftype - refaddr -); -use overload; - -sub c_ok -{ - is(refaddr(_CODELIKE($_[0])), refaddr($_[0]), "callable: $_[1]",); -} - -sub nc_ok -{ - my $left = shift; - $left = _CODELIKE($left); - is($left, undef, "not callable: $_[0]"); -} - -my @callables = ( - "callable itself" => \&_CODELIKE, - "a boring plain code ref" => sub { }, - 'an object with overloaded &{}' => C::O->new, - 'a object build from a coderef' => C::C->new, - 'an object with inherited overloaded &{}' => C::O::S->new, - 'a coderef blessed into CODE' => (bless sub { } => 'CODE'), -); - -my @uncallables = ( - "undef" => undef, - "a string" => "a string", - "a number" => 19780720, - "a ref to a ref to code" => \(sub { }), - "a boring plain hash ref" => {}, - 'a class that builds from coderefs' => "C::C", - 'a class with overloaded &{}' => "C::O", - 'a class with inherited overloaded &{}' => "C::O::S", - 'a plain boring hash-based object' => UC->new, - 'a non-coderef blessed into CODE' => (bless {} => 'CODE'), -); - -my $tests = (@callables + @uncallables) / 2 + 2; - -if ($] > 5.006) -{ - push @uncallables, 'a regular expression', qr/foo/; - $tests += 1; -} - -plan tests => $tests; - -# Import the function -use_ok('Params::Util', '_CODELIKE'); -ok(defined *_CODELIKE{CODE}, '_CODELIKE imported ok'); - -while (@callables) -{ - my $name = shift @callables; - my $object = shift @callables; - c_ok($object, $name); -} - -while (@uncallables) -{ - my $name = shift @uncallables; - my $object = shift @uncallables; - nc_ok($object, $name); -} - -###################################################################### -# callable: is a blessed code ref - -package C::C; - -sub new -{ - bless sub { } => shift; -} - -###################################################################### -# callable: overloads &{} -# but only objects are callable, not class - -package C::O; - -sub new -{ - bless {} => shift; -} -use overload '&{}' => sub { - sub { } -}; -use overload 'bool' => sub () { 1 }; - -###################################################################### -# callable: subclasses C::O - -package C::O::S; - -use vars qw{@ISA}; - -BEGIN -{ - @ISA = 'C::O'; -} - -###################################################################### -# uncallable: some boring object with no codey magic - -package UC; - -sub new -{ - bless {} => shift; -} diff --git a/t/pp/08_driver.t b/t/pp/08_driver.t deleted file mode 100644 index 98e4ddc..0000000 --- a/t/pp/08_driver.t +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/perl - -use strict; - -BEGIN -{ - $| = 1; - $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 1; -} - -use Test::More tests => 91; -use File::Spec::Functions ':ALL'; - -BEGIN -{ - ok(!defined &_CLASSISA, '_CLASSISA does not exist'); - ok(!defined &_SUBCLASS, '_SUBCLASS does not exist'); - ok(!defined &_DRIVER, '_DRIVER does not exist'); - use_ok('Params::Util', qw(_CLASSISA _SUBCLASS _DRIVER)); - ok(defined &_CLASSISA, '_CLASSISA imported ok'); - ok(defined &_SUBCLASS, '_SUBCLASS imported ok'); - ok(defined &_DRIVER, '_DRIVER imported ok'); -} - -# Import refaddr to make certain we have it -use Scalar::Util 'refaddr'; - -##################################################################### -# Preparing - -my $A = catfile('t', 'driver', 'A.pm'); -ok(-f $A, 'A exists'); -my $B = catfile('t', 'driver', 'My_B.pm'); -ok(-f $B, 'My_B exists'); -my $C = catfile('t', 'driver', 'C.pm'); -ok(!-f $C, 'C does not exist'); -my $D = catfile('t', 'driver', 'D.pm'); -ok(-f $D, 'D does not exist'); -my $E = catfile('t', 'driver', 'E.pm'); -ok(-f $E, 'E does not exist'); -my $F = catfile('t', 'driver', 'F.pm'); -ok(-f $F, 'F does not exist'); - -unshift @INC, catdir('t', 'driver'); - -##################################################################### -# Things that are not file handles - -foreach (undef, '', ' ', 'foo bar', 1, 0, -1, 1.23, [], {}, \'', bless({}, "foo")) -{ - is(_CLASSISA($_, 'A'), undef, 'Non-classisa returns undef'); - is(_SUBCLASS($_, 'A'), undef, 'Non-subclass returns undef'); - is(_DRIVER($_, 'A'), undef, 'Non-driver returns undef'); -} - -##################################################################### -# Sample Classes - -# classisa should not load classes -is(_CLASSISA('A', 'A'), 'A', 'A: Driver base class is undef'); -is(_CLASSISA('My_B', 'A'), undef, 'B: Good driver returns ok'); -is(_CLASSISA('My_B', 'H'), undef, 'B: Good driver return undef for incorrect base'); -is(_CLASSISA('C', 'A'), undef, 'C: Non-existant driver is undef'); -is(_CLASSISA('D', 'A'), undef, 'D: Broken driver is undef'); -is(_CLASSISA('E', 'A'), undef, 'E: Not a driver returns undef'); -is(_CLASSISA('F', 'A'), undef, 'F: Faked isa returns ok'); - -# classisa should not load classes -is(_SUBCLASS('A', 'A'), undef, 'A: Driver base class is undef'); -is(_SUBCLASS('My_B', 'A'), undef, 'B: Good driver returns ok'); -is(_SUBCLASS('My_B', 'H'), undef, 'B: Good driver return undef for incorrect base'); -is(_SUBCLASS('C', 'A'), undef, 'C: Non-existant driver is undef'); -is(_SUBCLASS('D', 'A'), undef, 'D: Broken driver is undef'); -is(_SUBCLASS('E', 'A'), undef, 'E: Not a driver returns undef'); -is(_SUBCLASS('F', 'A'), undef, 'F: Faked isa returns ok'); - -# The base class itself is not a driver -is(_DRIVER('A', 'A'), undef, 'A: Driver base class is undef'); -ok($A::VERSION, 'A: Class is loaded ok'); -is(_DRIVER('My_B', 'A'), 'My_B', 'B: Good driver returns ok'); -is(_DRIVER('My_B', 'H'), undef, 'B: Good driver return undef for incorrect base'); -ok($My_B::VERSION, 'B: Class is loaded ok'); -is(_DRIVER('C', 'A'), undef, 'C: Non-existant driver is undef'); -is(_DRIVER('D', 'A'), undef, 'D: Broken driver is undef'); -is(_DRIVER('E', 'A'), undef, 'E: Not a driver returns undef'); -is(_DRIVER('F', 'A'), 'F', 'F: Faked isa returns ok'); - -# Repeat for classisa -is(_CLASSISA('A', 'A'), 'A', 'A: Driver base class is undef'); -is(_CLASSISA('My_B', 'A'), 'My_B', 'B: Good driver returns ok'); -is(_CLASSISA('My_B', 'H'), undef, 'B: Good driver return undef for incorrect base'); -is(_CLASSISA('C', 'A'), undef, 'C: Non-existant driver is undef'); -is(_CLASSISA('D', 'A'), 'D', 'D: Broken driver is undef'); -is(_CLASSISA('E', 'A'), undef, 'E: Not a driver returns undef'); -is(_CLASSISA('F', 'A'), 'F', 'F: Faked isa returns ok'); - -# Repeat for subclasses -is(_SUBCLASS('A', 'A'), undef, 'A: Driver base class is undef'); -is(_SUBCLASS('My_B', 'A'), 'My_B', 'B: Good driver returns ok'); -is(_SUBCLASS('My_B', 'H'), undef, 'B: Good driver return undef for incorrect base'); -is(_SUBCLASS('C', 'A'), undef, 'C: Non-existant driver is undef'); -is(_SUBCLASS('D', 'A'), 'D', 'D: Broken driver is undef'); -is(_SUBCLASS('E', 'A'), undef, 'E: Not a driver returns undef'); -is(_SUBCLASS('F', 'A'), 'F', 'F: Faked isa returns ok'); - -SKIP: -{ - use_ok('Params::Util', qw(_CLASSDOES)); - - skip "DOES tests do not make sense on perls before 5.10", 4 - unless $] >= 5.010; - - is(_CLASSDOES('A', 'A'), 'A', 'A: DOES A'); - is(_CLASSDOES('My_B', 'A'), 'My_B', 'My_B: DOES A'); - is(_CLASSDOES('E', 'A'), undef, 'E: DOES not A'); - is(_CLASSDOES('F', 'A'), 'F', 'F: DOES A'); -} diff --git a/t/xs/01_compile.t b/t/xs/01_compile.t deleted file mode 100755 index 611482c..0000000 --- a/t/xs/01_compile.t +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/perl - -use 5.00503; -use strict; - -BEGIN -{ - $| = 1; - $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 0; -} - -use Test::More tests => 4; -use File::Spec::Functions ':ALL'; - -# Does the module load -use_ok('Params::Util'); - -# Double check that Scalar::Util is valid -require_ok('Scalar::Util'); -ok($Scalar::Util::VERSION >= 1.10, 'Scalar::Util version is at least 1.18'); -ok(defined &Scalar::Util::refaddr, 'Scalar::Util has a refaddr implementation'); diff --git a/t/xs/02_main.t b/t/xs/02_main.t deleted file mode 100644 index e75ee91..0000000 --- a/t/xs/02_main.t +++ /dev/null @@ -1,944 +0,0 @@ -#!/usr/bin/perl - -use strict; - -BEGIN -{ - $| = 1; - $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 0; -} - -use Test::More tests => 770; -use File::Spec::Functions ':ALL'; -use Scalar::Util 'refaddr'; -use Params::Util (); - -# Utility functions -sub true { is(shift, 1, shift || ()) } -sub false { is(shift, '', shift || ()) } -sub null { is(shift, undef, shift || ()) } - -sub dies -{ - my ($code, $regexp, $message) = @_; - eval "$code"; - ok((defined($@) and length($@)), $message); - if (defined $regexp) - { - like($@, $regexp, '... with expected error message'); - } -} - -##################################################################### -# Tests for _STRING - -# Test bad things against the actual function -dies("Params::Util::_STRING()", qr/Not enough arguments/, '...::_STRING() dies'); -null(Params::Util::_STRING(undef), '...::_STRING(undef) returns undef'); -null(Params::Util::_STRING(''), '...::_STRING(nullstring) returns undef'); -null(Params::Util::_STRING({foo => 1}), '...::_STRING(HASH) returns undef'); -null(Params::Util::_STRING(sub () { 1 }), '...::_STRING(CODE) returns undef'); -null(Params::Util::_STRING([]), '...::_STRING(ARRAY) returns undef'); -null(Params::Util::_STRING(\""), '...::_STRING(null constant) returns undef'); -null(Params::Util::_STRING(\"foo"), '...::_STRING(SCALAR) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $ident (qw{0 1 foo _foo foo1 __foo_1 Foo::Bar}, ' ', ' foo') -{ - is(Params::Util::_STRING($ident), $ident, "...::_STRING('$ident') returns ok"); - $ident =~ /(.*)/; - is(Params::Util::_STRING($1), $1, "...::_STRING('$1') returns ok"); -} - -# Import the function -use_ok('Params::Util', '_STRING'); -ok(defined *_STRING{CODE}, '_STRING imported ok'); - -# Test bad things against the actual function -dies("_STRING()", qr/Not enough arguments/, '...::_STRING() dies'); -null(_STRING(undef), '_STRING(undef) returns undef'); -null(_STRING(''), '_STRING(nullstring) returns undef'); -null(_STRING({foo => 1}), '_STRING(HASH) returns undef'); -null(_STRING(sub () { 1 }), '_STRING(CODE) returns undef'); -null(_STRING([]), '_STRING(ARRAY) returns undef'); -null(_STRING(\""), '_STRING(null constant) returns undef'); -null(_STRING(\"foo"), '_STRING(SCALAR) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $ident (qw{0 1 foo _foo foo1 __foo_1 Foo::Bar}, ' ', ' foo') -{ - is(_STRING($ident), $ident, "_STRING('$ident') returns ok"); - $ident =~ /(.*)/; - is(_STRING($1), $1, "_STRING('$1') returns ok"); -} - -##################################################################### -# Tests for _IDENTIFIER - -# Test bad things against the actual function -dies("Params::Util::_IDENTIFIER()", qr/Not enough arguments/, '...::_IDENTIFIER() dies'); -null(Params::Util::_IDENTIFIER(undef), '...::_IDENTIFIER(undef) returns undef'); -null(Params::Util::_IDENTIFIER(''), '...::_IDENTIFIER(nullstring) returns undef'); -null(Params::Util::_IDENTIFIER(1), '...::_IDENTIFIER(number) returns undef'); -null(Params::Util::_IDENTIFIER(' foo'), '...::_IDENTIFIER(string) returns undef'); -null(Params::Util::_IDENTIFIER({foo => 1}), '...::_IDENTIFIER(HASH) returns undef'); -null(Params::Util::_IDENTIFIER(sub () { 1 }), '...::_IDENTIFIER(CODE) returns undef'); -null(Params::Util::_IDENTIFIER([]), '...::_IDENTIFIER(ARRAY) returns undef'); -null(Params::Util::_IDENTIFIER(\""), '...::_IDENTIFIER(null constant) returns undef'); -null(Params::Util::_IDENTIFIER(\"foo"), '...::_IDENTIFIER(SCALAR) returns undef'); -null(Params::Util::_IDENTIFIER("Foo::Bar"), '...::_IDENTIFIER(CLASS) returns undef'); -null(Params::Util::_IDENTIFIER("foo\n"), '...::_IDENTIFIER(BAD) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $ident (qw{foo _foo foo1 __foo_1}) -{ - is(Params::Util::_IDENTIFIER($ident), $ident, "...::_IDENTIFIER('$ident') returns ok"); - $ident =~ /(.*)/; - is(Params::Util::_IDENTIFIER($1), $1, "...::_IDENTIFIER('$1') returns ok"); -} - -# Import the function -use_ok('Params::Util', '_IDENTIFIER'); -ok(defined *_IDENTIFIER{CODE}, '_IDENTIFIER imported ok'); - -# Test bad things against the actual function -dies("_IDENTIFIER()", qr/Not enough arguments/, '...::_IDENTIFIER() dies'); -null(_IDENTIFIER(undef), '_IDENTIFIER(undef) returns undef'); -null(_IDENTIFIER(''), '_IDENTIFIER(nullstring) returns undef'); -null(_IDENTIFIER(1), '_IDENTIFIER(number) returns undef'); -null(_IDENTIFIER(' foo'), '_IDENTIFIER(string) returns undef'); -null(_IDENTIFIER({foo => 1}), '_IDENTIFIER(HASH) returns undef'); -null(_IDENTIFIER(sub () { 1 }), '_IDENTIFIER(CODE) returns undef'); -null(_IDENTIFIER([]), '_IDENTIFIER(ARRAY) returns undef'); -null(_IDENTIFIER(\""), '_IDENTIFIER(null constant) returns undef'); -null(_IDENTIFIER(\"foo"), '_IDENTIFIER(SCALAR) returns undef'); -null(_IDENTIFIER("Foo::Bar"), '_IDENTIFIER(CLASS) returns undef'); -null(_IDENTIFIER("foo\n"), '_IDENTIFIER(BAD) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $ident (qw{foo _foo foo1 __foo_1}) -{ - is(_IDENTIFIER($ident), $ident, "_IDENTIFIER('$ident') returns ok"); - $ident =~ /(.*)/; - is(_IDENTIFIER($1), $1, "_IDENTIFIER('$1') returns ok"); -} - -##################################################################### -# Tests for _CLASS - -# Test bad things against the actual function -dies("Params::Util::_CLASS()", qr/Not enough arguments/, '...::_CLASS() dies'); -null(Params::Util::_CLASS(undef), '...::_CLASS(undef) returns undef'); -null(Params::Util::_CLASS(''), '...::_CLASS(nullstring) returns undef'); -null(Params::Util::_CLASS(1), '...::_CLASS(number) returns undef'); -null(Params::Util::_CLASS(' foo'), '...::_CLASS(string) returns undef'); -null(Params::Util::_CLASS({foo => 1}), '...::_CLASS(HASH) returns undef'); -null(Params::Util::_CLASS(sub () { 1 }), '...::_CLASS(CODE) returns undef'); -null(Params::Util::_CLASS([]), '...::_CLASS(ARRAY) returns undef'); -null(Params::Util::_CLASS(\""), '...::_CLASS(null constant) returns undef'); -null(Params::Util::_CLASS(\"foo"), '...::_CLASS(SCALAR) returns undef'); -null(Params::Util::_CLASS("D'oh"), '...::_CLASS(bad class) returns undef'); -null(Params::Util::_CLASS("::Foo"), '...::_CLASS(bad class) returns undef'); -null(Params::Util::_CLASS("1::X"), '...::_CLASS(bad class) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $ident (qw{foo _foo foo1 __foo_1 Foo::Bar _Foo::Baaar::Baz X::1}) -{ - is(Params::Util::_CLASS($ident), $ident, "...::_CLASS('$ident') returns ok"); - $ident =~ /(.*)/; - is(Params::Util::_CLASS($1), $1, "...::_CLASS('$1') returns ok"); -} - -# Import the function -use_ok('Params::Util', '_CLASS'); -ok(defined *_CLASS{CODE}, '_CLASS imported ok'); - -# Test bad things against the actual function -dies("_CLASS()", qr/Not enough arguments/, '_CLASS() dies'); -null(_CLASS(undef), '_CLASS(undef) returns undef'); -null(_CLASS(''), '_CLASS(nullstring) returns undef'); -null(_CLASS(1), '_CLASS(number) returns undef'); -null(_CLASS(' foo'), '_CLASS(string) returns undef'); -null(_CLASS({foo => 1}), '_CLASS(HASH) returns undef'); -null(_CLASS(sub () { 1 }), '_CLASS(CODE) returns undef'); -null(_CLASS([]), '_CLASS(ARRAY) returns undef'); -null(_CLASS(\""), '_CLASS(null constant) returns undef'); -null(_CLASS(\"foo"), '_CLASS(SCALAR) returns undef'); -null(_CLASS("D'oh"), '_CLASS(bad class) returns undef'); -null(_CLASS("::Foo"), '_CLASS(bad class) returns undef'); -null(_CLASS("1::X"), '_CLASS(bad class) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $ident (qw{foo _foo foo1 __foo_1 Foo::Bar _Foo::Baaar::Baz X::1}) -{ - is(_CLASS($ident), $ident, "_CLASS('$ident') returns ok"); - $ident =~ /(.*)/; - is(_CLASS($1), $1, "_CLASS('$1') returns ok"); -} - -##################################################################### -# Tests for _NUMBER - -# Test bad things against the actual function -dies("Params::Util::_NUMBER()", qr/Not enough arguments/, '...::_NUMBER() dies'); -null(Params::Util::_NUMBER(undef), '...::_NUMBER(undef) returns undef'); -null(Params::Util::_NUMBER(''), '...::_NUMBER(nullstring) returns undef'); -null(Params::Util::_NUMBER(' foo'), '...::_NUMBER(string) returns undef'); -null(Params::Util::_NUMBER({foo => 1}), '...::_NUMBER(HASH) returns undef'); -null(Params::Util::_NUMBER(sub () { 1 }), '...::_NUMBER(CODE) returns undef'); -null(Params::Util::_NUMBER([]), '...::_NUMBER(ARRAY) returns undef'); -null(Params::Util::_NUMBER(\""), '...::_NUMBER(null constant) returns undef'); -null(Params::Util::_NUMBER(\"foo"), '...::_NUMBER(SCALAR) returns undef'); -null(Params::Util::_NUMBER("D'oh"), '...::_NUMBER(bad class) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $id (qw{1 2 10 123456789 -1 0 +1 02 .1 0.013e-3 1e1}) -{ - is(Params::Util::_NUMBER($id), $id, "...::_NUMBER('$id') returns ok"); - $id =~ /(.*)/; - is(Params::Util::_NUMBER($1), $1, "...::_NUMBER('$1') returns ok"); -} - -# Import the function -use_ok('Params::Util', '_NUMBER'); -ok(defined *_NUMBER{CODE}, '_NUMBER imported ok'); - -# Test bad things against the actual function -dies("_NUMBER()", qr/Not enough arguments/, '_NUMBER() dies'); -null(_NUMBER(undef), '_NUMBER(undef) returns undef'); -null(_NUMBER(''), '_NUMBER(nullstring) returns undef'); -null(_NUMBER(' foo'), '_NUMBER(string) returns undef'); -null(_NUMBER({foo => 1}), '_NUMBER(HASH) returns undef'); -null(_NUMBER(sub () { 1 }), '_NUMBER(CODE) returns undef'); -null(_NUMBER([]), '_NUMBER(ARRAY) returns undef'); -null(_NUMBER(\""), '_NUMBER(null constant) returns undef'); -null(_NUMBER(\"foo"), '_NUMBER(SCALAR) returns undef'); -null(_NUMBER("D'oh"), '_NUMBER(bad class) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $id (qw{1 2 10 123456789 -1 0 +1 02 .1 0.013e-3 1e1}) -{ - is(_NUMBER($id), $id, "_NUMBER('$id') returns ok"); - $id =~ /(.*)/; - is(_NUMBER($1), $1, "_NUMBER('$1') returns ok"); -} - -##################################################################### -# Tests for _POSINT - -# Test bad things against the actual function -dies("Params::Util::_POSINT()", qr/Not enough arguments/, '...::_POSINT() dies'); -null(Params::Util::_POSINT(undef), '...::_POSINT(undef) returns undef'); -null(Params::Util::_POSINT(''), '...::_POSINT(nullstring) returns undef'); -null(Params::Util::_POSINT(' foo'), '...::_POSINT(string) returns undef'); -null(Params::Util::_POSINT({foo => 1}), '...::_POSINT(HASH) returns undef'); -null(Params::Util::_POSINT(sub () { 1 }), '...::_POSINT(CODE) returns undef'); -null(Params::Util::_POSINT([]), '...::_POSINT(ARRAY) returns undef'); -null(Params::Util::_POSINT(\""), '...::_POSINT(null constant) returns undef'); -null(Params::Util::_POSINT(\"foo"), '...::_POSINT(SCALAR) returns undef'); -null(Params::Util::_POSINT("D'oh"), '...::_POSINT(bad class) returns undef'); -null(Params::Util::_POSINT(-1), '...::_POSINT(negative) returns undef'); -null(Params::Util::_POSINT(0), '...::_POSINT(zero) returns undef'); -null(Params::Util::_POSINT("+1"), '...::_POSINT(explicit positive) returns undef'); -null(Params::Util::_POSINT("02"), '...::_POSINT(zero lead) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $id (qw{1 2 10 123456789}) -{ - is(Params::Util::_POSINT($id), $id, "...::_POSINT('$id') returns ok"); - $id =~ /(\d+)/; - is(Params::Util::_POSINT($1), $1, "...::_POSINT('$1') returns ok"); -} - -# Import the function -use_ok('Params::Util', '_POSINT'); -ok(defined *_POSINT{CODE}, '_POSINT imported ok'); - -# Test bad things against the actual function -dies("_POSINT()", qr/Not enough arguments/, '_POSINT() dies'); -null(_POSINT(undef), '_POSINT(undef) returns undef'); -null(_POSINT(''), '_POSINT(nullstring) returns undef'); -null(_POSINT(' foo'), '_POSINT(string) returns undef'); -null(_POSINT({foo => 1}), '_POSINT(HASH) returns undef'); -null(_POSINT(sub () { 1 }), '_POSINT(CODE) returns undef'); -null(_POSINT([]), '_POSINT(ARRAY) returns undef'); -null(_POSINT(\""), '_POSINT(null constant) returns undef'); -null(_POSINT(\"foo"), '_POSINT(SCALAR) returns undef'); -null(_POSINT("D'oh"), '_POSINT(bad class) returns undef'); -null(_POSINT(-1), '_POSINT(negative) returns undef'); -null(_POSINT(0), '_POSINT(zero) returns undef'); -null(_POSINT("+1"), '_POSINT(explicit positive) returns undef'); -null(_POSINT("02"), '_POSINT(zero lead) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $id (qw{1 2 10 123456789}) -{ - is(_POSINT($id), $id, "_POSINT('$id') returns ok"); - $id =~ /(\d+)/; - is(_POSINT($1), $1, "_POSINT('$1') returns ok"); -} - -##################################################################### -# Tests for _NONNEGINT - -# Test bad things against the actual function -dies("Params::Util::_NONNEGINT()", qr/Not enough arguments/, '...::_NONNEGINT() dies'); -null(Params::Util::_NONNEGINT(undef), '...::_NONNEGINT(undef) returns undef'); -null(Params::Util::_NONNEGINT(''), '...::_NONNEGINT(nullstring) returns undef'); -null(Params::Util::_NONNEGINT(' foo'), '...::_NONNEGINT(string) returns undef'); -null(Params::Util::_NONNEGINT({foo => 1}), '...::_NONNEGINT(HASH) returns undef'); -null(Params::Util::_NONNEGINT(sub () { 1 }), '...::_NONNEGINT(CODE) returns undef'); -null(Params::Util::_NONNEGINT([]), '...::_NONNEGINT(ARRAY) returns undef'); -null(Params::Util::_NONNEGINT(\""), '...::_NONNEGINT(null constant) returns undef'); -null(Params::Util::_NONNEGINT(\"foo"), '...::_NONNEGINT(SCALAR) returns undef'); -null(Params::Util::_NONNEGINT("D'oh"), '...::_NONNEGINT(bad class) returns undef'); -null(Params::Util::_NONNEGINT(-1), '...::_NONNEGINT(negative) returns undef'); -null(Params::Util::_NONNEGINT("+1"), '...::_NONNEGINT(explicit positive) returns undef'); -null(Params::Util::_NONNEGINT("02"), '...::_NONNEGINT(zero lead) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $id (qw{0 1 2 10 123456789}) -{ - is(Params::Util::_NONNEGINT($id), $id, "...::_NONNEGINT('$id') returns ok"); - $id =~ /(\d+)/; - is(Params::Util::_NONNEGINT($1), $1, "...::_NONNEGINT('$1') returns ok"); -} - -# Import the function -use_ok('Params::Util', '_NONNEGINT'); -ok(defined *_NONNEGINT{CODE}, '_NONNEGINT imported ok'); - -# Test bad things against the actual function -dies("_NONNEGINT()", qr/Not enough arguments/, '_NONNEGINT() dies'); -null(_NONNEGINT(undef), '_NONNEGINT(undef) returns undef'); -null(_NONNEGINT(''), '_NONNEGINT(nullstring) returns undef'); -null(_NONNEGINT(' foo'), '_NONNEGINT(string) returns undef'); -null(_NONNEGINT({foo => 1}), '_NONNEGINT(HASH) returns undef'); -null(_NONNEGINT(sub () { 1 }), '_NONNEGINT(CODE) returns undef'); -null(_NONNEGINT([]), '_NONNEGINT(ARRAY) returns undef'); -null(_NONNEGINT(\""), '_NONNEGINT(null constant) returns undef'); -null(_NONNEGINT(\"foo"), '_NONNEGINT(SCALAR) returns undef'); -null(_NONNEGINT("D'oh"), '_NONNEGINT(bad class) returns undef'); -null(_NONNEGINT(-1), '_NONNEGINT(negative) returns undef'); -null(_NONNEGINT("+1"), '_NONNEGINT(explicit positive) returns undef'); -null(_NONNEGINT("02"), '_NONNEGINT(zero lead) returns undef'); - -# Test good things against the actual function (carefully) -foreach my $id (qw{0 1 2 10 123456789}) -{ - is(_NONNEGINT($id), $id, "_NONNEGINT('$id') returns ok"); - $id =~ /(\d+)/; - is(_NONNEGINT($1), $1, "_NONNEGINT('$1') returns ok"); -} - -##################################################################### -# Tests for _SCALAR - -my $foo = "foo"; -my $scalar = \$foo; - -# Test bad things against the actual function -dies("Params::Util::_SCALAR()", qr/Not enough arguments/, '...::_SCALAR() dies'); -null(Params::Util::_SCALAR(undef), '...::_SCALAR(undef) returns undef'); -null(Params::Util::_SCALAR(\undef), '...::_SCALAR(\undef) returns undef'); -null(Params::Util::_SCALAR(''), '...::_SCALAR(nullstring) returns undef'); -null(Params::Util::_SCALAR(1), '...::_SCALAR(number) returns undef'); -null(Params::Util::_SCALAR('foo'), '...::_SCALAR(string) returns undef'); -null(Params::Util::_SCALAR({foo => 1}), '...::_SCALAR(HASH) returns undef'); -null(Params::Util::_SCALAR(sub () { 1 }), '...::_SCALAR(CODE) returns undef'); -null(Params::Util::_SCALAR([]), '...::_SCALAR(ARRAY) returns undef'); -null(Params::Util::_SCALAR(\""), '...::_SCALAR(null constant) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(Params::Util::_SCALAR(\"foo")), 'SCALAR', '...::_SCALAR(constant) returns true'); -is(ref(Params::Util::_SCALAR($scalar)), 'SCALAR', "...::_SCALAR(['foo']) returns true"); -is(refaddr(Params::Util::_SCALAR($scalar)), refaddr($scalar), '...::_SCALAR returns the same SCALAR reference'); - -# Import the function -use_ok('Params::Util', '_SCALAR'); -ok(defined *_SCALAR{CODE}, '_SCALAR imported ok'); - -# Test bad things against the imported function -dies("_SCALAR()", qr/Not enough arguments/, '...::_SCALAR() dies'); -null(_SCALAR(undef), '...::_SCALAR(undef) returns undef'); -null(_SCALAR(\undef), '...::_SCALAR(\undef) returns undef'); -null(_SCALAR(''), '...::_SCALAR(nullstring) returns undef'); -null(_SCALAR(1), '...::_SCALAR(number) returns undef'); -null(_SCALAR('foo'), '...::_SCALAR(string) returns undef'); -null(_SCALAR({foo => 1}), '...::_SCALAR(HASH) returns undef'); -null(_SCALAR(sub () { 1 }), '...::_SCALAR(CODE) returns undef'); -null(_SCALAR([]), '...::_SCALAR(ARRAY) returns undef'); -null(_SCALAR(\""), '...::_SCALAR(null constant) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(_SCALAR(\"foo")), 'SCALAR', '...::_SCALAR(constant) returns true'); -is(ref(_SCALAR($scalar)), 'SCALAR', "...::_SCALAR(SCALAR) returns true"); -is(refaddr(_SCALAR($scalar)), refaddr($scalar), '...::_SCALAR returns the same SCALAR reference'); - -##################################################################### -# Tests for _SCALAR0 - -my $null = ""; -my $scalar0 = \$null; - -# Test bad things against the actual function -dies("Params::Util::_SCALAR0()", qr/Not enough arguments/, '...::_SCALAR0() dies'); -null(Params::Util::_SCALAR0(undef), '...::_SCALAR0(undef) returns undef'); -null(Params::Util::_SCALAR0(''), '...::_SCALAR0(nullstring) returns undef'); -null(Params::Util::_SCALAR0(1), '...::_SCALAR0(number) returns undef'); -null(Params::Util::_SCALAR0('foo'), '...::_SCALAR0(string) returns undef'); -null(Params::Util::_SCALAR0({foo => 1}), '...::_SCALAR0(HASH) returns undef'); -null(Params::Util::_SCALAR0(sub () { 1 }), '...::_SCALAR0(CODE) returns undef'); -null(Params::Util::_SCALAR0([]), '...::_SCALAR0(ARRAY) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(Params::Util::_SCALAR0(\"foo")), 'SCALAR', '...::_SCALAR0(constant) returns true'); -is(ref(Params::Util::_SCALAR0(\"")), 'SCALAR', '...::_SCALAR0(constant) returns true'); -is(ref(Params::Util::_SCALAR0(\undef)), 'SCALAR', '...::_SCALAR0(\undef) returns true'); -is(ref(Params::Util::_SCALAR0($scalar)), 'SCALAR', "...::_SCALAR0(constant) returns true"); -is(ref(Params::Util::_SCALAR0($scalar0)), 'SCALAR', "...::_SCALAR0(constant) returns true"); -is(refaddr(Params::Util::_SCALAR0($scalar)), refaddr($scalar), '...::_SCALAR returns the same SCALAR reference'); -is(refaddr(Params::Util::_SCALAR0($scalar0)), refaddr($scalar0), '...::_SCALAR returns the same SCALAR reference'); - -# Import the function -use_ok('Params::Util', '_SCALAR0'); -ok(defined *_SCALAR0{CODE}, '_SCALAR0 imported ok'); - -# Test bad things against the imported function -dies("_SCALAR0()", qr/Not enough arguments/, '...::_SCALAR0() dies'); -null(_SCALAR0(undef), '...::_SCALAR0(undef) returns undef'); -null(_SCALAR0(''), '...::_SCALAR0(nullstring) returns undef'); -null(_SCALAR0(1), '...::_SCALAR0(number) returns undef'); -null(_SCALAR0('foo'), '...::_SCALAR0(string) returns undef'); -null(_SCALAR0({foo => 1}), '...::_SCALAR0(HASH) returns undef'); -null(_SCALAR0(sub () { 1 }), '...::_SCALAR0(CODE) returns undef'); -null(_SCALAR0([]), '...::_SCALAR0(ARRAY) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(_SCALAR0(\"foo")), 'SCALAR', '...::_SCALAR0(constant) returns true'); -is(ref(_SCALAR0(\"")), 'SCALAR', '...::_SCALAR0(constant) returns true'); -is(ref(_SCALAR0(\undef)), 'SCALAR', '...::_SCALAR0(\undef) returns true'); -is(ref(_SCALAR0($scalar)), 'SCALAR', "...::_SCALAR0(constant) returns true"); -is(ref(_SCALAR0($scalar0)), 'SCALAR', "...::_SCALAR0(constant) returns true"); -is(refaddr(_SCALAR0($scalar)), refaddr($scalar), '...::_SCALAR returns the same SCALAR reference'); -is(refaddr(_SCALAR0($scalar0)), refaddr($scalar0), '...::_SCALAR returns the same SCALAR reference'); - -##################################################################### -# Tests for _ARRAY - -my $array = ['foo', 'bar']; - -# Test bad things against the actual function -dies("Params::Util::_ARRAY()", qr/Not enough arguments/, '...::_ARRAY() dies'); -null(Params::Util::_ARRAY(undef), '...::_ARRAY(undef) returns undef'); -null(Params::Util::_ARRAY(''), '...::_ARRAY(nullstring) returns undef'); -null(Params::Util::_ARRAY(1), '...::_ARRAY(number) returns undef'); -null(Params::Util::_ARRAY('foo'), '...::_ARRAY(string) returns undef'); -null(Params::Util::_ARRAY(\'foo'), '...::_ARRAY(SCALAR) returns undef'); -null(Params::Util::_ARRAY({foo => 1}), '...::_ARRAY(HASH) returns undef'); -null(Params::Util::_ARRAY(sub () { 1 }), '...::_ARRAY(CODE) returns undef'); -null(Params::Util::_ARRAY([]), '...::_ARRAY(empty ARRAY) returns undef'); -null(Params::Util::_ARRAY(bless [1], 'cat'), '...::_ARRAY(blessed ARRAY) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(Params::Util::_ARRAY([undef])), 'ARRAY', '...::_ARRAY([undef]) returns true'); -is(ref(Params::Util::_ARRAY(['foo'])), 'ARRAY', "...::_ARRAY(['foo']) returns true"); -is(ref(Params::Util::_ARRAY($array)), 'ARRAY', '...::_ARRAY returns an ARRAY ok'); -is(refaddr(Params::Util::_ARRAY($array)), refaddr($array), '...::_ARRAY($array) returns the same ARRAY reference'); - -# Import the function -use_ok('Params::Util', '_ARRAY'); -ok(defined *_ARRAY{CODE}, '_ARRAY imported ok'); - -# Test bad things against the actual function -dies("_ARRAY();", qr/Not enough arguments/, '_ARRAY() dies'); -null(_ARRAY(undef), '_ARRAY(undef) returns undef'); -null(_ARRAY(''), '_ARRAY(nullstring) returns undef'); -null(_ARRAY(1), '_ARRAY(number) returns undef'); -null(_ARRAY('foo'), '_ARRAY(string) returns undef'); -null(_ARRAY(\'foo'), '_ARRAY(SCALAR) returns undef'); -null(_ARRAY({foo => 1}), '_ARRAY(HASH) returns undef'); -null(_ARRAY(sub () { 1 }), '_ARRAY(CODE) returns undef'); -null(_ARRAY([]), '_ARRAY(empty ARRAY) returns undef'); -null(_ARRAY(bless [1], 'cat'), '_ARRAY(blessed ARRAY) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(_ARRAY([undef])), 'ARRAY', '_ARRAY([undef]) returns true'); -is(ref(_ARRAY(['foo'])), 'ARRAY', "_ARRAY(['foo']) returns true"); -is(ref(_ARRAY($array)), 'ARRAY', '_ARRAY returns an ARRAY ok'); -is(refaddr(_ARRAY($array)), refaddr($array), '_ARRAY($array) returns the same ARRAY reference'); - -##################################################################### -# Tests for _ARRAY0 - -# Test bad things against the actual function -dies("Params::Util::_ARRAY0();", qr/Not enough arguments/, '...::_ARRAY0() dies'); -null(Params::Util::_ARRAY0(undef), '...::_ARRAY0(undef) returns undef'); -null(Params::Util::_ARRAY0(''), '...::_ARRAY0(nullstring) returns undef'); -null(Params::Util::_ARRAY0(1), '...::_ARRAY0(number) returns undef'); -null(Params::Util::_ARRAY0('foo'), '...::_ARRAY0(string) returns undef'); -null(Params::Util::_ARRAY0(\'foo'), '...::_ARRAY0(SCALAR) returns undef'); -null(Params::Util::_ARRAY0({foo => 1}), '...::_ARRAY0(HASH) returns undef'); -null(Params::Util::_ARRAY0(sub () { 1 }), '...::_ARRAY0(CODE) returns undef'); -null(Params::Util::_ARRAY0(bless [], 'cat'), '...::_ARRAY0(blessed ARRAY) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(Params::Util::_ARRAY0([])), 'ARRAY', '...::_ARRAY0(empty ARRAY) returns undef'); -is(ref(Params::Util::_ARRAY0([undef])), 'ARRAY', '...::_ARRAY0([undef]) returns true'); -is(ref(Params::Util::_ARRAY0(['foo'])), 'ARRAY', "...::_ARRAY0(['foo']) returns true"); -is(ref(Params::Util::_ARRAY0($array)), 'ARRAY', '...::_ARRAY0 returns an ARRAY ok'); -is(refaddr(Params::Util::_ARRAY0($array)), refaddr($array), '...::_ARRAY0($array) returns the same ARRAY reference'); - -# Import the function -use_ok('Params::Util', '_ARRAY0'); -ok(defined *_ARRAY0{CODE}, '_ARRAY0 imported ok'); - -# Test bad things against the actual function -dies("_ARRAY0();", qr/Not enough arguments/, '_ARRAY0() dies'); -null(_ARRAY0(undef), '_ARRAY0(undef) returns undef'); -null(_ARRAY0(''), '_ARRAY0(nullstring) returns undef'); -null(_ARRAY0(1), '_ARRAY0(number) returns undef'); -null(_ARRAY0('foo'), '_ARRAY0(string) returns undef'); -null(_ARRAY0(\'foo'), '_ARRAY0(SCALAR) returns undef'); -null(_ARRAY0({foo => 1}), '_ARRAY0(HASH) returns undef'); -null(_ARRAY0(sub () { 1 }), '_ARRAY0(CODE) returns undef'); -null(_ARRAY0(bless [], 'cat'), '_ARRAY0(blessed ARRAY) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(_ARRAY0([])), 'ARRAY', '_ARRAY0(empty ARRAY) returns undef'); -is(ref(_ARRAY0([undef])), 'ARRAY', '_ARRAY0([undef]) returns true'); -is(ref(_ARRAY0(['foo'])), 'ARRAY', "_ARRAY0(['foo']) returns true"); -is(ref(_ARRAY0($array)), 'ARRAY', '_ARRAY0 returns an ARRAY ok'); -is(refaddr(_ARRAY0($array)), refaddr($array), '_ARRAY0($array) returns the same reference'); - -##################################################################### -# Tests for _HASH - -my $hash = {'foo' => 'bar'}; - -# Test bad things against the actual function -dies("Params::Util::_HASH();", qr/Not enough arguments/, '...::_HASH() dies'); -null(Params::Util::_HASH(undef), '...::_HASH(undef) returns undef'); -null(Params::Util::_HASH(''), '...::_HASH(nullstring) returns undef'); -null(Params::Util::_HASH(1), '...::_HASH(number) returns undef'); -null(Params::Util::_HASH('foo'), '...::_HASH(string) returns undef'); -null(Params::Util::_HASH(\'foo'), '...::_HASH(SCALAR) returns undef'); -null(Params::Util::_HASH(['foo']), '...::_HASH(ARRAY) returns undef'); -null(Params::Util::_HASH(sub () { 1 }), '...::_HASH(CODE) returns undef'); -null(Params::Util::_HASH({}), '...::_HASH(empty HASH) returns undef'); -null(Params::Util::_HASH(bless {a => 1}, 'cat'), '...::_HASH(blessed HASH) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(Params::Util::_HASH({foo => 1})), 'HASH', '...::_HASH([undef]) returns ok'); -is(ref(Params::Util::_HASH($hash)), 'HASH', '...::_HASH returns an HASH ok'); -is(refaddr(Params::Util::_HASH($hash)), refaddr($hash), '...::_HASH($hash) returns the same reference',); - -# Import the function -use_ok('Params::Util', '_HASH'); -ok(defined *_HASH{CODE}, '_HASH imported ok'); - -# Test bad things against the actual function -dies("_HASH();", qr/Not enough arguments/, '_HASH() dies'); -null(_HASH(undef), '_HASH(undef) returns undef'); -null(_HASH(''), '_HASH(nullstring) returns undef'); -null(_HASH(1), '_HASH(number) returns undef'); -null(_HASH('foo'), '_HASH(string) returns undef'); -null(_HASH(\'foo'), '_HASH(SCALAR) returns undef'); -null(_HASH([]), '_HASH(ARRAY) returns undef'); -null(_HASH(sub () { 1 }), '_HASH(CODE) returns undef'); -null(_HASH({}), '...::_HASH(empty HASH) returns undef'); -null(_HASH(bless {a => 1}, 'cat'), '_HASH(blessed HASH) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(_HASH({foo => 1})), 'HASH', '_HASH([undef]) returns true'); -is(ref(_HASH($hash)), 'HASH', '_HASH returns an ARRAY ok'); -is(refaddr(_HASH($hash)), refaddr($hash), '_HASH($hash) returns the same reference',); - -##################################################################### -# Tests for _HASH0 - -# Test bad things against the actual function -dies("Params::Util::_HASH0();", qr/Not enough arguments/, '...::_HASH0() dies'); -null(Params::Util::_HASH0(undef), '...::_HASH0(undef) returns undef'); -null(Params::Util::_HASH0(''), '...::_HASH0(nullstring) returns undef'); -null(Params::Util::_HASH0(1), '...::_HASH0(number) returns undef'); -null(Params::Util::_HASH0('foo'), '...::_HASH0(string) returns undef'); -null(Params::Util::_HASH0(\'foo'), '...::_HASH0(SCALAR) returns undef'); -null(Params::Util::_HASH0(['foo']), '...::_HASH0(ARRAY) returns undef'); -null(Params::Util::_HASH0(sub () { 1 }), '...::_HASH0(CODE) returns undef'); -null(Params::Util::_HASH0(bless {}, 'cat'), '...::_HASH0(blessed HASH) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(Params::Util::_HASH0({})), 'HASH', '...::_HASH0(empty ARRAY) returns undef'); -is(ref(Params::Util::_HASH0({foo => 1})), 'HASH', '...::_HASH0([undef]) returns true'); -is(ref(Params::Util::_HASH0($hash)), 'HASH', '...::_HASH0 returns an ARRAY ok'); -is(refaddr(Params::Util::_HASH0($hash)), refaddr($hash), '...::_HASH0($hash) returns the same reference',); - -# Import the function -use_ok('Params::Util', '_HASH0'); -ok(defined *_HASH0{CODE}, '_HASH0 imported ok'); - -# Test bad things against the actual function -dies("_HASH0();", qr/Not enough arguments/, '_HASH0() dies'); -null(_HASH0(undef), '_HASH0(undef) returns undef'); -null(_HASH0(''), '_HASH0(nullstring) returns undef'); -null(_HASH0(1), '_HASH0(number) returns undef'); -null(_HASH0('foo'), '_HASH0(string) returns undef'); -null(_HASH0(\'foo'), '_HASH0(SCALAR) returns undef'); -null(_HASH0([]), '_HASH0(ARRAY) returns undef'); -null(_HASH0(sub () { 1 }), '_HASH0(CODE) returns undef'); -null(_HASH0(bless {}, 'cat'), '_HASH0(blessed HASH) returns undef'); - -# Test good things against the actual function (carefully) -is(ref(_HASH0({})), 'HASH', '_HASH0(empty ARRAY) returns undef'); -is(ref(_HASH0({foo => 1})), 'HASH', '_HASH0([undef]) returns true'); -is(ref(_HASH0($hash)), 'HASH', '_HASH0 returns an ARRAY ok'); -is(refaddr(_HASH0($hash)), refaddr($hash), '_HASH0($hash) returns the same reference',); - -##################################################################### -# Tests for _CODE - -my $code = sub () { 1 }; -sub testcode { 3 } - -# Import the function -use_ok('Params::Util', '_CODE'); -ok(defined *_CODE{CODE}, '_CODE imported ok'); - -# Test bad things against the actual function -dies("Params::Util::_CODE();", qr/Not enough arguments/, '...::_CODE() dies'); -null(Params::Util::_CODE(undef), '...::_CODE(undef) returns undef'); -null(Params::Util::_CODE(''), '...::_CODE(nullstring) returns undef'); -null(Params::Util::_CODE(1), '...::_CODE(number) returns undef'); -null(Params::Util::_CODE('foo'), '...::_CODE(string) returns undef'); -null(Params::Util::_CODE(\'foo'), '...::_CODE(SCALAR) returns undef'); -null(Params::Util::_CODE(['foo']), '...::_CODE(ARRAY) returns undef'); -null(Params::Util::_CODE({}), '...::_CODE(empty HASH) returns undef'); - -# Test bad things against the actual function -dies("_CODE();", qr/Not enough arguments/, '_CODE() dies'); -null(_CODE(undef), '_CODE(undef) returns undef'); -null(_CODE(''), '_CODE(nullstring) returns undef'); -null(_CODE(1), '_CODE(number) returns undef'); -null(_CODE('foo'), '_CODE(string) returns undef'); -null(_CODE(\'foo'), '_CODE(SCALAR) returns undef'); -null(_CODE([]), '_CODE(ARRAY) returns undef'); -null(_CODE({}), '...::_CODE(empty HASH) returns undef'); - -# Test good things against the actual function -is(ref(Params::Util::_CODE(sub { 2 })), 'CODE', '...::_CODE(anon) returns ok'); -is(ref(Params::Util::_CODE($code)), 'CODE', '...::_CODE(ref) returns ok'); -is(ref(Params::Util::_CODE(\&testsub)), 'CODE', '...::_CODE(\&func) returns ok'); -is(refaddr(Params::Util::_CODE($code)), refaddr($code), '...::_CODE(ref) returns the same reference'); -is(refaddr(Params::Util::_CODE(\&testsub)), refaddr(\&testsub), '...::_CODE(\&func) returns the same reference'); - -# Test good things against the imported function -is(ref(_CODE(sub { 2 })), 'CODE', '_CODE(anon) returns ok'); -is(ref(_CODE($code)), 'CODE', '_CODE(ref) returns ok'); -is(ref(_CODE(\&testsub)), 'CODE', '_CODE(\&func) returns ok'); -is(refaddr(_CODE($code)), refaddr($code), '_CODE(ref) returns the same reference'); -is(refaddr(_CODE(\&testsub)), refaddr(\&testsub), '_CODE(\&func) returns the same reference'); - -##################################################################### -# Tests for _INSTANCE - -my $s1 = "foo"; -my $s2 = "bar"; -my $s3 = "baz"; -my $scalar1 = \$s1; -my $scalar2 = \$s2; -my $scalar3 = \$s3; -my @objects = ( - bless({}, 'Foo'), - bless([], 'Foo'), - bless($scalar1, 'Foo'), - bless({}, 'Bar'), - bless([], 'Bar'), - bless($scalar1, 'Bar'), - bless({}, 'Baz'), - bless([], 'Baz'), - bless($scalar3, 'Baz'), -); - -# Test bad things against the actual function -dies("Params::Util::_INSTANCE()", qr/Not enough arguments/, '...::_INSTANCE() dies'); -dies("Params::Util::_INSTANCE(bless {}, 'Foo')", qr/Not enough arguments/, '...::_INSTANCE(object) dies'); -null(Params::Util::_INSTANCE(undef, 'Foo'), '...::_INSTANCE(undef) returns undef'); -null(Params::Util::_INSTANCE('', 'Foo'), '...::_INSTANCE(nullstring) returns undef'); -null(Params::Util::_INSTANCE(1, 'Foo'), '...::_INSTANCE(number) returns undef'); -null(Params::Util::_INSTANCE('foo', 'Foo'), '...::_INSTANCE(string) returns undef'); -null(Params::Util::_INSTANCE({foo => 1}, 'Foo'), '...::_INSTANCE(HASH) returns undef'); -null(Params::Util::_INSTANCE(sub () { 1 }, 'Foo'), '...::_INSTANCE(CODE) returns undef'); -null(Params::Util::_INSTANCE([], 'Foo'), '...::_INSTANCE(ARRAY) returns undef'); -null(Params::Util::_INSTANCE(\"", 'Foo'), '...::_INSTANCE(null constant) returns undef'); -null(Params::Util::_INSTANCE(\"foo", 'Foo'), '...::_INSTANCE(SCALAR) returns undef'); -null(Params::Util::_INSTANCE(bless({}, 'Bad'), 'Foo'), '...::_INSTANCE(bad object) returns undef'); - -# Import the function -use_ok('Params::Util', '_INSTANCE'); -ok(defined *_INSTANCE{CODE}, '_INSTANCE imported ok'); - -# Test bad things against the actual function -dies("_INSTANCE()", qr/Not enough arguments/, '_INSTANCE() dies'); -dies("_INSTANCE(bless {}, 'Foo')", qr/Not enough arguments/, '_INSTANCE(object) dies'); -null(_INSTANCE(undef, 'Foo'), '_INSTANCE(undef) returns undef'); -null(_INSTANCE('', 'Foo'), '_INSTANCE(nullstring) returns undef'); -null(_INSTANCE(1, 'Foo'), '_INSTANCE(number) returns undef'); -null(_INSTANCE('foo', 'Foo'), '_INSTANCE(string) returns undef'); -null(_INSTANCE({foo => 1}, 'Foo'), '_INSTANCE(HASH) returns undef'); -null(_INSTANCE(sub () { 1 }, 'Foo'), '_INSTANCE(CODE) returns undef'); -null(_INSTANCE([], 'Foo'), '_INSTANCE(ARRAY) returns undef'); -null(_INSTANCE(\"", 'Foo'), '_INSTANCE(null constant) returns undef'); -null(_INSTANCE(\"foo", 'Foo'), '_INSTANCE(SCALAR) returns undef'); -null(_INSTANCE(bless({}, 'Bad'), 'Foo'), '_INSTANCE(bad object) returns undef'); - -# Testing good things is a little more complicated in this case, -# so lets do the basic ones first. -foreach my $object (@objects) -{ - ok(Params::Util::_INSTANCE($object, 'Foo'), '...::_INSTANCE(object, class) returns true when expected'); - is(refaddr(Params::Util::_INSTANCE($object, 'Foo')), - refaddr($object), '...::_INSTANCE(object, class) returns the same object'); -} - -# Testing good things is a little more complicated in this case, -# so lets do the basic ones first. -foreach my $object (@objects) -{ - ok(_INSTANCE($object, 'Foo'), '_INSTANCE(object, class) returns true when expected'); - is(refaddr(_INSTANCE($object, 'Foo')), refaddr($object), '_INSTANCE(object, class) returns the same object'); -} - -SKIP: -{ - use_ok('Params::Util', '_INSTANCEDOES'); - - skip "DOES tests do not make sense on perls before 5.10", 19 - unless $] >= 5.010; - - null(_INSTANCEDOES(bless({}, 'Bad'), 'Foo'), '_INSTANCEDOES(bad object) returns undef'); - - foreach my $object (@objects) - { - ok(_INSTANCEDOES($object, 'Foo'), '_INSTANCEDOES(object, class) returns true when expected'); - is(refaddr(_INSTANCEDOES($object, 'Foo')), refaddr($object), '_INSTANCEDOES(object, class) returns the same object'); - } -} - -##################################################################### -# Tests for _CLASSCAN - -use_ok('Params::Util', '_CLASSCAN'); -ok(defined *_CLASSCAN{CODE}, '_CLASSCAN imported ok'); - -# Bad values -null(_CLASSCAN(undef, 'foo'), '_CLASSCAN(undef, method) returns undef'); -null(_CLASSCAN('', 'foo'), '_CLASSCAN(empty, method) returns undef'); -null(_CLASSCAN({}, 'foo'), '_CLASSCAN(HASH, method) returns undef'); -null(_CLASSCAN([], 'foo'), '_CLASSCAN(ARRAY, method) returns undef'); -null(_CLASSCAN('4bad', 'foo'), '_CLASSCAN(bad class, method) returns undef'); - -# Class without the method -null(_CLASSCAN('Bad', 'foo'), '_CLASSCAN(Bad, foo) returns undef'); - -# Class with the method -is(_CLASSCAN('Foo', 'foo'), 'Foo', '_CLASSCAN(Foo, foo) returns class name'); -is(_CLASSCAN('Bar', 'foo'), 'Bar', '_CLASSCAN(Bar, foo) returns class name (inherited)'); - -##################################################################### -# Tests for _INSTANCECAN - -use_ok('Params::Util', '_INSTANCECAN'); -ok(defined *_INSTANCECAN{CODE}, '_INSTANCECAN imported ok'); - -# Bad values -null(_INSTANCECAN(undef, 'foo'), '_INSTANCECAN(undef, method) returns undef'); -null(_INSTANCECAN('Foo', 'foo'), '_INSTANCECAN(class string, method) returns undef'); -null(_INSTANCECAN({}, 'foo'), '_INSTANCECAN(unblessed HASH, method) returns undef'); -null(_INSTANCECAN(bless({}, 'Bad'), 'foo'), '_INSTANCECAN(bad object, foo) returns undef'); - -# Baz fakes isa('Foo') but does not actually provide 'foo' -null(_INSTANCECAN(bless({}, 'Baz'), 'foo'), '_INSTANCECAN(Baz object, foo) returns undef'); - -# Good values - only objects whose class genuinely provides 'foo' -foreach my $object (grep { $_->can('foo') } @objects) -{ - ok(_INSTANCECAN($object, 'foo'), '_INSTANCECAN(object, foo) returns true when expected'); - is(refaddr(_INSTANCECAN($object, 'foo')), refaddr($object), '_INSTANCECAN(object, foo) returns the same object'); -} - -##################################################################### -# Tests for _INVOCANTCAN - -use_ok('Params::Util', '_INVOCANTCAN'); -ok(defined *_INVOCANTCAN{CODE}, '_INVOCANTCAN imported ok'); - -# Bad values -null(_INVOCANTCAN(undef, 'foo'), '_INVOCANTCAN(undef, method) returns undef'); -null(_INVOCANTCAN('', 'foo'), '_INVOCANTCAN(empty, method) returns undef'); -null(_INVOCANTCAN({}, 'foo'), '_INVOCANTCAN(unblessed HASH, method) returns undef'); -null(_INVOCANTCAN('Bad', 'foo'), '_INVOCANTCAN(Bad, foo) returns undef'); -null(_INVOCANTCAN(bless({}, 'Bad'), 'foo'), '_INVOCANTCAN(bad object, foo) returns undef'); - -# Good values - class -is(_INVOCANTCAN('Foo', 'foo'), 'Foo', '_INVOCANTCAN(Foo class, foo) returns class name'); - -# Baz fakes isa but does not provide 'foo' -null(_INVOCANTCAN(bless({}, 'Baz'), 'foo'), '_INVOCANTCAN(Baz object, foo) returns undef'); - -# Good values - object -foreach my $object (grep { $_->can('foo') } @objects) -{ - ok(_INVOCANTCAN($object, 'foo'), '_INVOCANTCAN(object, foo) returns true when expected'); - is(refaddr(_INVOCANTCAN($object, 'foo')), refaddr($object), '_INVOCANTCAN(object, foo) returns the same object'); -} - -##################################################################### -# Tests for _REGEX - -# Test bad things against the actual function -dies("Params::Util::_REGEX();", qr/Not enough arguments/, '...::_REGEX() dies'); -null(Params::Util::_REGEX(undef), '...::_REGEX(undef) returns undef'); -null(Params::Util::_REGEX(''), '...::_REGEX(STRING0) returns undef'); -null(Params::Util::_REGEX(1), '...::_REGEX(number) returns undef'); -null(Params::Util::_REGEX('foo'), '...::_REGEX(string) returns undef'); -null(Params::Util::_REGEX(\'foo'), '...::_REGEX(SCALAR) returns undef'); -null(Params::Util::_REGEX(['foo']), '...::_REGEX(ARRAY) returns undef'); -null(Params::Util::_REGEX(sub () { 1 }), '...::_REGEX(CODE) returns undef'); -null(Params::Util::_REGEX({}), '...::_REGEX(HASH0) returns undef'); -null(Params::Util::_REGEX({foo => 1}), '...::_REGEX(HASH) returns undef'); -ok(Params::Util::_REGEX(qr//), '...::_REGEX(qr//) ok'); -ok(Params::Util::_REGEX(qr/foo/), '...::_REGEX(qr//) ok'); - -# Import the function -use_ok('Params::Util', '_REGEX'); -ok(defined *_REGEX{CODE}, '_REGEX imported ok'); - -# Test bad things against the actual function -dies("_REGEX();", qr/Not enough arguments/, '_REGEX() dies'); -null(_REGEX(undef), '_REGEX(undef) returns undef'); -null(_REGEX(''), '_REGEX(STRING0) returns undef'); -null(_REGEX(1), '_REGEX(number) returns undef'); -null(_REGEX('foo'), '_REGEX(string) returns undef'); -null(_REGEX(\'foo'), '_REGEX(SCALAR) returns undef'); -null(_REGEX([]), '_REGEX(ARRAY) returns undef'); -null(_REGEX(sub () { 1 }), '_REGEX(CODE) returns undef'); -null(_REGEX({}), 'REGEX(HASH0) returns undef'); -null(_REGEX({foo => 1}), 'REGEX(HASH) returns undef'); -ok(_REGEX(qr//), '_REGEX(qr//) ok'); -ok(_REGEX(qr/foo/), '_REGEX(qr//) ok'); - -##################################################################### -# Tests for _SET - -my %set = ( - good => [map { bless {} => 'Foo' } qw(1..3)], - mixed => [map { bless {} => "Foo$_" } qw(1..3)], - unblessed => [map { {} } qw(1..3)], -); - -# Test bad things against the actual function -dies("Params::Util::_SET()", qr/Not enough arguments/, '...::_SET() dies'); -dies("Params::Util::_SET([])", qr/Not enough arguments/, '...::_SET(single) dies'); -null(Params::Util::_SET(undef, 'Foo'), '...::_SET(undef) returns undef'); -null(Params::Util::_SET('', 'Foo'), '...::_SET(nullstring) returns undef'); -null(Params::Util::_SET(1, 'Foo'), '...::_SET(number) returns undef'); -null(Params::Util::_SET('foo', 'Foo'), '...::_SET(string) returns undef'); -null(Params::Util::_SET(\'foo', 'Foo'), '...::_SET(SCALAR) returns undef'); -null(Params::Util::_SET({foo => 1}, 'Foo'), '...::_SET(HASH) returns undef'); -null(Params::Util::_SET(sub () { 1 }, 'Foo'), '...::_SET(CODE) returns undef'); -null(Params::Util::_SET([], 'Foo'), '...::_SET(empty ARRAY) returns undef'); -ok(Params::Util::_SET($set{good}, 'Foo'), '...::_SET(homogenous ARRAY) returns true'); -null(Params::Util::_SET($set{mixed}, 'Foo'), '...::_SET(mixed ARRAY) returns undef'); -null(Params::Util::_SET($set{unblessed}, 'Foo'), '...::_SET(unblessed ARRAY) returns undef'); - -# Import the function -use_ok('Params::Util', '_SET'); -ok(defined *_SET{CODE}, '_SET imported ok'); - -# Test bad things against the actual function -dies("_SET()", qr/Not enough arguments/, '_SET() dies'); -dies("_SET([])", qr/Not enough arguments/, '_SET(single) dies'); -null(_SET(undef, 'Foo'), '_SET(undef) returns undef'); -null(_SET('', 'Foo'), '_SET(nullstring) returns undef'); -null(_SET(1, 'Foo'), '_SET(number) returns undef'); -null(_SET('foo', 'Foo'), '_SET(string) returns undef'); -null(_SET(\'foo', 'Foo'), '_SET(SCALAR) returns undef'); -null(_SET({foo => 1}, 'Foo'), '_SET(HASH) returns undef'); -null(_SET(sub () { 1 }, 'Foo'), '_SET(CODE) returns undef'); -null(_SET([], 'Foo'), '_SET(empty ARRAY) returns undef'); - -ok(_SET($set{good}, 'Foo'), '_SET(homogenous ARRAY) returns true'); -null(_SET($set{mixed}, 'Foo'), '_SET(mixed ARRAY) returns undef'); -null(_SET($set{unblessed}, 'Foo'), '_SET(unblessed ARRAY) returns undef'); - -##################################################################### -# Tests for _SET0 - -# Test bad things against the actual function -dies("Params::Util::_SET0()", qr/Not enough arguments/, '...::_SET0() dies'); -dies("Params::Util::_SET0([])", qr/Not enough arguments/, '...::_SET0(single) dies'); -null(Params::Util::_SET0(undef, 'Foo'), '...::_SET0(undef) returns undef'); -null(Params::Util::_SET0('', 'Foo'), '...::_SET0(nullstring) returns undef'); -null(Params::Util::_SET0(1, 'Foo'), '...::_SET0(number) returns undef'); -null(Params::Util::_SET0('foo', 'Foo'), '...::_SET0(string) returns undef'); -null(Params::Util::_SET0(\'foo', 'Foo'), '...::_SET0(SCALAR) returns undef'); -null(Params::Util::_SET0({foo => 1}, 'Foo'), '...::_SET0(HASH) returns undef'); -null(Params::Util::_SET0(sub () { 1 }, 'Foo'), '...::_SET0(CODE) returns undef'); -ok(Params::Util::_SET0([], 'Foo'), '...::_SET0(empty ARRAY) returns true'); -ok(Params::Util::_SET0($set{good}, 'Foo'), '...::_SET0(homogenous ARRAY) returns true'); -null(Params::Util::_SET0($set{mixed}, 'Foo'), '...::_SET0(mixed ARRAY) returns undef'); -null(Params::Util::_SET0($set{unblessed}, 'Foo'), '...::_SET0(unblessed ARRAY) returns undef'); - -# Import the function -use_ok('Params::Util', '_SET0'); -ok(defined *_SET0{CODE}, '_SET0 imported ok'); - -# Test bad things against the actual function -dies("_SET0()", qr/Not enough arguments/, '_SET0() dies'); -dies("_SET0([])", qr/Not enough arguments/, '_SET0(single) dies'); -null(_SET0(undef, 'Foo'), '_SET0(undef) returns undef'); -null(_SET0('', 'Foo'), '_SET0(nullstring) returns undef'); -null(_SET0(1, 'Foo'), '_SET0(number) returns undef'); -null(_SET0('foo', 'Foo'), '_SET0(string) returns undef'); -null(_SET0(\'foo', 'Foo'), '_SET0(SCALAR) returns undef'); -null(_SET0({foo => 1}, 'Foo'), '_SET0(HASH) returns undef'); -null(_SET0(sub () { 1 }, 'Foo'), '_SET0(CODE) returns undef'); -ok(_SET0([], 'Foo'), '_SET0(empty ARRAY) returns true'); -ok(_SET0($set{good}, 'Foo'), '_SET0(homogenous ARRAY) returns true'); -null(_SET0($set{mixed}, 'Foo'), '_SET0(mixed ARRAY) returns undef'); -null(_SET0($set{unblessed}, 'Foo'), '_SET0(unblessed ARRAY) returns undef'); - -exit(0); - -# Base class -package Foo; - -sub foo { 1 } - -# Normal inheritance -package Bar; - -use vars qw{@ISA}; - -BEGIN -{ - @ISA = 'Foo'; -} - -# Coded isa -package Baz; - -sub isa -{ - return 1 if $_[1] eq 'Foo'; - shift->SUPER::isa(@_); -} - -# Not a subclass -package Bad; - -sub bad { 1 } - -1; diff --git a/t/xs/03_all.t b/t/xs/03_all.t deleted file mode 100755 index 4f0a181..0000000 --- a/t/xs/03_all.t +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/perl - -use strict; - -BEGIN -{ - $| = 1; - $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 0; -} - -use Test::More tests => 26; -use File::Spec::Functions ':ALL'; - -BEGIN -{ - use_ok('Params::Util', ':ALL'); -} - -##################################################################### -# Is everything imported - -ok(defined &_STRING, '_STRING imported ok'); -ok(defined &_IDENTIFIER, '_IDENTIFIER imported ok'); - -ok(defined &_CLASS, '_CLASS imported ok'); -ok(defined &_CLASSISA, '_CLASSISA imported ok'); -ok(defined &_SUBCLASS, '_SUBCLASS imported ok'); -ok(defined &_DRIVER, '_DRIVER imported ok'); - -ok(defined &_NUMBER, '_NUMBER imported ok'); -ok(defined &_POSINT, '_POSINT imported ok'); -ok(defined &_NONNEGINT, '_NONNEGINT imported ok'); - -ok(defined &_SCALAR, '_SCALAR imported ok'); -ok(defined &_SCALAR0, '_SCALAR0 imported ok'); - -ok(defined &_ARRAY, '_ARRAY imported ok'); -ok(defined &_ARRAY0, '_ARRAY0 imported ok'); -ok(defined &_ARRAYLIKE, '_ARRAYLIKE imported ok'); - -ok(defined &_HASH, '_HASH imported ok'); -ok(defined &_HASH0, '_HASH0 imported ok'); -ok(defined &_HASHLIKE, '_HASHLIKE imported ok'); - -ok(defined &_CODE, '_CODE imported ok'); -ok(defined &_CODELIKE, '_CODELIKE imported ok'); - -ok(defined &_INVOCANT, '_INVOCANT imported ok'); -ok(defined &_INSTANCE, '_INSTANCE imported ok'); -ok(defined &_REGEX, '_REGEX imported ok'); - -ok(defined &_SET, '_SET imported ok'); -ok(defined &_SET0, '_SET0 imported ok'); - -ok(defined &_HANDLE, '_HANDLE imported ok'); diff --git a/t/xs/05_typelike.t b/t/xs/05_typelike.t deleted file mode 100644 index 4ecd2fe..0000000 --- a/t/xs/05_typelike.t +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/perl - -use strict; - -BEGIN -{ - $| = 1; - $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 0; -} - -use Test::More tests => 44; -use Scalar::Util 'refaddr'; -use File::Spec::Functions ':ALL'; -use Params::Util qw{_ARRAYLIKE _HASHLIKE}; - -# Tests that two objects are the same object -sub addr -{ - my $have = shift; - my $want = shift; - is(refaddr($have), refaddr($want), 'Objects are the same object'); -} - -my $listS = bless \do { my $i } - => 'Foo::Listy'; -my $hashS = bless \do { my $i } - => 'Foo::Hashy'; -my $bothS = bless \do { my $i } - => 'Foo::Bothy'; - -my $listH = bless {} => 'Foo::Listy'; -my $hashH = bless {} => 'Foo::Hashy'; -my $bothH = bless {} => 'Foo::Bothy'; - -my $listA = bless [] => 'Foo::Listy'; -my $hashA = bless [] => 'Foo::Hashy'; -my $bothA = bless [] => 'Foo::Bothy'; - -my @data = ( # A H - [undef, 0, 0, 'undef'], - [ - 1000 => 0, - 0, '1000' - ], - [ - 'Foo' => 0, - 0, '"Foo"' - ], - [ - [] => 1, - 0, '[]' - ], - [ - {} => 0, - 1, '{}' - ], - [ - $listS => 1, - 0, 'scalar-based Foo::Listy' - ], - [ - $hashS => 0, - 1, 'scalar-based Foo::Hashy' - ], - [ - $bothS => 1, - 1, 'scalar-based Foo::Bothy' - ], - [ - $listH => 1, - 1, 'hash-based Foo::Listy' - ], - [ - $hashH => 0, - 1, 'hash-based Foo::Hashy' - ], - [ - $bothH => 1, - 1, 'hash-based Foo::Bothy' - ], - [ - $listA => 1, - 0, 'array-based Foo::Listy' - ], - [ - $hashA => 1, - 1, 'array-based Foo::Hashy' - ], - [ - $bothA => 1, - 1, 'array-based Foo::Bothy' - ], -); - -for my $t (@data) -{ - is(_ARRAYLIKE($t->[0]) ? 1 : 0, $t->[1], "$t->[3] " . ($t->[1] ? 'is' : "isn't") . ' @ish'); - if (_ARRAYLIKE($t->[0])) - { - addr(_ARRAYLIKE($t->[0]), $t->[0]); - } - is(_HASHLIKE($t->[0]) ? 1 : 0, $t->[2], "$t->[3] " . ($t->[2] ? 'is' : "isn't") . ' %ish'); - if (_HASHLIKE($t->[0])) - { - addr(_HASHLIKE($t->[0]), $t->[0]); - } -} - -package Foo; -# this package is totally unremarkable; - -package Foo::Listy; -use overload - '@{}' => sub { [] }, - fallback => 1; - -package Foo::Hashy; -use overload - '%{}' => sub { {} }, - fallback => 1; - -package Foo::Bothy; -use overload - '@{}' => sub { [] }, - '%{}' => sub { {} }, - fallback => 1; diff --git a/t/xs/06_invocant.t b/t/xs/06_invocant.t deleted file mode 100644 index 4020c9b..0000000 --- a/t/xs/06_invocant.t +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/perl - -use strict; - -BEGIN -{ - $| = 1; - $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 0; -} - -use Test::More tests => 11; -use File::Spec::Functions ':ALL'; - -BEGIN -{ - use_ok('Params::Util', qw(_INVOCANT)); -} - -my $object = bless \do { my $i } - => 'Params::Util::Test::Bogus::Whatever'; -my $false_obj1 = bless \do { my $i } - => 0; -my $false_obj2 = bless \do { my $i } - => "\0"; -my $tied = tie my $x, 'Params::Util::Test::_INVOCANT::Tied'; -my $unpkg = 'Params::Util::Test::_INVOCANT::Fake'; -my $pkg = 'Params::Util::Test::_INVOCANT::Real'; -eval "package $pkg;"; ## no critic - -my @data = ( # I - [undef, 0, 'undef'], - [ - 1000 => 0, - '1000' - ], - [ - $unpkg => 1, - qq("$unpkg") - ], - [ - $pkg => 1, - qq("$pkg") - ], - [ - [] => 0, - '[]' - ], - [ - {} => 0, - '{}' - ], - [ - $object => 1, - 'blessed reference' - ], - [ - $false_obj1 => 1, - 'blessed reference' - ], - [ - $tied => 1, - 'tied value' - ], -); - -for my $datum (@data) -{ - is(_INVOCANT($datum->[0]) ? 1 : 0, $datum->[1], "$datum->[2] " . ($datum->[1] ? 'is' : "isn't") . " _IN"); -} - -# Skip the most evil test except on automated testing, because it -# fails on at least one common production OS (RedHat Enterprise Linux 4) -# and the test case should be practically impossible to encounter -# in real life. The damage the bug could cause users in production is -# far lower than the damage caused by Params::Util failing to install. -SKIP: -{ - unless ($ENV{AUTOMATED_TESTING}) - { - skip("Skipping nasty test unless AUTOMATED_TESTING", 1); - } - ok(!!_INVOCANT($false_obj2), 'Testing null class as an invocant'); -} - -package Params::Util::Test::_INVOCANT::Tied; - -sub TIESCALAR -{ - my ($class, $value) = @_; - return bless \$value => $class; -} diff --git a/t/xs/07_handle.t b/t/xs/07_handle.t deleted file mode 100644 index 67165a0..0000000 --- a/t/xs/07_handle.t +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/perl - -use strict; - -BEGIN -{ - $| = 1; - $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 0; -} - -use Test::More tests => 23; -use File::Spec::Functions ':ALL'; - -BEGIN -{ - ok(!defined &_HANDLE, '_HANDLE does not exist'); - use_ok('Params::Util', qw(_HANDLE)); - ok(defined &_HANDLE, '_HANDLE imported ok'); -} - -# Import refaddr to make certain we have it -use Scalar::Util 'refaddr'; - -##################################################################### -# Preparing - -my $readfile = catfile('t', 'handles', 'readfile.txt'); -ok(-f $readfile, "$readfile exists"); -my $writefile = catfile('t', 'handles', 'writefile.txt'); -if (-f $writefile) { unlink $writefile } - -END -{ - if (-f $writefile) { unlink $writefile } -} -ok(!-e $writefile, "$writefile does not exist"); - -sub is_handle -{ - my $maybe = shift; - my $message = shift || 'Is a file handle'; - my $result = _HANDLE($maybe); - ok(defined $result, '_HANDLE does not return undef'); - is(refaddr($result), refaddr($maybe), '_HANDLE returns the passed value'); -} - -sub not_handle -{ - my $maybe = shift; - my $message = shift || 'Is not a file handle'; - my $result = _HANDLE($maybe); - ok(!defined $result, '_HANDLE returns undef'); -} - -##################################################################### -# Basic Filesystem Handles - -# A read filehandle -SCOPE: -{ - local *HANDLE; - open(HANDLE, $readfile); - is_handle(\*HANDLE, 'Ordinary read filehandle'); - close HANDLE; -} - -# A write filehandle -SCOPE: -{ - local *HANDLE; - open(HANDLE, "> $readfile"); - is_handle(\*HANDLE, 'Ordinary read filehandle'); - print HANDLE "A write filehandle"; - close HANDLE; - if (-f $writefile) { unlink $writefile } -} - -# On 5.8+ the new style filehandle -SKIP: -{ - skip("Skipping 5.8-style 'my \$fh' handles", 2) if $] < 5.008; - open(my $handle, $readfile); - is_handle($handle, '5.8-style read filehandle'); -} - -##################################################################### -# Things that are not file handles - -foreach (undef, '', ' ', 'foo', 1, 0, -1, 1.23, [], {}, \'', bless({}, "foo")) -{ - not_handle($_); -} - diff --git a/t/xs/09_insideout.t b/t/xs/09_insideout.t deleted file mode 100644 index 527b4cc..0000000 --- a/t/xs/09_insideout.t +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/perl - -# Test for a custom isa method that returns the same way that -# Object::InsideOut does. - -use strict; - -BEGIN -{ - $| = 1; - $^W = 1; - $ENV{PERL_PARAMS_UTIL_PP} ||= 0; -} - -use Test::More tests => 2; -use Scalar::Util (); -use Params::Util (); - -##################################################################### -# Create an object and test it - -SCOPE: -{ - my $object = Foo->new; - ok(Scalar::Util::blessed($object), 'Foo'); - my $instance = Params::Util::_INSTANCE($object, 'Foo'); - is($instance, undef, '_INSTANCE correctly returns undef'); -} - -##################################################################### -# Create a package to simulate Object::InsideOut - -CLASS: -{ - - package Foo; - - sub new - { - my $foo = 1234; - my $self = \$foo; - bless $self, $_[0]; - return $self; - } - - sub isa - { - return (''); - } - - 1; -} diff --git a/xt/perltidy.t b/xt/perltidy.t index 75f1dde..c0cb827 100644 --- a/xt/perltidy.t +++ b/xt/perltidy.t @@ -8,6 +8,5 @@ use Test::PerlTidy; run_tests( perltidyrc => '.perltidyrc', - exclude => - ['travis-perl-helpers', 'inc/inc_Capture-Tiny', 'inc/inc_Config-AutoConf', 'inc/latest.pm', 'inc/latest/private.pm'], + exclude => ['inc/inc_Capture-Tiny', 'inc/inc_Config-AutoConf', 'inc/latest.pm', 'inc/latest/private.pm', 't/pp', 't/xs',], ); diff --git a/xt/spelling.t b/xt/spelling.t index 83006dc..fe6adab 100644 --- a/xt/spelling.t +++ b/xt/spelling.t @@ -7,6 +7,7 @@ add_stopwords(); all_pod_files_spelling_ok(); __END__ +ADR dist importable Jens From 707bcf68665a56855be6f781e23d0a9236477a73 Mon Sep 17 00:00:00 2001 From: Jens Rehsack Date: Sat, 2 May 2026 14:45:47 +0200 Subject: [PATCH 3/8] Document open design decisions as ADRs ADR-002: Multi-method signatures for `_CAN` and `_DOES` (proposed) ADR-003: `Params::Util::Assert` assertion variants (proposed) ADR-004: `Test::Params::Util` as separate distribution (proposed) Cross-reference the ADRs from the TO DO section in the main POD so future contributors find the design context directly. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Jens Rehsack --- lib/Params/Util.pm | 6 ++- lib/Params/Util/ADR-002.pod | 78 +++++++++++++++++++++++++++++++ lib/Params/Util/ADR-003.pod | 91 +++++++++++++++++++++++++++++++++++++ lib/Params/Util/ADR-004.pod | 79 ++++++++++++++++++++++++++++++++ xt/spelling.t | 2 + 5 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 lib/Params/Util/ADR-002.pod create mode 100644 lib/Params/Util/ADR-003.pod create mode 100644 lib/Params/Util/ADR-004.pod diff --git a/lib/Params/Util.pm b/lib/Params/Util.pm index e50e65d..e98bfd1 100755 --- a/lib/Params/Util.pm +++ b/lib/Params/Util.pm @@ -473,9 +473,11 @@ or the class fails the isa test. =head1 TO DO - Implement an assertion-like version of this module, that dies on -error. +error. See L for design considerations. -- Implement a Test:: version of this module, for use in testing +- Implement a Test:: version of this module, for use in testing. +See L for the rationale to ship it as a +separate distribution. =head1 SUPPORT diff --git a/lib/Params/Util/ADR-002.pod b/lib/Params/Util/ADR-002.pod new file mode 100644 index 0000000..96f3b86 --- /dev/null +++ b/lib/Params/Util/ADR-002.pod @@ -0,0 +1,78 @@ +=head1 ADR-002: Multi-method signatures for CAN and DOES predicates + +=head2 Status + +Proposed + +=head2 Context + +The current C<_CLASSCAN>, C<_INSTANCECAN>, C<_INVOCANTCAN>, +C<_CLASSDOES>, and C<_INSTANCEDOES> predicates accept exactly one +method or role name (C<$$> prototype). + +In practice, callers often need to verify that an invocant satisfies +multiple capabilities at once (e.g. "provides both C and +C") or fulfils several roles simultaneously. Today this +requires chaining multiple calls: + + _INSTANCECAN($obj, 'connect') and _INSTANCECAN($obj, 'disconnect') + +This is verbose and evaluates the blessed/class check repeatedly. + +=head2 Decision + +B Introduce multi-method variants once a concrete consumer +demonstrates the need. The design space includes: + +=over 4 + +=item Signature change + +C<_INSTANCECAN($obj, @methods)> -- breaks the C<$$> prototype. +Prototypes cannot express C<$@>, so the function would need to drop +its prototype or use a different calling convention. + +=item Semantic: AND vs OR + +Multiple arguments most naturally mean "provides all of these" (AND). +An OR semantic ("provides at least one") is a different use case and +would warrant a separate function name to avoid ambiguity. + +=item XS implications + +A variadic XS implementation must loop over the method list in C, +calling C<< ->can >> or C<< ->DOES >> for each. The early-exit on +first failure makes this efficient, but the stack handling differs +from the current fixed-arity pattern. + +=item Interaction with Assert (ADR-003) + +An assertion variant that reports I method is missing benefits +from knowing the full list up front rather than failing on the first +chained call. + +=back + +=head2 Consequences + +=over 4 + +=item * + +No action required now; the C<$$> variants are sufficient for the +initial release. + +=item * + +When a consumer emerges, the multi-method variant should be added as a +new function name (e.g. C<_INSTANCECAN_ALL>) rather than changing the +existing C<$$> signature, preserving backwards compatibility. + +=item * + +The same pattern applies to C<_CLASSDOES> / C<_INSTANCEDOES> for +verifying multiple roles simultaneously. + +=back + +=cut diff --git a/lib/Params/Util/ADR-003.pod b/lib/Params/Util/ADR-003.pod new file mode 100644 index 0000000..7faa122 --- /dev/null +++ b/lib/Params/Util/ADR-003.pod @@ -0,0 +1,91 @@ +=head1 ADR-003: Params::Util::Assert -- assertion variants + +=head2 Status + +Proposed + +=head2 Context + +Params::Util predicates return the value on success or C on +failure. Callers that want to die on invalid input must wrap each +check: + + my $obj = _INSTANCE($val, 'Foo') or croak "expected a Foo"; + +This pattern is repetitive. An assertion module that dies directly +would be more ergonomic and -- in XS -- more efficient, since it avoids +the Perl-level conditional after the C<< ->isa >> / C<< ->can >> call. + +=head2 Decision + +B Ship C as a separate module +within the same distribution once the interface stabilises. Key open +questions: + +=over 4 + +=item Error behaviour + +C vs C vs throwing a structured exception object. +Different consumers need different behaviour; a single hard-coded +C does not serve them all. + +=item Error message content + +Minimally useful: the predicate name and the failing value's type. +Maximally useful: parameter name, expected type, caller context. The +richer the message, the more the interface must accept (extra +arguments or configuration). + +=item Batch validation + +Validating all parameters up front and collecting all failures (rather +than dying on the first) is common in form/API validation. This +fundamentally changes the control flow and may warrant a separate +interface rather than extending the per-parameter assertion. + +=item XS integration + +A direct C from XS avoids the return-check-croak round-trip. +However, baking error-message formatting into C makes the module +harder to extend. A possible middle ground: XS performs the check and +calls a configurable Perl-level formatter only on the failure path. + +=item Relationship to type systems + +L, L, and Moose type constraints already provide +assertion semantics. C should complement rather +than compete -- it targets the lightweight, no-dependency niche where +full type systems are overkill. + +=back + +=head2 Consequences + +=over 4 + +=item * + +No code ships until a concrete consumer clarifies the interface +requirements. + +=item * + +When implemented, the module lives in F +within the Params-Util distribution -- no separate dist, no runtime +pollution for users who do not load it. + +=item * + +XS acceleration is desirable but must not lock in an error-reporting +strategy that cannot be overridden from Perl. + +=item * + +The Assert interface should be designed with ADR-002 in mind: if +multi-method C<_CAN> / C<_DOES> variants exist, the assertion should +report which specific method or role was missing. + +=back + +=cut diff --git a/lib/Params/Util/ADR-004.pod b/lib/Params/Util/ADR-004.pod new file mode 100644 index 0000000..62eeadf --- /dev/null +++ b/lib/Params/Util/ADR-004.pod @@ -0,0 +1,79 @@ +=head1 ADR-004: Test::Params::Util -- test predicates + +=head2 Status + +Proposed + +=head2 Context + +The original TODO list for Params::Util included a "Test:: version of +this module, for use in testing." The idea is to provide test +functions that produce TAP-compatible diagnostics: + + instance_ok($obj, 'Foo', 'constructor returns a Foo'); + can_ok_methods($obj, qw(connect disconnect)); + +Perl's testing ecosystem already offers L and +L, but these do not cover the full range of +Params::Util predicates (C<_CODELIKE>, C<_HASHLIKE>, C<_HANDLE>, +C<_DRIVER>, etc.). + +=head2 Decision + +Implement C as a B. + +=over 4 + +=item Why not in the Params-Util dist? + +Test modules depend on L or L. Params::Util is a +zero-non-core-dependency module used deep in dependency chains. +Pulling test infrastructure into its prerequisites would create +circular or heavyweight dependencies for something that is only needed +at test time. + +=item Why not a bundled module excluded from runtime? + +Even as an optional module, shipping it in the same dist means the +F<.pm> file is installed into C<@INC>. Build systems that scan +installed modules (e.g. for dependency resolution) would see the +Test2 dependency regardless of whether the module is ever loaded. + +=item Pollution concern + +Unlike C (ADR-003), which shares implementation +with the core predicates, C only I the +predicates -- it has no privileged access to internals. A separate +dist with C as a runtime prerequisite is the natural +factoring. + +=back + +=head2 Consequences + +=over 4 + +=item * + +C depends on C and +C (or L). + +=item * + +Its release cycle is independent; new Params::Util predicates can +ship before matching test functions exist, and vice versa. + +=item * + +The test module should mirror the Params::Util export list: for each +C<_FOO> predicate, provide a corresponding C (or similar) +test function that produces useful diagnostics on failure. + +=item * + +This ADR does not block any work in the Params-Util distribution +itself. + +=back + +=cut diff --git a/xt/spelling.t b/xt/spelling.t index fe6adab..7a9effb 100644 --- a/xt/spelling.t +++ b/xt/spelling.t @@ -8,6 +8,7 @@ all_pod_files_spelling_ok(); __END__ ADR +arity dist importable Jens @@ -15,4 +16,5 @@ param params PurePerl Rehsack +TODO Util From 889f901dbdab14f7497aadd9e889d07009570a7b Mon Sep 17 00:00:00 2001 From: Jens Rehsack Date: Sat, 2 May 2026 14:52:11 +0200 Subject: [PATCH 4/8] Update SUPPORT section to point to GitHub RT is kept as historical reference but GitHub Issues is now the primary channel for bugs and feature requests. Also update the copyright year range. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Jens Rehsack --- lib/Params/Util.pm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Params/Util.pm b/lib/Params/Util.pm index e98bfd1..9574921 100755 --- a/lib/Params/Util.pm +++ b/lib/Params/Util.pm @@ -481,9 +481,17 @@ separate distribution. =head1 SUPPORT -Bugs should be reported via the CPAN bug tracker at +Bugs and feature requests should be reported via GitHub Issues at -L +L + +The source repository is at + +L + +For historical bug reports, see the CPAN RT queue at + +L =head1 AUTHOR @@ -499,7 +507,7 @@ L Copyright 2005 - 2012 Adam Kennedy. -Copyright 2020 - 2020 Jens Rehsack. +Copyright 2020 - 2026 Jens Rehsack. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. From 3fb6536d67a9816b84489f661b0106ce17ba5a59 Mon Sep 17 00:00:00 2001 From: Jens Rehsack Date: Sat, 2 May 2026 15:13:48 +0200 Subject: [PATCH 5/8] Consolidate XS via ALIAS and add missing accelerators Refactor _INSTANCE/_INSTANCECAN into a single ALIAS group (Group 4) and add XS implementations for all previously PP-only predicates: - Group 1: _IDENTIFIER, _CLASS - Group 2: _POSINT, _NONNEGINT - Group 3: _CLASSISA, _CLASSDOES, _CLASSCAN, _SUBCLASS - Group 5: _INVOCANT, _INVOCANTCAN See ADR-005 for the rationale behind using ALIAS over duplicated XSUBs. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Jens Rehsack --- Util.xs | 444 ++++++++++++++++++++++++++++-------- lib/Params/Util/ADR-005.pod | 115 ++++++++++ xt/spelling.t | 1 + 3 files changed, 464 insertions(+), 96 deletions(-) create mode 100644 lib/Params/Util/ADR-005.pod diff --git a/Util.xs b/Util.xs index 9548247..5cf6109 100644 --- a/Util.xs +++ b/Util.xs @@ -75,6 +75,50 @@ is_like( SV *sv, const char *like ) return likely; } +/* Validate that pv/len is a valid Perl identifier (no ::) */ +static int +is_identifier( const char *pv, STRLEN len ) +{ + STRLEN i; + if( len == 0 || !isALPHA(*pv) && *pv != '_' ) + return 0; + for( i = 1; i < len; i++ ) + { + if( !isALNUM(pv[i]) ) + return 0; + } + return 1; +} + +/* Validate that pv/len is a valid Perl class name (identifiers joined by ::) */ +static int +is_class( const char *pv, STRLEN len ) +{ + STRLEN i; + if( len == 0 ) + return 0; + /* first char must be alpha or underscore */ + if( !isALPHA(*pv) && *pv != '_' ) + return 0; + for( i = 1; i < len; i++ ) + { + if( pv[i] == ':' ) + { + /* must be :: followed by \w */ + if( i + 2 >= len || pv[i+1] != ':' ) + return 0; + i += 2; + if( !isALNUM(pv[i]) ) + return 0; + } + else if( !isALNUM(pv[i]) ) + { + return 0; + } + } + return 1; +} + MODULE = Params::Util PACKAGE = Params::Util void @@ -109,6 +153,310 @@ CODE: XSRETURN_UNDEF; } +## Group 1: String validators + +void +_IDENTIFIER(sv) + SV *sv; +PROTOTYPE: $ +ALIAS: + _IDENTIFIER = 0 + _CLASS = 1 +CODE: +{ + STRLEN len; + const char *pv; + if( SvMAGICAL(sv) ) + mg_get(sv); + if( !is_string0(sv) ) + XSRETURN_UNDEF; + pv = SvPV(sv, len); + if( len == 0 ) + XSRETURN_UNDEF; + if( ix == 0 ) + { + if( is_identifier(pv, len) ) + { + ST(0) = sv; + XSRETURN(1); + } + } + else + { + if( is_class(pv, len) ) + { + ST(0) = sv; + XSRETURN(1); + } + } + XSRETURN_UNDEF; +} + +## Group 2: Numeric validators + +void +_POSINT(sv) + SV *sv; +PROTOTYPE: $ +ALIAS: + _POSINT = 0 + _NONNEGINT = 1 +CODE: +{ + STRLEN len; + const char *pv; + STRLEN i; + if( SvMAGICAL(sv) ) + mg_get(sv); + if( SvROK(sv) ) + XSRETURN_UNDEF; + if( !is_string0(sv) ) + XSRETURN_UNDEF; + pv = SvPV(sv, len); + if( len == 0 ) + XSRETURN_UNDEF; + if( ix == 0 ) + { + /* _POSINT: first digit must be 1-9 */ + if( pv[0] < '1' || pv[0] > '9' ) + XSRETURN_UNDEF; + } + else + { + /* _NONNEGINT: "0" is ok, otherwise first digit 1-9 */ + if( len == 1 && pv[0] == '0' ) + { + ST(0) = sv; + XSRETURN(1); + } + if( pv[0] < '1' || pv[0] > '9' ) + XSRETURN_UNDEF; + } + for( i = 1; i < len; i++ ) + { + if( pv[i] < '0' || pv[i] > '9' ) + XSRETURN_UNDEF; + } + ST(0) = sv; + XSRETURN(1); +} + +## Group 3: Class dispatchers + +void +_CLASSISA(sv, arg) + SV *sv; + char *arg; +PROTOTYPE: $$ +ALIAS: + _CLASSISA = 0 + _CLASSDOES = 1 + _CLASSCAN = 2 + _SUBCLASS = 3 +CODE: +{ + static const char *methods[] = {"isa", "DOES", "can", "isa"}; + STRLEN svlen; + const char *pv; + STRLEN arglen; + if( SvMAGICAL(sv) ) + mg_get(sv); + if( !is_string0(sv) ) + XSRETURN_UNDEF; + pv = SvPV(sv, svlen); + if( svlen == 0 || !is_class(pv, svlen) ) + XSRETURN_UNDEF; + if( !arg || ( ( arglen = strlen(arg) ) == 0 ) ) + XSRETURN_UNDEF; + + /* _SUBCLASS: must not be the same class */ + if( ix == 3 && svlen == arglen && strEQ(pv, arg) ) + XSRETURN_UNDEF; + + { + I32 result = 0; + int count; + + ENTER; + SAVETMPS; + PUSHMARK(SP); + XPUSHs( sv_2mortal( newSVsv( sv ) ) ); + XPUSHs( sv_2mortal( newSVpv( arg, arglen ) ) ); + PUTBACK; + + if( ( count = call_method(methods[ix], G_SCALAR) ) ) + { + I32 oldax = ax; + SPAGAIN; + SP -= count; + ax = (SP - PL_stack_base) + 1; + result = SvTRUE(ST(0)); + ax = oldax; + } + + PUTBACK; + FREETMPS; + LEAVE; + + if( result ) + { + ST(0) = sv; + XSRETURN(1); + } + } + XSRETURN_UNDEF; +} + +## Group 4: Instance dispatchers + +void +_INSTANCE(ref, arg) + SV *ref; + char *arg; +PROTOTYPE: $$ +ALIAS: + _INSTANCE = 0 + _INSTANCEDOES = 1 + _INSTANCECAN = 2 +CODE: +{ + static const char *methods[] = {"isa", "DOES", "can"}; + STRLEN len; + if( SvMAGICAL(ref) ) + mg_get(ref); + if( SvROK(ref) && arg && ( ( len = strlen(arg) ) > 0 ) ) + { + if( sv_isobject(ref) ) + { + I32 result = 0; + int count; + + ENTER; + SAVETMPS; + PUSHMARK(SP); + XPUSHs( sv_2mortal( newSVsv( ref ) ) ); + XPUSHs( sv_2mortal( newSVpv( arg, len ) ) ); + PUTBACK; + + if( ( count = call_method(methods[ix], G_SCALAR) ) ) + { + I32 oldax = ax; + SPAGAIN; + SP -= count; + ax = (SP - PL_stack_base) + 1; + result = SvTRUE(ST(0)); + ax = oldax; + } + + PUTBACK; + FREETMPS; + LEAVE; + + if( result ) + { + ST(0) = ref; + XSRETURN(1); + } + } + } + XSRETURN_UNDEF; +} + +## Group 5: Invocant dispatchers + +void +_INVOCANT(sv) + SV *sv; +PROTOTYPE: $ +CODE: +{ + STRLEN len; + const char *pv; + if( SvMAGICAL(sv) ) + mg_get(sv); + /* blessed object? */ + if( SvROK(sv) && sv_isobject(sv) ) + { + ST(0) = sv; + XSRETURN(1); + } + /* valid class name? */ + if( !is_string0(sv) ) + XSRETURN_UNDEF; + pv = SvPV(sv, len); + if( len > 0 && is_class(pv, len) ) + { + ST(0) = sv; + XSRETURN(1); + } + XSRETURN_UNDEF; +} + +void +_INVOCANTCAN(sv, method) + SV *sv; + char *method; +PROTOTYPE: $$ +CODE: +{ + STRLEN len; + const char *pv; + int is_valid_invocant = 0; + STRLEN methlen; + + if( SvMAGICAL(sv) ) + mg_get(sv); + if( !method || ( ( methlen = strlen(method) ) == 0 ) ) + XSRETURN_UNDEF; + + /* blessed object? */ + if( SvROK(sv) && sv_isobject(sv) ) + is_valid_invocant = 1; + /* valid class name? */ + else if( is_string0(sv) ) + { + pv = SvPV(sv, len); + if( len > 0 && is_class(pv, len) ) + is_valid_invocant = 1; + } + + if( is_valid_invocant ) + { + I32 result = 0; + int count; + + ENTER; + SAVETMPS; + PUSHMARK(SP); + XPUSHs( sv_2mortal( newSVsv( sv ) ) ); + XPUSHs( sv_2mortal( newSVpv( method, methlen ) ) ); + PUTBACK; + + if( ( count = call_method("can", G_SCALAR) ) ) + { + I32 oldax = ax; + SPAGAIN; + SP -= count; + ax = (SP - PL_stack_base) + 1; + result = SvTRUE(ST(0)); + ax = oldax; + } + + PUTBACK; + FREETMPS; + LEAVE; + + if( result ) + { + ST(0) = sv; + XSRETURN(1); + } + } + XSRETURN_UNDEF; +} + +## Remaining standalone XSUBs + void _SCALAR0(ref) SV *ref; @@ -319,102 +667,6 @@ CODE: XSRETURN_UNDEF; } -void -_INSTANCE(ref,type) - SV *ref; - char *type; -PROTOTYPE: $$ -CODE: -{ - STRLEN len; - if( SvMAGICAL(ref) ) - mg_get(ref); - if( SvROK(ref) && type && ( ( len = strlen(type) ) > 0 ) ) - { - if( sv_isobject(ref) ) - { - I32 isa_type = 0; - int count; - - ENTER; - SAVETMPS; - PUSHMARK(SP); - XPUSHs( sv_2mortal( newSVsv( ref ) ) ); - XPUSHs( sv_2mortal( newSVpv( type, len ) ) ); - PUTBACK; - - if( ( count = call_method("isa", G_SCALAR) ) ) - { - I32 oldax = ax; - SPAGAIN; - SP -= count; - ax = (SP - PL_stack_base) + 1; - isa_type = SvTRUE(ST(0)); - ax = oldax; - } - - PUTBACK; - FREETMPS; - LEAVE; - - if( isa_type ) - { - ST(0) = ref; - XSRETURN(1); - } - } - } - XSRETURN_UNDEF; -} - -void -_INSTANCECAN(ref,method) - SV *ref; - char *method; -PROTOTYPE: $$ -CODE: -{ - STRLEN len; - if( SvMAGICAL(ref) ) - mg_get(ref); - if( SvROK(ref) && method && ( ( len = strlen(method) ) > 0 ) ) - { - if( sv_isobject(ref) ) - { - I32 has_method = 0; - int count; - - ENTER; - SAVETMPS; - PUSHMARK(SP); - XPUSHs( sv_2mortal( newSVsv( ref ) ) ); - XPUSHs( sv_2mortal( newSVpv( method, len ) ) ); - PUTBACK; - - if( ( count = call_method("can", G_SCALAR) ) ) - { - I32 oldax = ax; - SPAGAIN; - SP -= count; - ax = (SP - PL_stack_base) + 1; - has_method = SvTRUE(ST(0)); - ax = oldax; - } - - PUTBACK; - FREETMPS; - LEAVE; - - if( has_method ) - { - ST(0) = ref; - XSRETURN(1); - } - } - } - XSRETURN_UNDEF; -} - void _XScompiled () CODE: diff --git a/lib/Params/Util/ADR-005.pod b/lib/Params/Util/ADR-005.pod new file mode 100644 index 0000000..72fa50c --- /dev/null +++ b/lib/Params/Util/ADR-005.pod @@ -0,0 +1,115 @@ +=head1 ADR-005: DRY in XS via XSUB ALIAS + +=head2 Status + +Accepted + +=head2 Context + +Params::Util's XS layer historically implemented each function as a +standalone XSUB, even when functions share nearly identical logic. +For example, C<_INSTANCE> calls C<< ->isa >> while C<_INSTANCEDOES> +calls C<< ->DOES >> and C<_INSTANCECAN> calls C<< ->can >> -- the +surrounding code (magic handling, blessed check, stack manipulation, +return convention) is identical. + +Duplicating 40+ lines of XS per variant violates DRY and makes +maintenance error-prone. The XSUB C mechanism allows multiple +Perl-visible function names to share one C entry point, distinguished +only by the C variable. + +A concern raised during review of L and +L is that ALIAS forces conditionals into a shared +code path. For functions that loop over lists (e.g. C/C/ +C), a branch per iteration can hurt performance. However, +Params::Util predicates perform a single check per call -- the +dominant cost is always the Perl method dispatch (C), and +an array-index lookup for the method name is negligible in comparison. + +=head2 Decision + +Consolidate the XS implementation into ALIAS groups where the only +difference is the method name passed to C or the +validation logic selected by C: + +=over 4 + +=item Group 1: String validators + +C<_IDENTIFIER> and C<_CLASS> -- differ only in the pattern matched +against the string (identifier vs. class name with optional C<::> +separators). + +=item Group 2: Numeric validators + +C<_POSINT> and C<_NONNEGINT> -- differ only in whether zero is +accepted. + +=item Group 3: Class dispatchers + +C<_CLASSISA>, C<_CLASSDOES>, C<_CLASSCAN>, C<_SUBCLASS> -- class name +validation followed by C with method name from a static +table. C<_SUBCLASS> adds one inequality check. + +=item Group 4: Instance dispatchers + +C<_INSTANCE>, C<_INSTANCEDOES>, C<_INSTANCECAN> -- C +followed by C with method name from a static table. + +=item Group 5: Invocant dispatchers + +C<_INVOCANT>, C<_INVOCANTCAN> -- blessed-or-class check, optionally +followed by C. + +=back + +Functions deliberately excluded from XS acceleration: + +=over 4 + +=item C<_SET> / C<_SET0> + +These loop over an array calling C<_INSTANCE> per element. The +per-element C<_INSTANCE> is already XS-accelerated; the loop overhead +in Perl is minimal. Callers needing high-performance list filtering +should use L or L instead. + +=item C<_HANDLE> + +Too many special cases (globs, tied handles, multiple C checks). +Rarely performance-critical. + +=item C<_DRIVER> + +Dominated by C cost; XS around the dispatch adds no value. + +=back + +=head2 Consequences + +=over 4 + +=item * + +Each ALIAS group is maintained as a single block of C; bug fixes and +improvements apply to all aliased functions simultaneously. + +=item * + +Adding a new variant (e.g. a future C<_CLASSDOES_ALL>) requires only +a new ALIAS line and a table entry, not duplicating the entire XSUB. + +=item * + +The existing C<_INSTANCE> XSUB is refactored into the Group 4 ALIAS +block, which is a non-functional change -- existing tests cover the +behaviour. + +=item * + +No measurable performance regression from ALIAS dispatch: one static +array index per call vs. hundreds of cycles for C. + +=back + +=cut diff --git a/xt/spelling.t b/xt/spelling.t index 7a9effb..ee97dd0 100644 --- a/xt/spelling.t +++ b/xt/spelling.t @@ -18,3 +18,4 @@ PurePerl Rehsack TODO Util +validators From e05a66e70b8210f0801950ae38048ccd8e50d044 Mon Sep 17 00:00:00 2001 From: Jens Rehsack Date: Sat, 2 May 2026 15:16:47 +0200 Subject: [PATCH 6/8] Add memory leak tests for all XS-accelerated predicates Exercises both success and failure paths through call_method to verify ENTER/SAVETMPS/FREETMPS/LEAVE stack handling is leak-free. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Jens Rehsack --- t/inline/10_leaks.t | 103 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 t/inline/10_leaks.t diff --git a/t/inline/10_leaks.t b/t/inline/10_leaks.t new file mode 100644 index 0000000..137663c --- /dev/null +++ b/t/inline/10_leaks.t @@ -0,0 +1,103 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; + +BEGIN +{ + eval { require Test::LeakTrace; 1 } + or plan skip_all => "Test::LeakTrace required for leak testing"; + Test::LeakTrace->import; +} + +use Params::Util qw( + _STRING _IDENTIFIER _CLASS _NUMBER _POSINT _NONNEGINT + _SCALAR _SCALAR0 _ARRAY _ARRAY0 _ARRAYLIKE + _HASH _HASH0 _HASHLIKE _CODE _CODELIKE + _REGEX _INVOCANT _INVOCANTCAN + _CLASSISA _CLASSDOES _CLASSCAN _SUBCLASS + _INSTANCE _INSTANCEDOES _INSTANCECAN +); + +# Set up test classes +{ + + package Leak::Foo; + sub new { bless {}, shift } + sub foo { 1 } +} +{ + + package Leak::Bar; + our @ISA = ('Leak::Foo'); +} + +my $obj = Leak::Foo->new; + +# Group 1: String validators +no_leaks_ok { _STRING("hello") } '_STRING(valid) no leak'; +no_leaks_ok { _STRING(undef) } '_STRING(undef) no leak'; +no_leaks_ok { _IDENTIFIER("foo") } '_IDENTIFIER(valid) no leak'; +no_leaks_ok { _IDENTIFIER("4bad") } '_IDENTIFIER(invalid) no leak'; +no_leaks_ok { _CLASS("Foo::Bar") } '_CLASS(valid) no leak'; +no_leaks_ok { _CLASS("4bad") } '_CLASS(invalid) no leak'; + +# Group 2: Numeric validators +no_leaks_ok { _NUMBER(42) } '_NUMBER(valid) no leak'; +no_leaks_ok { _NUMBER("abc") } '_NUMBER(invalid) no leak'; +no_leaks_ok { _POSINT(1) } '_POSINT(valid) no leak'; +no_leaks_ok { _POSINT(0) } '_POSINT(zero) no leak'; +no_leaks_ok { _NONNEGINT(0) } '_NONNEGINT(zero) no leak'; +no_leaks_ok { _NONNEGINT(-1) } '_NONNEGINT(negative) no leak'; + +# Group 3: Class dispatchers (call_method path) +no_leaks_ok { _CLASSISA("Leak::Bar", "Leak::Foo") } '_CLASSISA(valid) no leak'; +no_leaks_ok { _CLASSISA("Leak::Foo", "Leak::Bar") } '_CLASSISA(invalid) no leak'; +no_leaks_ok { _CLASSISA("4bad", "Leak::Foo") } '_CLASSISA(bad class) no leak'; +no_leaks_ok { _CLASSDOES("Leak::Foo", "Leak::Foo") } '_CLASSDOES(valid) no leak'; +no_leaks_ok { _CLASSDOES("Leak::Foo", "NoSuch") } '_CLASSDOES(invalid) no leak'; +no_leaks_ok { _CLASSCAN("Leak::Foo", "foo") } '_CLASSCAN(valid) no leak'; +no_leaks_ok { _CLASSCAN("Leak::Foo", "nope") } '_CLASSCAN(invalid) no leak'; +no_leaks_ok { _SUBCLASS("Leak::Bar", "Leak::Foo") } '_SUBCLASS(valid) no leak'; +no_leaks_ok { _SUBCLASS("Leak::Foo", "Leak::Foo") } '_SUBCLASS(same) no leak'; + +# Group 4: Instance dispatchers (call_method path) +no_leaks_ok { _INSTANCE($obj, "Leak::Foo") } '_INSTANCE(valid) no leak'; +no_leaks_ok { _INSTANCE($obj, "NoSuch") } '_INSTANCE(invalid) no leak'; +no_leaks_ok { _INSTANCE("notref", "Leak::Foo") } '_INSTANCE(non-ref) no leak'; +no_leaks_ok { _INSTANCEDOES($obj, "Leak::Foo") } '_INSTANCEDOES(valid) no leak'; +no_leaks_ok { _INSTANCEDOES($obj, "NoSuch") } '_INSTANCEDOES(invalid) no leak'; +no_leaks_ok { _INSTANCECAN($obj, "foo") } '_INSTANCECAN(valid) no leak'; +no_leaks_ok { _INSTANCECAN($obj, "nope") } '_INSTANCECAN(invalid) no leak'; + +# Group 5: Invocant dispatchers +no_leaks_ok { _INVOCANT($obj) } '_INVOCANT(object) no leak'; +no_leaks_ok { _INVOCANT("Leak::Foo") } '_INVOCANT(class) no leak'; +no_leaks_ok { _INVOCANT(undef) } '_INVOCANT(undef) no leak'; +no_leaks_ok { _INVOCANTCAN($obj, "foo") } '_INVOCANTCAN(obj valid) no leak'; +no_leaks_ok { _INVOCANTCAN("Leak::Foo", "foo") } '_INVOCANTCAN(class valid) no leak'; +no_leaks_ok { _INVOCANTCAN($obj, "nope") } '_INVOCANTCAN(obj invalid) no leak'; +no_leaks_ok { _INVOCANTCAN(undef, "foo") } '_INVOCANTCAN(undef) no leak'; + +# Container types +no_leaks_ok { _SCALAR(\"hello") } '_SCALAR(valid) no leak'; +no_leaks_ok { _SCALAR0(\"") } '_SCALAR0(valid) no leak'; +no_leaks_ok { _ARRAY([1, 2, 3]) } '_ARRAY(valid) no leak'; +no_leaks_ok { _ARRAY0([]) } '_ARRAY0(valid) no leak'; +no_leaks_ok { _HASH({a => 1}) } '_HASH(valid) no leak'; +no_leaks_ok { _HASH0({}) } '_HASH0(valid) no leak'; +no_leaks_ok +{ + _CODE(sub { }) +} +'_CODE(valid) no leak'; +no_leaks_ok +{ + _CODELIKE(sub { }) +} +'_CODELIKE(valid) no leak'; +no_leaks_ok { _REGEX(qr//) } '_REGEX(valid) no leak'; + +done_testing; From 3d77e6946b6d922a7ef0b56236f9f77a2cde8442 Mon Sep 17 00:00:00 2001 From: Jens Rehsack Date: Sat, 2 May 2026 15:31:26 +0200 Subject: [PATCH 7/8] Add CLAUDE.md for AI-assisted development Captures the non-obvious conventions: container-only workflow, the PP/XS dual implementation with PP fallback, the Test::WriteVariants generation pipeline, the XS ALIAS groups, the author-test gates, and the asymmetric `Foo`/`Bar`/`Baz`/`Bad` test fixtures that discriminate `_ISA` from `_CAN`/`_DOES`. Co-Authored-By: Claude Opus 4.7 Signed-off-by: Jens Rehsack --- CLAUDE.md | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..7963462 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,95 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Development environment + +All Perl/build operations run inside the Docker dev container. Do not install Perl, cpanm, or build deps on the host. + +```sh +docker ps # confirm params-util-dev-1 is running +docker exec params-util-dev-1 sh -ec 'cd /workspace && ' +``` + +The container mounts the repo read-write at `/workspace`. The `perl-5.30`...`perl-5.42` Compose services exist for cross-version testing but mount the workspace **read-only** (and `cp -a` to `/tmp/build` first), so use the `dev` service for active work. + +## Common commands + +```sh +# Inside the container (`docker exec params-util-dev-1 sh -ec 'cd /workspace && ...'`): +perl Makefile.PL # regenerates t/pp and t/xs from t/inline (see below) +make # compiles XS +make test # full suite incl. xt/ author tests +make manifest # regenerate MANIFEST after adding files +make realclean # nukes generated tests + build artifacts + +prove -lbv t/xs/02_main.t # single test file (after `make`) +prove -lbv t/inline/10_leaks.t # leak tests need Test::LeakTrace + +perltidy -b # in-place tidy; remove the .bak afterwards +podchecker lib/Params/Util/ # POD validation +``` + +## Architecture + +### Dual PP/XS implementation + +`Params::Util` ships both a Pure-Perl backend (`lib/Params/Util/PP.pm`) and an XS backend (`Util.xs`). The loader in `lib/Params/Util.pm` falls back to PP for any function not present in the XS module: + +```perl +Params::Util->can($_) or *$_ = Params::Util::PP->can($_) for (@EXPORT_OK); +``` + +`PERL_PARAMS_UTIL_PP=1` forces PP at runtime. **Any new predicate must exist in PP**; XS is an optional accelerator. + +### XS uses ALIAS groups (ADR-005) + +Functions that share logic differing only by the called Perl method or by a small validation switch live in one C body, dispatched via `ix`: + +- Group 1 (`_IDENTIFIER`/`_CLASS`) — string validators +- Group 2 (`_POSINT`/`_NONNEGINT`) — numeric validators +- Group 3 (`_CLASSISA`/`_CLASSDOES`/`_CLASSCAN`/`_SUBCLASS`) — class + `call_method` +- Group 4 (`_INSTANCE`/`_INSTANCEDOES`/`_INSTANCECAN`) — `sv_isobject` + `call_method` +- Group 5 (`_INVOCANT`/`_INVOCANTCAN`) — invocant check + optional `call_method` + +When adding a sibling predicate to one of these groups, add an `ALIAS:` line and an entry in the static `methods[]` table — do **not** copy a whole new XSUB. + +`_HANDLE`, `_DRIVER`, `_SET`, `_SET0` are intentionally PP-only (see ADR-005). + +### Tests are generated — `t/inline/` is canonical (ADR-001) + +`t/pp/` and `t/xs/` are gitignored. They are regenerated by `Sandbox/Tumble.pm` at every `perl Makefile.PL` run and shipped in `MANIFEST` so CPAN consumers do not need `Test::WriteVariants`. + +**Edit only `t/inline/*.t`.** Variants differ solely in the `BEGIN { $ENV{PERL_PARAMS_UTIL_PP} = 0|1; }` preamble that Tumble injects. + +After adding a test file: `make manifest` to register `t/inline/`, `t/pp/`, and `t/xs/` versions. + +The test fixture classes at the tail of `t/inline/02_main.t` are deliberately asymmetric: + +- `Foo` — has `sub foo` +- `Bar` — `@ISA = 'Foo'` (real inheritance, inherits `foo`) +- `Baz` — overrides `isa` to fake `isa('Foo')` but has **no** `foo` method +- `Bad` — unrelated, only has `sub bad` + +`Baz` is the discriminator between `_ISA` (which trusts the faked `isa`) and `_CAN`/`_DOES` (which see no actual method). Tests that exercise `_CAN`/`_DOES` against `@objects` must filter — e.g. `grep { $_->can('foo') } @objects` — or they will fail on the three Baz blessings. + +### Architecture Decision Records + +`lib/Params/Util/ADR-NNN.pod` (Nygard format: Status / Context / Decision / Consequences). Existing ADRs cover Test::WriteVariants (001), multi-method `_CAN`/`_DOES` deferral (002), `Params::Util::Assert` deferral (003), `Test::Params::Util` as separate dist (004), XS ALIAS consolidation (005). When making a non-trivial design choice, write an ADR rather than burying the rationale in a commit. + +## Author-test gates + +`make test` runs `xt/*.t` which can fail on otherwise-correct code: + +- **`xt/perltidy.t`** — generated `t/pp`/`t/xs` are excluded; `Sandbox/`, inline tests, and ADR pods are checked. Run `perltidy -b ` to fix; perltidy's brace placement is the authority, do not hand-format. +- **`xt/spelling.t`** — every novel proper noun (`ADR`, `arity`, `validators`, ...) needs a stopword in `xt/spelling.t`'s `__DATA__` block. +- **`xt/manifest.t`** — run `make manifest` after adding/renaming files. +- **`xt/pod.t`/`pod-coverage.t`** — keep the SYNOPSIS predicate list in `lib/Params/Util.pm` synchronised with `@EXPORT_OK`. + +POD with em-dashes/curly quotes fails podchecker without an `=encoding` line. Stick to ASCII (`--`, `'`, `"`) in pods. + +## Conventions + +- **Commits** use `git commit --signoff`, Chris Beams style (imperative subject ≤ 50 chars, body explains *why*). Pass multi-line messages via a `.git-commit-msg` file (HEREDOC corrupts the backticks); delete the file after committing. Include the `Co-Authored-By: Claude Opus ` trailer. +- **No emoji** in code, comments, or pods unless explicitly requested. +- The leak-test suite (`t/inline/10_leaks.t`) must stay green for every XS change that touches `call_method`/stack handling. From 539b9699416afed10fbd59c4e96959afd7d2c9f5 Mon Sep 17 00:00:00 2001 From: Jens Rehsack Date: Sat, 2 May 2026 15:41:43 +0200 Subject: [PATCH 8/8] Prepare 1.105_001 developer release Skip 1.104 to leapfrog the unauthorised ETHER/Params-Util-1.103_01 upload that was numerically shadowing the 1.103_001 release on MetaCPAN (1.10301 > 1.103001 in Perl's decimal version comparison). Also extend `realclean` to mop up `inc/latest*`, `inc/inc_*`, `config.log`, and `M*.bak` so a freshly cloned dev checkout returns to a pristine state without manual cleanup. Co-Authored-By: Claude Opus 4.7 Signed-off-by: Jens Rehsack --- Changes | 26 ++++++++++++++++++++++++++ Makefile.PL | 4 ++-- lib/Params/Util.pm | 2 +- lib/Params/Util/PP.pm | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index a795803..25d431a 100755 --- a/Changes +++ b/Changes @@ -1,5 +1,31 @@ Revision history for Perl extension Params-Util +1.105_001 2026-05-02 + - Bump to 1.105_001 to get over shadowing ETHER/1.103_01 + - add _CLASSCAN, _INSTANCECAN and _INVOCANTCAN predicates to + resolve the UNIVERSAL::can debacle by calling ->can as a method + rather than as a function, respecting any overridden can() in + the invocant's class hierarchy. + - consolidate the XS layer using XSUB ALIAS groups (ADR-005): + string validators (_IDENTIFIER/_CLASS), numeric validators + (_POSINT/_NONNEGINT), class dispatchers (_CLASSISA/_CLASSDOES/ + _CLASSCAN/_SUBCLASS), instance dispatchers (_INSTANCE/ + _INSTANCEDOES/_INSTANCECAN), and invocant dispatchers + (_INVOCANT/_INVOCANTCAN). All previously PP-only predicates + except _SET/_SET0/_HANDLE/_DRIVER now have XS accelerators. + - replace hand-maintained t/pp and t/xs trees with a + Test::WriteVariants pipeline driven by Sandbox/Tumble.pm + (ADR-001). Canonical tests live in t/inline/; backend variants + are generated at `perl Makefile.PL` time and shipped in the + distribution so CPAN consumers do not need Test::WriteVariants. + - add memory-leak coverage (t/inline/10_leaks.t) exercising both + success and failure paths through call_method to verify + ENTER/SAVETMPS/FREETMPS/LEAVE handling is leak-free. + - document open design decisions as ADRs in lib/Params/Util/ + (ADR-001..005, Nygard format). + - update SUPPORT section to point to GitHub Issues as the primary + bug tracker; RT remains as historical reference. + 1.103_001 2026-05-01 - fix #3 / RT#75561: XS variants of _HASH/_HASH0/_ARRAY/_ARRAY0 now reject blessed references, matching the documented "raw and diff --git a/Makefile.PL b/Makefile.PL index 49d8dfb..60834b7 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -134,8 +134,8 @@ WriteMakefile1( depend => {'$(FIRST_MAKEFILE)' => '$(VERSION_FROM)'}, test => {TESTS => join(' ', 't/pp/*.t', ($loadable_xs ? 't/xs/*.t' : ()), 'xt/*.t')}, # Otherwise 'cxinc' isn't defined - ($] < 5.012 ? (DEFINE => '-DPERL_EXT') : (),), - (-d 'Sandbox' ? (realclean => {FILES => join(' ', 't/pp', 't/xs')}) : ()), + ($] < 5.012 ? (DEFINE => '-DPERL_EXT') : (),), + (-d 'Sandbox' ? (realclean => {FILES => join(' ', 't/pp', 't/xs', 'inc/latest* inc/inc_*', 'config.log', 'M*.bak')}) : ()), ); sub WriteMakefile1 diff --git a/lib/Params/Util.pm b/lib/Params/Util.pm index 9574921..0110cf1 100755 --- a/lib/Params/Util.pm +++ b/lib/Params/Util.pm @@ -62,7 +62,7 @@ use parent qw{Exporter XSLoader}; use Params::Util::PP qw(); -our $VERSION = '1.103_001'; +our $VERSION = '1.105_001'; local $ENV{PERL_DL_NONLAZY} = 0 if $ENV{PERL_DL_NONLAZY}; XSLoader::load("Params::Util", $VERSION) unless $ENV{PERL_PARAMS_UTIL_PP}; diff --git a/lib/Params/Util/PP.pm b/lib/Params/Util/PP.pm index e024294..13b1267 100644 --- a/lib/Params/Util/PP.pm +++ b/lib/Params/Util/PP.pm @@ -3,7 +3,7 @@ package Params::Util::PP; use strict; use warnings; -our $VERSION = '1.103_001'; +our $VERSION = '1.105_001'; =pod