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

Re: [MacPerl] Howto import modules ...



As the logical next step toward building a standalone app I modified the
droplet slightly so it allows to drop a runtime version and saves the
imported modules as 'TEXT' resources directly into the file:

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

use Mac::Resources;
use Mac::Memory;

#ARGV now in scalar context (thanks to Bart and Chris)
$res= OpenResFile($ARGV[0]) || die $^E;

#first 'TEXT' resource is source code:
$sourceCodeRes= Get1IndResource('TEXT', 1);
$sourceCodeText= $sourceCodeRes-> get();

#clear the hash:
undef(%INC);

#suppress warnings about redefining subroutines
#by 'eval(use...)':
local $^W = 0;

#angle operator doesn't work here(?):
@sourceCodeText= split /\n/, $sourceCodeText;
for (@sourceCodeText){
	if(/^use.*;/){
		eval($_); #read the %INC
	}
}

$id= 5000;
foreach $libFileName(keys %INC) {
	$aText= "";

	open(libFile, $INC{$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++;
	print "Copied module ".$libFileName." into resource fork.\n";
}
CloseResFile($res);
sleep(3);
&MacPerl'Quit(3);

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

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