Codebase list libparams-validate-perl / 92ba775
Imported Upstream version 1.06 gregor herrmann 12 years ago
13 changed file(s) with 81 addition(s) and 135 deletion(s). Raw diff Collapse all Expand all
1010 "File::Spec" => 0,
1111 "File::Temp" => 0,
1212 "Module::Build" => "0.3601",
13 "Module::Implementation" => "0.04",
1314 "Test::Fatal" => 0,
1415 "Test::More" => "0.88",
1516 "Tie::Array" => 0,
2627 "Dave Rolsky, <autarch\@urth.org> and Ilya Martynov <ilya\@martynov.org>"
2728 ],
2829 "dist_name" => "Params-Validate",
29 "dist_version" => "1.03",
30 "dist_version" => "1.06",
3031 "license" => "artistic_2",
3132 "module_name" => "Params::Validate",
3233 "recommends" => {},
5455 if ( grep { $_ eq '--pp' } @ARGV ) {
5556 $skip_xs = 1;
5657 }
57 elsif ( ! can_xs() ) {
58 elsif ( ! $build->have_c_compiler() ) {
5859 $skip_xs = 1;
5960 }
6061
6263 $build->build_elements(
6364 [ grep { $_ ne 'xs' } @{ $build->build_elements() } ] );
6465 }
65
66 sub can_xs {
67 # Do we have the configure_requires checker?
68 local $@;
69 eval "require ExtUtils::CBuilder;";
70 if ($@) {
71
72 # They don't obey configure_requires, so it is
73 # someone old and delicate. Try to avoid hurting
74 # them by falling back to an older simpler test.
75 return can_cc();
76 }
77
78 # Do a simple compile that consumes the headers we need
79 my @libs = ();
80 my $object = undef;
81 my $builder = ExtUtils::CBuilder->new( quiet => 1 );
82 unless ( $builder->have_compiler ) {
83
84 # Lack of a compiler at all
85 return 0;
86 }
87 eval {
88 $object = $builder->compile(
89 source => 'sanexs.c',
90 );
91 @libs = $builder->link(
92 objects => $object,
93 module_name => 'sanexs',
94 );
95 };
96 my $broken = !!$@;
97 foreach ( $object, @libs ) {
98 next unless defined $_;
99 1 while unlink $_;
100 }
101
102 if ($broken) {
103 ### NOTE: Don't do this in a production release.
104 # Compiler is officially screwed, you don't deserve
105 # to do any of our downstream depedencies as you'll
106 # probably end up choking on them as well.
107 # Trigger an NA for their own protection.
108 print "Unresolvable broken external dependency.\n";
109 print "This package requires a C compiler with full perl headers.\n";
110 print "Trivial test code using them failed to compile.\n";
111 print STDERR "NA: Unable to build distribution on this platform.\n";
112 exit(0);
113 }
114
115 return 1;
116 }
117
118 sub can_cc {
119 my @chunks = split( / /, $Config::Config{cc} ) or return;
120
121 # $Config{cc} may contain args; try to find out the program part
122 while (@chunks) {
123 return can_run("@chunks") || ( pop(@chunks), next );
124 }
125
126 return;
127 }
128
129 sub can_run {
130 my ($cmd) = @_;
131
132 my $_cmd = $cmd;
133 if ( -x $_cmd or $_cmd = MM->maybe_command($_cmd) ) {
134 return $_cmd;
135 }
136
137 foreach my $dir ( ( split /$Config::Config{path_sep}/, $ENV{PATH} ), '.' )
138 {
139 next if $dir eq '';
140 my $abs = File::Spec->catfile( $dir, $cmd );
141 return $abs if ( -x $abs or $abs = MM->maybe_command($abs) );
142 }
143
144 return;
145 }
14666 $build->create_build_script;
0 1.06 2012-02-10
1
2 - Shut up warnings when XS is loaded on older 5.8.x Perl versions. Reported by
3 Aaron James Trevena. RT #74742.
4
5
6 1.05 2012-02-08
7
8 - The XS code had a code path where it could pass the contents of a Perl
9 variable as the first argument to the XS croak() subroutine. This subroutine
10 is like printf(), and should receive a format string as its first
11 argument. According to RT #74777, this can lead to segfaults on some systems.
12
13 This could in theory be a security bug, but it's very unlikely that
14 untrusted user input could end up being passed to this croak(). It is called
15 when a spec specifies a "depend" value on another parameter. The value of
16 the "depend" parameter was passed in the first argument to croak().
17
18 Reported by Andreas Voegele.
19
20
21 1.04 2012-02-08
22
23 - Use the latest Module::XSOrPP dzil plugin to generate a saner Build.PL. No
24 need update if you're using an earlier version.
25
26
027 1.03 2012-02-06
128
229 - This release uses Module::Implementation to handle loading the XS or pure
1818 lib/Params/Validate/XS.xs
1919 lib/Params/ValidatePP.pm
2020 lib/Params/ValidateXS.pm
21 sanexs.c
2221 t/01-validate.t
2322 t/02-noop.t
2423 t/03-attribute.t
9796 t/release-pp-32-regex-as-value.t
9897 t/release-pp-is-loaded.t
9998 t/release-xs-is-loaded.t
99 t/release-xs-segfault.t
4343 "Devel::Peek" : 0,
4444 "File::Spec" : 0,
4545 "File::Temp" : 0,
46 "Module::Implementation" : "0.04",
4647 "Test::Fatal" : 0,
4748 "Test::More" : "0.88",
4849 "Tie::Array" : 0,
6465 "web" : "http://git.urth.org/Params-Validate.git"
6566 }
6667 },
67 "version" : "1.03"
68 "version" : "1.06"
6869 }
6970
66 File::Spec: 0
77 File::Temp: 0
88 Module::Build: 0.3601
9 Module::Implementation: 0.04
910 Test::Fatal: 0
1011 Test::More: 0.88
1112 Tie::Array: 0
3637 resources:
3738 bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Params-Validate
3839 repository: git://git.urth.org/Params-Validate.git
39 version: 1.03
40 version: 1.06
00
11
22 This archive contains the distribution Params-Validate,
3 version 1.03:
3 version 1.06:
44
55 Validate method/function parameters
66
22 license = Artistic_2_0
33 copyright_holder = Dave Rolsky and Ilya Martynov
44
5 version = 1.03
5 version = 1.06
66
77 [NextRelease]
88 format = %-7v %{yyyy-MM-dd}d
0 /* Copyright (c) 2000-2011 Dave Rolsky */
0 /* Copyright (c) 2000-2012 Dave Rolsky and Ilya Martynov */
11
22 #include "EXTERN.h"
33 #include "perl.h"
7373 break; \
7474 } \
7575 } STMT_END
76
77 /* module initialization */
78 static void
79 bootinit() {
80 HV* stash;
81
82 /* define constants */
83 stash = gv_stashpv("Params::Validate", 1);
84 newCONSTSUB(stash, "SCALAR", newSViv(SCALAR));
85 newCONSTSUB(stash, "ARRAYREF", newSViv(ARRAYREF));
86 newCONSTSUB(stash, "HASHREF", newSViv(HASHREF));
87 newCONSTSUB(stash, "CODEREF", newSViv(CODEREF));
88 newCONSTSUB(stash, "GLOB", newSViv(GLOB));
89 newCONSTSUB(stash, "GLOBREF", newSViv(GLOBREF));
90 newCONSTSUB(stash, "SCALARREF", newSViv(SCALARREF));
91 newCONSTSUB(stash, "UNKNOWN", newSViv(UNKNOWN));
92 newCONSTSUB(stash, "UNDEF", newSViv(UNDEF));
93 newCONSTSUB(stash, "OBJECT", newSViv(OBJECT));
94 newCONSTSUB(stash, "HANDLE", newSViv(HANDLE));
95 newCONSTSUB(stash, "BOOLEAN", newSViv(BOOLEAN));
96 }
9776
9877
9978 INLINE static bool
439418 return 1;
440419 }
441420
442 #define VALID_KEY_COUNT 9
443 static char* valid_keys[VALID_KEY_COUNT] = {
444 "callbacks", "can", "default", "depends", "isa", "optional", "regex", "type", "untaint"
445 };
446
447421 /* validates specific parameter using supplied parameter specification */
448422 static IV
449423 validate_one_param(SV* value, SV* params, HV* spec, SV* id, HV* options, IV* untaint) {
1001975 sv_catpv(buffer, "' does not exist in spec: ");
1002976 sv_catsv(buffer, depend_name);
1003977
1004 croak(SvPV_nolen(buffer));
978 croak("%s", SvPV_nolen(buffer));
1005979 }
1006980 /* if we got here, the spec was correct. we just
1007981 * need to issue a regular validation failure
15131487
15141488 MODULE = Params::Validate::XS PACKAGE = Params::Validate::XS
15151489
1516 BOOT:
1517 bootinit();
1518
15191490 void
15201491 validate(p, specs)
15211492 SV* p
00 package Params::Validate;
11 {
2 $Params::Validate::VERSION = '1.03';
2 $Params::Validate::VERSION = '1.06';
33 }
44
55 use 5.008001;
7979
8080 =head1 VERSION
8181
82 version 1.03
82 version 1.06
8383
8484 =head1 SYNOPSIS
8585
+0
-12
sanexs.c less more
0 #include "EXTERN.h"
1 #include "perl.h"
2 #include "XSUB.h"
3
4 int main(int argc, char **argv) {
5 return 0;
6 }
7
8 int boot_sanexs() {
9 return 1;
10 }
11
1515 $ENV{PV_WARN_FAILED_IMPLEMENTATION} = 1;
1616 }
1717
18 use Module::Implementation 0.04 ();
1819 use Params::Validate;
1920
2021 is(
21 Params::Validate::_implementation(), 'PP',
22 Module::Implementation::implementation_for('Params::Validate'),
23 'PP',
2224 'PP implementation is loaded when env var is set'
2325 );
2426
1212
1313 BEGIN { $ENV{PV_WARN_FAILED_IMPLEMENTATION} = 1 }
1414
15 use Module::Implementation 0.04 ();
1516 use Params::Validate;
1617
1718 is(
18 Params::Validate::_implementation(), 'XS',
19 Module::Implementation::implementation_for('Params::Validate'),
20 'XS',
1921 'XS implementation is loaded by default'
2022 );
2123
0
1 BEGIN {
2 unless ($ENV{RELEASE_TESTING}) {
3 require Test::More;
4 Test::More::plan(skip_all => 'these tests are for release candidate testing');
5 }
6 }
7
8 use strict;
9 use warnings;
10
11 use Test::More;
12
13 BEGIN {
14 $ENV{PARAMS_VALIDATE_IMPLEMENTATION} = 'XS';
15 $ENV{PV_WARN_FAILED_IMPLEMENTATION} = 1;
16 }
17
18 use Params::Validate qw( validate SCALAR );
19
20 eval { foo( { a => 1 } ) };
21
22 ok(1, 'did not segfault');
23
24 done_testing();
25
26 sub foo {
27 validate(
28 @_,
29 {
30 a => { type => SCALAR, depends => ['%s%s%s'] },
31 }
32 );
33 }