Skip to content

Instantly share code, notes, and snippets.

@xtetsuji
Created February 24, 2013 05:34
Show Gist options
  • Select an option

  • Save xtetsuji/5022763 to your computer and use it in GitHub Desktop.

Select an option

Save xtetsuji/5022763 to your computer and use it in GitHub Desktop.
Tiny proof of concept script why mod_perl Registry/PerlRun script can not use __DATA__ (and __END__) token.
#!/usr/bin/perl
# Tiny proof of concept script
# why mod_perl Registry/PerlRun script can not use __DATA__ (and __END__) token.
use strict;
use warnings;
my $code_simple = <<END_CODE;
print "Hello! world1.\n";
END_CODE
my $code_simple_pkgname = 'My::Dummy::CodeSimple';
my $code_include_data_token = <<END_CODE;
print "Hello! world2.\n";
__DATA__
foofoofoo
barbarbar
END_CODE
my $code_include_data_token_pkgname = 'My::Dummy::IncludeDataToken';
{
local $@;
eval(qq{
package $code_simple_pkgname;
sub handler {
$code_simple
}
1;
});
print "=== code_simple compile " . ($@ ? "FAILED: \n" . $@ : 'SUCCESS') . ".\n";
}
{
local $@;
eval(qq{
package $code_include_data_token_pkgname;
sub handler {
$code_include_data_token
}
1;
});
print "=== code_include_data_token compile " . ($@ ? "FAILED: \n" . $@ : 'SUCCESS') . ".\n";
}
print "\n";
{
local $@;
print "*** Call $code_simple_pkgname\::handler() ***\n";
eval "$code_simple_pkgname\::handler();";
if ($@) {
print "$code_simple_pkgname\::handler() called error\n";
}
}
print "\n";
{
local $@;
print "*** Call $code_include_data_token_pkgname\::handler() ***\n";
eval "$code_include_data_token_pkgname\::handler();";
if ($@) {
print "$code_include_data_token_pkgname\::handler() called error: $@\n";
}
}
__END__
OUTPUT IS HERE:
=== code_simple compile SUCCESS.
=== code_include_data_token compile FAILED:
Missing right curly or square bracket at (eval 2) line 6, at end of line
(Might be a runaway multi-line "" string starting on line 4)
syntax error at (eval 2) line 6, at EOF
.
*** Call My::Dummy::CodeSimple::handler() ***
Hello! world1.
*** Call My::Dummy::IncludeDataToken::handler() ***
My::Dummy::IncludeDataToken::handler() called error: Undefined subroutine &My::Dummy::IncludeDataToken::handler called at (eval 4) line 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment