Acme-AllThePerlIsAStage

 view release on metacpan or  search on metacpan

lib/Acme/AllThePerlIsAStage.pm  view on Meta::CPAN


use strict;
use warnings;

$Acme::AllThePerlIsAStage::VERSION = '0.01';
BEGIN { print __PACKAGE__ . " - And so it BEGINs … (\${^GLOBAL_PHASE} is '${^GLOBAL_PHASE}')\n" }

use Acme::AllThePerlIsAStage::AndAllTheMenAndWomenJAPH;

# TODO v0.02: functions
# use Acme::AllThePerlIsAStage::AndAllTheMenAndWomenJAPH 'set_at_begin_via_import';
#
# BEGIN { *set_at_begin_via_block = sub { return $$ }; };
#
# sub set_at_begin_via_sub_defined_at_global;
# *set_at_begin_via_sub_defined_at_global = sub { return $$ };
#
# sub set_at_begin { return $$ }
#
# *set_at_global = sub { return $$ };
# etc …

my $my_set_at_global = $$;
my $my_set_at_run;
my $my_set_at_begin;
my $my_set_at_unitcheck;
my $my_set_at_check;
my $my_set_at_init;
my $my_set_at_end;
my $my_set_at_init_and_run;

our $our_set_at_global = $$;
our $our_set_at_run;
our $our_set_at_begin;
our $our_set_at_unitcheck;
our $our_set_at_check;
our $our_set_at_init;
our $our_set_at_end;
our $our_set_at_init_and_run;

sub import {
    _say_stage("inside import()");
}

# Since we are doing BEGIN blocks that call this we need it first:
sub _say_stage {
    my ($name) = @_;
    print caller() . " - $name (\${^GLOBAL_PHASE} is '${^GLOBAL_PHASE}')\n";
    return unless $ENV{'AllThePerlIsAStage_verbose'};

    # TODO v0.02: test that this does not change results
    # TODO v0.02: eval if callable w/and w/out parens?
    # print "\t set_at_begin() is " . (defined &set_at_begin) ? "defined" : "not defined";
    # print "\tset_at_global() is " . (defined &set_at_global) ? "defined" : "not defined";
    # set_at_begin_via_import
    # set_at_begin_via_block
    # set_at_begin_via_sub_defined_at_global
    # set_at_begin_via_sub_defined_at_global
    # set_at_begin
    # set_at_global

    for my $var (
        qw(
        my_set_at_global  my_set_at_run  my_set_at_begin  my_set_at_unitcheck  my_set_at_check  my_set_at_init  my_set_at_end  my_set_at_init_and_run
        our_set_at_global our_set_at_run our_set_at_begin our_set_at_unitcheck our_set_at_check our_set_at_init our_set_at_end our_set_at_init_and_run
        )
      ) {
        no strict 'refs';    ## no critic
        my $val = defined ${$var} ? "'${$var}'" : 'undef() (i.e. not initialized at this point)';
        my $spacing = " " x ( 22 - length($var) );
        print "\t\$$var$spacing is $val\n";
    }

    print "\n";
}

#### now the meat and potatoes ##

_say_stage("Global Scope 1");

if ( ${^GLOBAL_PHASE} eq 'RUN' ) {
    $my_set_at_run           = $$;
    $our_set_at_run          = $$;
    $my_set_at_init_and_run  = $$;
    $our_set_at_init_and_run = $$;
    _say_stage("IF-RUN 1");
}

BEGIN {
    $my_set_at_begin  = $$;
    $our_set_at_begin = $$;
    _say_stage("BEGIN 1");
}

UNITCHECK {
    $my_set_at_unitcheck  = $$;
    $our_set_at_unitcheck = $$;
    _say_stage("UNITCHECK 1");
}

CHECK {
    $my_set_at_check  = $$;
    $our_set_at_check = $$;
    _say_stage("CHECK 1");
}

INIT {
    $my_set_at_init          = $$;
    $our_set_at_init         = $$;
    $my_set_at_init_and_run  = $$;
    $our_set_at_init_and_run = $$;
    _say_stage("INIT 1");
}

END {
    $my_set_at_end  = $$;
    $our_set_at_end = $$;
    _say_stage("END 1");
}

END {
    _say_stage("END 2");
}

INIT {
    _say_stage("INIT 2");
}

lib/Acme/AllThePerlIsAStage.pm  view on Meta::CPAN

    perlcc -e 'require Acme::AllThePerlIsAStage;' -o tmp/req
    ./tmp/req
    ./tmp/req

=head1 DESCRIPTION

Sometimes the stages involved in perl’s execution can be hard to grasp. It gets even hairier when you start compiling your code.

When trying to explain and then demonstrate what was happening I found myself writing scripts and modules to output what perl is doing where in order to find out if my understanding lined up with reality. Then to see how reality held up once compiled...

Finally, making a set up every few months got old and I thought I’d put it all on CPAN for the masses to enjoy/ignore.

=head1 TL;DR

Too Long; Didn’t Run

TODO v0.02 – fill me out (sorry, ran our of time)

=head2 stage info

TODO v0.02 – fill me out (sorry, ran our of time)

lib/Acme/AllThePerlIsAStage/AndAllTheMenAndWomenJAPH.pm  view on Meta::CPAN

package Acme::AllThePerlIsAStage::AndAllTheMenAndWomenJAPH;

use strict;
use warnings;

BEGIN { print __PACKAGE__ . " - And so it BEGINs … (\${^GLOBAL_PHASE} is '${^GLOBAL_PHASE}')\n" }
$Acme::AllThePerlIsAStage::AndAllTheMenAndWomenJAPH::VERSION = '0.01';

my $my_set_at_global = $$;
my $my_set_at_run;
my $my_set_at_begin;
my $my_set_at_unitcheck;
my $my_set_at_check;
my $my_set_at_init;
my $my_set_at_end;
my $my_set_at_init_and_run;

our $our_set_at_global = $$;
our $our_set_at_run;
our $our_set_at_begin;
our $our_set_at_unitcheck;
our $our_set_at_check;
our $our_set_at_init;
our $our_set_at_end;
our $our_set_at_init_and_run;

sub import {
    _say_stage("inside import()");
}

# Since we are doing BEGIN blocks that call this we need it first:
sub _say_stage {
    my ($name) = @_;
    print caller() . " - $name (\${^GLOBAL_PHASE} is '${^GLOBAL_PHASE}')\n";
    return unless $ENV{'AllThePerlIsAStage_verbose'};

    for my $var (
        qw(
        my_set_at_global  my_set_at_run  my_set_at_begin  my_set_at_unitcheck  my_set_at_check  my_set_at_init  my_set_at_end  my_set_at_init_and_run
        our_set_at_global our_set_at_run our_set_at_begin our_set_at_unitcheck our_set_at_check our_set_at_init our_set_at_end our_set_at_init_and_run
        )
      ) {
        no strict 'refs';    ## no critic
        my $val = defined ${$var} ? "'${$var}'" : 'undef() (i.e. not initialized at this point)';
        my $spacing = " " x ( 22 - length($var) );
        print "\t\$$var$spacing is $val\n";
    }

    print "\n";
}

#### now the meat and potatoes ##

_say_stage("Global Scope 1");

if ( ${^GLOBAL_PHASE} eq 'RUN' ) {
    $my_set_at_run           = $$;
    $our_set_at_run          = $$;
    $my_set_at_init_and_run  = $$;
    $our_set_at_init_and_run = $$;
    _say_stage("IF-RUN 1");
}

BEGIN {
    $my_set_at_begin  = $$;
    $our_set_at_begin = $$;
    _say_stage("BEGIN 1");
}

UNITCHECK {
    $my_set_at_unitcheck  = $$;
    $our_set_at_unitcheck = $$;
    _say_stage("UNITCHECK 1");
}

CHECK {
    $my_set_at_check  = $$;
    $our_set_at_check = $$;
    _say_stage("CHECK 1");
}

INIT {
    $my_set_at_init          = $$;
    $our_set_at_init         = $$;
    $my_set_at_init_and_run  = $$;
    $our_set_at_init_and_run = $$;
    _say_stage("INIT 1");
}

END {
    $my_set_at_end  = $$;
    $our_set_at_end = $$;
    _say_stage("END 1");
}

END {
    _say_stage("END 2");
}

INIT {
    _say_stage("INIT 2");
}

share/and_one_man_in_his_time_plays_many_parts.pl  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

BEGIN { print __PACKAGE__ . " - And so it BEGINs … (\${^GLOBAL_PHASE} is '${^GLOBAL_PHASE}')\n" }
use Acme::AllThePerlIsAStage;

my $my_set_at_global = $$;
my $my_set_at_run;
my $my_set_at_begin;
my $my_set_at_unitcheck;
my $my_set_at_check;
my $my_set_at_init;
my $my_set_at_end;
my $my_set_at_init_and_run;

our $our_set_at_global = $$;
our $our_set_at_run;
our $our_set_at_begin;
our $our_set_at_unitcheck;
our $our_set_at_check;
our $our_set_at_init;
our $our_set_at_end;
our $our_set_at_init_and_run;

# Since we are doing BEGIN blocks that call this we need it first:
sub say_stage {
    my ($name) = @_;
    print caller() . " - $name (\${^GLOBAL_PHASE} is '${^GLOBAL_PHASE}')\n";
    return unless $ENV{'AllThePerlIsAStage_verbose'};

    for my $var (
        qw(
        my_set_at_global  my_set_at_run  my_set_at_begin  my_set_at_unitcheck  my_set_at_check  my_set_at_init  my_set_at_end  my_set_at_init_and_run
        our_set_at_global our_set_at_run our_set_at_begin our_set_at_unitcheck our_set_at_check our_set_at_init our_set_at_end our_set_at_init_and_run
        )
      ) {
        no strict 'refs';    ## no critic
        my $val = defined ${$var} ? "'${$var}'" : 'undef() (i.e. not initialized at this point)';
        my $spacing = " " x ( 22 - length($var) );
        print "\t\$$var$spacing is $val\n";
    }

    print "\n";
}

#### now the meat and potatoes ##

say_stage("Global Scope 1");

if ( ${^GLOBAL_PHASE} eq 'RUN' ) {
    $my_set_at_run           = $$;
    $our_set_at_run          = $$;
    $my_set_at_init_and_run  = $$;
    $our_set_at_init_and_run = $$;
    say_stage("IF-RUN 1");
}

BEGIN {
    $my_set_at_begin  = $$;
    $our_set_at_begin = $$;
    say_stage("BEGIN 1");
}

UNITCHECK {
    $my_set_at_unitcheck  = $$;
    $our_set_at_unitcheck = $$;
    say_stage("UNITCHECK 1");
}

CHECK {
    $my_set_at_check  = $$;
    $our_set_at_check = $$;
    say_stage("CHECK 1");
}

INIT {
    $my_set_at_init          = $$;
    $our_set_at_init         = $$;
    $my_set_at_init_and_run  = $$;
    $our_set_at_init_and_run = $$;
    say_stage("INIT 1");
}

END {
    $my_set_at_end  = $$;
    $our_set_at_end = $$;
    say_stage("END 1");
}

END {
    say_stage("END 2");
}

INIT {
    say_stage("INIT 2");
}

share/they_have_their_exits_and_their_entrances.pl  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

BEGIN { print __PACKAGE__ . " - And so it BEGINs … (\${^GLOBAL_PHASE} is '${^GLOBAL_PHASE}')\n" }
require Acme::AllThePerlIsAStage;

my $my_set_at_global = $$;
my $my_set_at_run;
my $my_set_at_begin;
my $my_set_at_unitcheck;
my $my_set_at_check;
my $my_set_at_init;
my $my_set_at_end;
my $my_set_at_init_and_run;

our $our_set_at_global = $$;
our $our_set_at_run;
our $our_set_at_begin;
our $our_set_at_unitcheck;
our $our_set_at_check;
our $our_set_at_init;
our $our_set_at_end;
our $our_set_at_init_and_run;

# Since we are doing BEGIN blocks that call this we need it first:
sub say_stage {
    my ($name) = @_;
    print caller() . " - $name (\${^GLOBAL_PHASE} is '${^GLOBAL_PHASE}')\n";
    return unless $ENV{'AllThePerlIsAStage_verbose'};

    for my $var (
        qw(
        my_set_at_global  my_set_at_run  my_set_at_begin  my_set_at_unitcheck  my_set_at_check  my_set_at_init  my_set_at_end  my_set_at_init_and_run
        our_set_at_global our_set_at_run our_set_at_begin our_set_at_unitcheck our_set_at_check our_set_at_init our_set_at_end our_set_at_init_and_run
        )
      ) {
        no strict 'refs';    ## no critic
        my $val = defined ${$var} ? "'${$var}'" : 'undef() (i.e. not initialized at this point)';
        my $spacing = " " x ( 22 - length($var) );
        print "\t\$$var$spacing is $val\n";
    }

    print "\n";
}

#### now the meat and potatoes ##

say_stage("Global Scope 1");

if ( ${^GLOBAL_PHASE} eq 'RUN' ) {
    $my_set_at_run           = $$;
    $our_set_at_run          = $$;
    $my_set_at_init_and_run  = $$;
    $our_set_at_init_and_run = $$;
    say_stage("IF-RUN 1");
}

BEGIN {
    $my_set_at_begin  = $$;
    $our_set_at_begin = $$;
    say_stage("BEGIN 1");
}

UNITCHECK {
    $my_set_at_unitcheck  = $$;
    $our_set_at_unitcheck = $$;
    say_stage("UNITCHECK 1");
}

CHECK {
    $my_set_at_check  = $$;
    $our_set_at_check = $$;
    say_stage("CHECK 1");
}

INIT {
    $my_set_at_init          = $$;
    $our_set_at_init         = $$;
    $my_set_at_init_and_run  = $$;
    $our_set_at_init_and_run = $$;
    say_stage("INIT 1");
}

END {
    $my_set_at_end  = $$;
    $our_set_at_end = $$;
    say_stage("END 1");
}

END {
    say_stage("END 2");
}

INIT {
    say_stage("INIT 2");
}



( run in 1.581 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )