Acme-Win32-PEPM
view release on metacpan or search on metacpan
lib/Win32/PEPM.pm view on Meta::CPAN
This module is a packager that allows you to build a .pm that is simultaneously
a .pm that can be C<do>, C<require>d, or C<use>d, and the same .pm is a 100%
real DLL containing XS code. The generated file meets the file format standards
of both a .pm and a PE (Portable Executable) DLL and uses no temp files.
The author of this module sees this module as a joke since with this
"packager", the .pm text is stored uncompressed in the .dll, and there is no
sane reason to keep .pm text memory mapped into a process since after
parsing/compiling .pm, the .pm text is never referenced again, yet with this
"packager", if the XS DLL is loaded, so is the .pm text, into the process.
The resulting .pm that is built can not be edited even though it mostly looks
like plain text. If it is edited, the DLL will be corrupt. The resulting .pm,
although superficially looking like pure perl can not be moved between perl
installations/versions except for maint versions, since the XS DLL inside the
.pm, like all XS DLLs/SOs is bound to a particular perl installation and version
number.
=head1 FUNCTIONS
=head2 load
Win32::PEPM::load(__FILE__, $VERSION);
lib/Win32/PEPM/Build.pm view on Meta::CPAN
my $crlf = index($text, "\r") != -1;
my $nl = $crlf ? "\r\n" : "\n";
#note, this will break if __END__ is in a string
my $pos = index($text, '__END__');
#stop following error caused by no __END__
#Unrecognized character \x12; marked by <-- HERE after <-- HERE near column 1 at
#C:/perl/***.pm line 154.
$text .= $nl.'__END__'.$nl if $pos == -1;
$text = 'MZ' #DOS MAGIC
.';' #make the magic not be a syntax error
.$nl.'#!!!!WARNING do not edit this file!!!!'.$nl
.' ' #space pad to the heredoc
x (0x40 #DOS headers full length
-length('MZ')
-length(';')
-length($nl.'#!!!!WARNING do not edit this file!!!!'.$nl)
-length('<<e_lfanew;'.$nl) #heredoc to escape
-4 #size of DWORD e_lfanew
)
.'<<e_lfanew;'.$nl #heredoc
."\x01\x01\x01\x01" #e_lfanew member, a U32/DWORD offset, will be overwritten by linker
#end of 0x40 area, things below are now supposed executable space of the dos prog
.$nl.'e_lfanew'.$nl.$nl #end quoting of the binary offset
.$text
#note the "Rich Signature" appears here before PE header
#after going through VC linker, the Rich Signature IS NOT uninitialized
( run in 1.047 second using v1.01-cache-2.11-cpan-de7293f3b23 )