7 require Config; import Config;
8 keys %Config; # Silence warning
9 if ($Config{extensions} !~ /\bList\/Util\b/) {
10 print "1..0 # Skip: List::Util was not built\n";
17 use Test::More (grep { /set_prototype/ } @Scalar::Util::EXPORT_FAIL)
18 ? (skip_all => 'set_prototype requires XS version')
21 Scalar::Util->import('set_prototype');
24 is( prototype('f'), undef, 'no prototype');
26 $r = set_prototype(\&f,'$');
27 is( prototype('f'), '$', 'set prototype');
28 is( $r, \&f, 'return value');
30 set_prototype(\&f,undef);
31 is( prototype('f'), undef, 'remove prototype');
33 set_prototype(\&f,'');
34 is( prototype('f'), '', 'empty prototype');
37 is( prototype('g'), '@', '@ prototype');
39 set_prototype(\&g,undef);
40 is( prototype('g'), undef, 'remove prototype');
43 is( prototype('stub'), undef, 'non existing sub');
45 set_prototype(\&stub,'$$$');
46 is( prototype('stub'), '$$$', 'change non existing sub');
49 is( prototype('f_decl'), '$$$$', 'forward declaration');
51 set_prototype(\&f_decl,'\%');
52 is( prototype('f_decl'), '\%', 'change forward declaration');
54 eval { &set_prototype( 'f', '' ); };
56 ok($@ =~ /^set_prototype: not a reference/, 'not a reference');
58 eval { &set_prototype( \'f', '' ); };
59 ok($@ =~ /^set_prototype: not a subroutine reference/, 'not a sub reference');