Movatterモバイル変換


[0]ホーム

URL:


variables /${^GLOBAL_PHASE}
(source,CPAN)
#${^GLOBAL_PHASE}

The current phase of the perl interpreter.

Possible values are:

#CONSTRUCT

ThePerlInterpreter* is being constructed viaperl_construct. This value is mostly there for completeness and for use via the underlying C variablePL_phase. It's not really possible for Perl code to be executed unless construction of the interpreter is finished.

#START

This is the global compile-time. That includes, basically, everyBEGIN block executed directly or indirectly from during the compile-time of the top-level program.

This phase is not called "BEGIN" to avoid confusion withBEGIN-blocks, as those are executed during compile-time of any compilation unit, not just the top-level program. A new, localised compile-time entered at run-time, for example by constructs aseval "use SomeModule" are not global interpreter phases, and therefore aren't reflected by${^GLOBAL_PHASE}.

#CHECK

Execution of anyCHECK blocks.

#INIT

Similar to "CHECK", but forINIT-blocks, notCHECK blocks.

#RUN

The main run-time, i.e. the execution ofPL_main_root.

#END

Execution of anyEND blocks.

#DESTRUCT

Global destruction.

Also note that there's no value for UNITCHECK-blocks. That's because those are run for each compilation unit individually, and therefore is not a global interpreter phase.

Not every program has to go through each of the possible phases, but transition from one phase to another can only happen in the order described in the above list.

An example of all of the phases Perl code can see:

BEGIN { print "compile-time: ${^GLOBAL_PHASE}\n" }INIT  { print "init-time: ${^GLOBAL_PHASE}\n" }CHECK { print "check-time: ${^GLOBAL_PHASE}\n" }{    package Print::Phase;    sub new {        my ($class, $time) = @_;        return bless \$time, $class;    }    sub DESTROY {        my $self = shift;        print "$$self: ${^GLOBAL_PHASE}\n";    }}print "run-time: ${^GLOBAL_PHASE}\n";my $runtime = Print::Phase->new(    "lexical variables are garbage collected before END");END   { print "end-time: ${^GLOBAL_PHASE}\n" }our $destruct = Print::Phase->new(    "package variables are garbage collected after END");

This will print out

compile-time: STARTcheck-time: CHECKinit-time: INITrun-time: RUNlexical variables are garbage collected before END: RUNend-time: ENDpackage variables are garbage collected after END: DESTRUCT

This variable was added in Perl 5.14.0.

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2025 Movatter.jp