summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embed.fnc2
-rw-r--r--perl.h18
-rw-r--r--pod/perldelta.pod5
-rw-r--r--proto.h2
4 files changed, 24 insertions, 3 deletions
diff --git a/embed.fnc b/embed.fnc
index fd87959e72..84155ff323 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -3724,4 +3724,6 @@ XEop |STRLEN*|dup_warnings |NULLOK STRLEN* warnings
Amd |void |CopFILEGV_set |NN COP * c|NN GV * gv
#endif
+Amd|char *const|phase_name|enum perl_phase
+
: ex: set ts=8 sts=4 sw=4 noet:
diff --git a/perl.h b/perl.h
index 53f00b1b7a..4b528ab21f 100644
--- a/perl.h
+++ b/perl.h
@@ -5423,6 +5423,24 @@ EXTCONST char *const PL_phase_names[] = {
EXTCONST char *const PL_phase_names[];
#endif
+/*
+=for apidoc_section $utility
+
+=for apidoc Amd|char *const|phase_name|enum perl_phase
+
+Returns the given phase's name as a NUL-terminated string.
+
+For example, to print a stack trace that includes the current
+interpreter phase you might do:
+
+ const char* phase_name = phase_name(PL_phase);
+ mess("This is weird. (Perl phase: %s)", phase_name);
+
+=cut
+*/
+
+#define phase_name(phase) (PL_phase_names[phase])
+
#ifndef PERL_CORE
/* Do not use this macro. It only exists for extensions that rely on PL_dirty
* instead of using the newer PL_phase, which provides everything PL_dirty
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index c30c628ddd..bde13eee7c 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -346,9 +346,8 @@ well.
=over 4
-=item *
-
-XXX
+=item * A new phase_name() interface provides access to the name
+for each interpreter phase (i.e., PL_phase value).
=back
diff --git a/proto.h b/proto.h
index 9cf9054b06..016e79856a 100644
--- a/proto.h
+++ b/proto.h
@@ -2808,6 +2808,8 @@ PERL_CALLCONV int perl_run(PerlInterpreter *my_perl);
assert(my_perl)
PERL_CALLCONV Signal_t Perl_perly_sighandler(int sig, Siginfo_t *info, void *uap, bool safe);
#define PERL_ARGS_ASSERT_PERLY_SIGHANDLER
+/* PERL_CALLCONV char *const phase_name(pTHX_ enum perl_phase); */
+#define PERL_ARGS_ASSERT_PHASE_NAME
PERL_CALLCONV void Perl_pmop_dump(pTHX_ PMOP* pm);
#define PERL_ARGS_ASSERT_PMOP_DUMP
PERL_CALLCONV OP* Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl, UV flags, I32 floor);