| 1 | package ModPerl::RegistryCookerSealed; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use version; | ||
| 5 | our $VERSION = qv(1.3.3); | ||
| 6 | |||
| 7 | use Apache2::Const -compile => qw(:common &OPT_EXECCGI); | ||
| 8 | use ModPerl::RegistryCooker; | ||
| 9 | use constant DEBUG => ModPerl::RegistryCooker::DEBUG; | ||
| 10 | use constant D_NOISE => ModPerl::RegistryCooker::D_NOISE; | ||
| 11 | use sealed (); | ||
| 12 | |||
| 13 | sub convert_script_to_compiled_handler { | ||
| 14 | my $self = shift; | ||
| 15 | |||
| 16 | my $rc = Apache2::Const::OK; | ||
| 17 | |||
| 18 | $self->debug("Adding package $self->{PACKAGE}") if DEBUG & D_NOISE; | ||
| 19 | |||
| 20 | # get the script's source | ||
| 21 | $rc = $self->read_script; | ||
| 22 | return $rc unless $rc == Apache2::Const::OK; | ||
| 23 | |||
| 24 | # convert the shebang line opts into perl code | ||
| 25 | my $shebang = $self->shebang_to_perl; | ||
| 26 | |||
| 27 | # mod_cgi compat, should compile the code while in its dir, so | ||
| 28 | # relative require/open will work. | ||
| 29 | $self->chdir_file; | ||
| 30 | |||
| 31 | # undef &{"$self->{PACKAGE}\::handler"}; unless DEBUG & D_NOISE; #avoid warnings | ||
| 32 | # $self->{PACKAGE}->can('undef_functions') && $self->{PACKAGE}->undef_functions; | ||
| 33 | |||
| 34 | my $line = $self->get_mark_line; | ||
| 35 | |||
| 36 | $self->strip_end_data_segment; | ||
| 37 | |||
| 38 | # handle the non-parsed handlers ala mod_cgi (though mod_cgi does | ||
| 39 | # some tricks removing the header_out and other filters, here we | ||
| 40 | # just call assbackwards which has the same effect). | ||
| 41 | my $base = File::Basename::basename($self->{FILENAME}); | ||
| 42 | my $nph = substr($base, 0, 4) eq 'nph-' ? '$_[0]->assbackwards(1);' : ""; | ||
| 43 | my $script_name = $self->get_script_name || $0; | ||
| 44 | |||
| 45 | # handle sealed.pm's source filter ourselves, since the string eval won't. | ||
| 46 | sealed::source_munger($self->{PACKAGE}) for ${$self->{CODE}}; | ||
| 47 | |||
| 48 | my $eval = join '', | ||
| 49 | 'package ', | ||
| 50 | $self->{PACKAGE}, ";", | ||
| 51 | "use base 'sealed';", | ||
| 52 | "sub handler {", | ||
| 53 | "local \$0 = '$script_name';", | ||
| 54 | $nph, | ||
| 55 | $shebang, | ||
| 56 | $line, | ||
| 57 | ${ $self->{CODE} }, | ||
| 58 | "}\nsealed::all();1;"; # last line comment without newline? | ||
| 59 | |||
| 60 | $rc = $self->compile(\$eval); | ||
| 61 | return $rc unless $rc == Apache2::Const::OK; | ||
| 62 | $self->debug(qq{compiled package \"$self->{PACKAGE}\"}) if DEBUG & D_NOISE; | ||
| 63 | |||
| 64 | $self->chdir_file(Apache2::ServerUtil::server_root()); | ||
| 65 | |||
| 66 | # if(my $opt = $r->dir_config("PerlRunOnce")) { | ||
| 67 | # $r->child_terminate if lc($opt) eq "on"; | ||
| 68 | # } | ||
| 69 | |||
| 70 | $self->cache_it; | ||
| 71 | |||
| 72 | return $rc; | ||
| 73 | } | ||
| 74 | |||
| 75 | undef &ModPerl::RegistryCooker::convert_script_to_compiled_handler; | ||
| 76 | |||
| 77 | *ModPerl::RegistryCooker::convert_script_to_compiled_handler = \&convert_script_to_compiled_handler; | ||
| 78 | |||
| 79 | __END__ |