[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Howto import modules ...



Hello MacPerlers

Axel Rose wrote:
>My MacPerl applets can now "use" modules and run without
>further installations of files, i.e. real standalone applications.
>
>.....
>Here is a summary of the necessary steps

For further facilitation of this process I wrote a small droplet which
saves all needed modules of a script as 'TEXT' resources in a ".rsrc"-File
when dropped on it:

"ExtractModules.dp"
#=================================================
#!perl

open(inFile, @ARGV[0]) or die "No file dropped!";
while($line= <inFile>) {
	if($line=~ /^use.*;/) {
		eval($line); #read the %INC
	}
}

%LIBS= %INC;
$resFileName= @ARGV[0].".rsrc";

# 'eval' prevents the preprocessor from writing the
#libs used by this script into %INC
eval <<"EOE";
use Mac::Resources;
use Mac::Memory;
EOE

CreateResFile($resFileName);
$res= OpenResFile($resFileName);

$id= 5000;

foreach $libFileName(keys %LIBS) {
	$aText= "";

	open(libFile, $LIBS{$libFileName}) or die $^E;
	while(<libFile>){
		$aText.= $_;
	}
	$codeHand= new Handle($aText);

	#UNIX-> Mac Folder
	$libFileName=~ s/\//:/g;
	AddResource($codeHand, 'TEXT', $id, $libFileName) or die $^E;
	WriteResource($codeHand) or die $^E;
	ReleaseResource($codeHand) or die $^E;
	$codeHand-> dispose;
	$id++;
}
CloseResFile($res);

&MacPerl'Quit(3);

#========================================================

So the steps for developping a standalone application are now:

>1. Develop your Perl program as usual with MacPerl and save
>it as droplet or as plain text.

2. Drop the file on "ExtractModules.dp" which yields a file called
"yourScript.rsrc"

>3. Save your program as "Runtime Version"

4. Open the runtime version and "yourScript.rsrc" with ResEdit

5. Copy the content of "yourScript.rsrc" (all 'TEXT' resources) into the
"Runtime Version"

>7. Save, exit and ready

With a little effort one could probably make this (via AppleScript) a
one-step matter.

Michael

Michael Ziege
Sallenbachstr. 11
8055 ZŸrich
Switzerland
tel. 	++41-1-463 82 78
e-mail. ziege@ito.umnw.ethz.ch



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch