File Coverage

blib/lib/Acme/AllThePerlIsAStage.pm
Criterion Covered Total %
statement 35 42 83.3
branch 1 4 25.0
condition n/a
subroutine 15 15 100.0
pod n/a
total 51 61 83.6


line stmt bran cond sub pod time code
1             package Acme::AllThePerlIsAStage;
2              
3 1     1   15826 use strict;
  1         2  
  1         36  
4 1     1   3 use warnings;
  1         1  
  1         48  
5              
6             $Acme::AllThePerlIsAStage::VERSION = '0.01';
7 1     1   49 BEGIN { print __PACKAGE__ . " - And so it BEGINs … (\${^GLOBAL_PHASE} is '${^GLOBAL_PHASE}')\n" }
8              
9 1     1   327 use Acme::AllThePerlIsAStage::AndAllTheMenAndWomenJAPH;
  1         1  
  1         5  
10              
11             # TODO v0.02: functions
12             # use Acme::AllThePerlIsAStage::AndAllTheMenAndWomenJAPH 'set_at_begin_via_import';
13             #
14             # BEGIN { *set_at_begin_via_block = sub { return $$ }; };
15             #
16             # sub set_at_begin_via_sub_defined_at_global;
17             # *set_at_begin_via_sub_defined_at_global = sub { return $$ };
18             #
19             # sub set_at_begin { return $$ }
20             #
21             # *set_at_global = sub { return $$ };
22             # etc …
23              
24             my $my_set_at_global = $$;
25             my $my_set_at_run;
26             my $my_set_at_begin;
27             my $my_set_at_unitcheck;
28             my $my_set_at_check;
29             my $my_set_at_init;
30             my $my_set_at_end;
31             my $my_set_at_init_and_run;
32              
33             our $our_set_at_global = $$;
34             our $our_set_at_run;
35             our $our_set_at_begin;
36             our $our_set_at_unitcheck;
37             our $our_set_at_check;
38             our $our_set_at_init;
39             our $our_set_at_end;
40             our $our_set_at_init_and_run;
41              
42             sub import {
43 1     1   7 _say_stage("inside import()");
44             }
45              
46             # Since we are doing BEGIN blocks that call this we need it first:
47             sub _say_stage {
48 13     13   17 my ($name) = @_;
49 13         108 print caller() . " - $name (\${^GLOBAL_PHASE} is '${^GLOBAL_PHASE}')\n";
50 13 50       296 return unless $ENV{'AllThePerlIsAStage_verbose'};
51              
52             # TODO v0.02: test that this does not change results
53             # TODO v0.02: eval if callable w/and w/out parens?
54             # print "\t set_at_begin() is " . (defined &set_at_begin) ? "defined" : "not defined";
55             # print "\tset_at_global() is " . (defined &set_at_global) ? "defined" : "not defined";
56             # set_at_begin_via_import
57             # set_at_begin_via_block
58             # set_at_begin_via_sub_defined_at_global
59             # set_at_begin_via_sub_defined_at_global
60             # set_at_begin
61             # set_at_global
62              
63 0           for my $var (
64             qw(
65             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
66             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
67             )
68             ) {
69 1     1   5 no strict 'refs'; ## no critic
  1         1  
  1         158  
70 0 0         my $val = defined ${$var} ? "'${$var}'" : 'undef() (i.e. not initialized at this point)';
  0            
  0            
71 0           my $spacing = " " x ( 22 - length($var) );
72 0           print "\t\$$var$spacing is $val\n";
73             }
74              
75 0           print "\n";
76             }
77              
78             #### now the meat and potatoes ##
79              
80             _say_stage("Global Scope 1");
81              
82             if ( ${^GLOBAL_PHASE} eq 'RUN' ) {
83             $my_set_at_run = $$;
84             $our_set_at_run = $$;
85             $my_set_at_init_and_run = $$;
86             $our_set_at_init_and_run = $$;
87             _say_stage("IF-RUN 1");
88             }
89              
90             BEGIN {
91 1     1   6 $my_set_at_begin = $$;
92 1         1 $our_set_at_begin = $$;
93 1         2 _say_stage("BEGIN 1");
94             }
95              
96             UNITCHECK {
97             $my_set_at_unitcheck = $$;
98             $our_set_at_unitcheck = $$;
99             _say_stage("UNITCHECK 1");
100             }
101              
102             CHECK {
103 1     1   2 $my_set_at_check = $$;
104 1         2 $our_set_at_check = $$;
105 1         2 _say_stage("CHECK 1");
106             }
107              
108             INIT {
109 1     1   3 $my_set_at_init = $$;
110 1         1 $our_set_at_init = $$;
111 1         2 $my_set_at_init_and_run = $$;
112 1         2 $our_set_at_init_and_run = $$;
113 1         3 _say_stage("INIT 1");
114             }
115              
116             END {
117 1     1   2 $my_set_at_end = $$;
118 1         1 $our_set_at_end = $$;
119 1         2 _say_stage("END 1");
120             }
121              
122             END {
123 1     1   160 _say_stage("END 2");
124             }
125              
126             INIT {
127 1     1   2 _say_stage("INIT 2");
128             }
129              
130             CHECK {
131 1     1   2654 _say_stage("CHECK 2");
132             }
133              
134             UNITCHECK {
135             _say_stage("UNITCHECK 2");
136             }
137              
138             BEGIN {
139 1     1   3 _say_stage("BEGIN 2");
140             }
141              
142             if ( ${^GLOBAL_PHASE} eq 'RUN' ) {
143             _say_stage("IF-RUN 2");
144             }
145              
146             _say_stage("Global Scope 2");
147              
148             1;
149              
150             __END__