1 ################################################################################
5 ## $Date: 2010/03/07 13:15:48 +0100 $
7 ################################################################################
9 ## Version 3.x, Copyright (C) 2004-2010, Marcus Holland-Moritz.
10 ## Version 2.x, Copyright (C) 2001, Paul Marquess.
11 ## Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
13 ## This program is free software; you can redistribute it and/or
14 ## modify it under the same terms as Perl itself.
16 ################################################################################
25 * Returns a CV* as of perl-5.7.1. This return value is not supported
29 /* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */
30 #if { VERSION < 5.004_63 } && { VERSION != 5.004_05 }
31 #if { NEED newCONSTSUB }
33 /* This is just a trick to avoid a dependency of newCONSTSUB on PL_parser */
34 /* (There's no PL_parser in perl < 5.005, so this is completely safe) */
35 #define D_PPP_PL_copline PL_copline
38 newCONSTSUB(HV *stash, const char *name, SV *sv)
40 U32 oldhints = PL_hints;
41 HV *old_cop_stash = PL_curcop->cop_stash;
42 HV *old_curstash = PL_curstash;
43 line_t oldline = PL_curcop->cop_line;
44 PL_curcop->cop_line = D_PPP_PL_copline;
46 PL_hints &= ~HINT_BLOCK_SCOPE;
48 PL_curstash = PL_curcop->cop_stash = stash;
52 #if { VERSION < 5.003_22 }
54 #elif { VERSION == 5.003_22 }
56 #else /* 5.003_23 onwards */
57 start_subparse(FALSE, 0),
60 newSVOP(OP_CONST, 0, newSVpv((char *) name, 0)),
61 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
62 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
66 PL_curcop->cop_stash = old_cop_stash;
67 PL_curstash = old_curstash;
68 PL_curcop->cop_line = oldline;
75 #define NEED_newCONSTSUB
79 void call_newCONSTSUB_1(void)
81 #ifdef PERL_NO_GET_CONTEXT
84 newCONSTSUB(gv_stashpv("Devel::PPPort", FALSE), "test_value_1", newSViv(1));
87 extern void call_newCONSTSUB_2(void);
88 extern void call_newCONSTSUB_3(void);
103 &Devel::PPPort::call_newCONSTSUB_1();
104 ok(&Devel::PPPort::test_value_1(), 1);
106 &Devel::PPPort::call_newCONSTSUB_2();
107 ok(&Devel::PPPort::test_value_2(), 2);
109 &Devel::PPPort::call_newCONSTSUB_3();
110 ok(&Devel::PPPort::test_value_3(), 3);