| 1 | =head1 NAME | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | MKDoc::Core::Init - MKDoc Initialization Framework | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | =head1 SUMMARY | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | The MKDoc Initialization is done much like the way the plugins are processed, | ||||||||||||||||||||
| 9 | except that the initialization modules cannot interrupt the initialization chain | ||||||||||||||||||||
| 10 | unless they choose to die(), which triggers a 500 Internal Server Error. | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | Initialization modules which are registered in $ENV{SITE_DIR}/init are executed | ||||||||||||||||||||
| 13 | on each request within MKDoc::Init. | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | Under mod_perl, L<MKDoc::Core::Init> runs as a PerlInitHandler. | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | Under mod_cgi, L<MKDoc::Core::Init> runs before any plugin is invoked. | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | See L<MKDoc::Core::Init::Petal> for an example of initialization module. | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||
| 22 | package MKDoc::Core::Init; | ||||||||||||||||||||
| 23 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | sub handler | ||||||||||||||||||||
| 28 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
handler: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 29 | 0 | clean(); | |||||||||||||||||||
| 30 | 0 | init(); | |||||||||||||||||||
| 31 | 0 | return 1; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =head2 $class->init(); | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | Sets all the variables, database connections, etc. before the query is | ||||||||||||||||||||
| 38 | executed. | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||
| 41 | sub init | ||||||||||||||||||||
| 42 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
init: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 43 | 0 | ▶ | $::MKD_INIT && return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 0 | for my $pkg (_init_list()) | |||||||||||||||||||
| 46 | { | ||||||||||||||||||||
| 47 | 0 | main_import ($pkg); | |||||||||||||||||||
| 48 | 0 | $pkg->init(); | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | 0 | $::MKD_INIT = 1; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | sub _init_list | ||||||||||||||||||||
| 55 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_init_list: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 56 | 0 | my $class = shift; | |||||||||||||||||||
| 57 | 0 | ▶ | $::MKD_Init_List ||= do { | ||||||||||||||||||
|
Condition0%0/3
$main::MKD_Init_List ||= do {
opendir DD, conf_site_dir() . '/init';
my(@files) = sort(grep(/^\d\d\d\d\d_/, readdir DD));
closedir DD;
[map({s/^\d\d\d\d\d_//;
$_;} @files)]
}
MC/DC0%0/2
$main::MKD_Init_List ||= do {
opendir DD, conf_site_dir() . '/init';
my(@files) = sort(grep(/^\d\d\d\d\d_/, readdir DD));
closedir DD;
[map({s/^\d\d\d\d\d_//;
$_;} @files)]
}
$main::MKD_Init_List
do {
opendir DD, conf_site_dir() . '/init';
my(@files) = sort(grep(/^\d\d\d\d\d_/, readdir DD));
closedir DD;
[map({s/^\d\d\d\d\d_//;
$_;} @files)]
}
Truth table0%0/3
A ||= B
A= $main::MKD_Init_ListB= do {
opendir DD, conf_site_dir() . '/init';
my(@files) = sort(grep(/^\d\d\d\d\d_/, readdir DD));
closedir DD;
[map({s/^\d\d\d\d\d_//;
$_;} @files)]
}
| |||||||||||||||||||||
| 58 | 0 | opendir DD, conf_site_dir() . '/init'; | |||||||||||||||||||
| 59 | 0 | my @files = sort grep /^\d\d\d\d\d_/, readdir (DD); | |||||||||||||||||||
| 60 | 0 | closedir DD; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | [ map { s/^\d\d\d\d\d_//; $_ } @files ]; | |||||||||||||||||||
| 63 | }; | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 0 | return @{$::MKD_Init_List}; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =head2 $class->clean(); | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | Resets all the variables which look like $::MKD_<something> to undef. | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||
| 75 | sub clean | ||||||||||||||||||||
| 76 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
clean: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 77 | 0 | foreach my $key (keys %::) | |||||||||||||||||||
| 78 | { | ||||||||||||||||||||
| 79 | 0 | ▶ | $key =~ /^MKD_/ and do { $ {$::{$key}} = undef } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | sub main_import | ||||||||||||||||||||
| 85 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
main_import: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 86 | 0 | my $pkg = shift; | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | my $file = $pkg; | |||||||||||||||||||
| 89 | 0 | $file =~ s/::/\//g; | |||||||||||||||||||
| 90 | 0 | $file .= '.pm'; | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | ▶ | $INC{$file} && return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | require $file; | |||||||||||||||||||
| 95 | 0 | import $pkg; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | sub conf_site_dir | ||||||||||||||||||||
| 100 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
conf_site_dir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 101 | 0 | return $ENV{SITE_DIR}; | |||||||||||||||||||
| 102 | # $ENV{MOD_PERL} ? | ||||||||||||||||||||
| 103 | # Apache->server()->dir_config ('SITE_DIR') : | ||||||||||||||||||||
| 104 | # $ENV{SITE_DIR}; | ||||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 1 | 1; | |||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||