Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Variable to point to library?

by orderthruchaos (Scribe)
on Jul 12, 2004 at 17:52 UTC ( [id://373674]=note: print w/replies, xml ) Need Help??


in reply to Variable to point to library?

I actually prefer using MakeMaker (and h2xs) to perform this kind of task. MM allows you to specify perl programs to run at compile time as arguments to the WriteMakefile() routine:
WriteMakefile( NAME => 'Test::Bin', VERSION_FROM => 'lib/Test/Bin.pm', # finds $VERSION PREREQ_PM => {}, # e.g., Module::Name => 1.1 PL_FILES => { 'bin/test.PL $(INSTALLSITELIB) $(INSTALLSITEARCH)' => 'lib/Test/Bin.pm' }, );
The PL_FILES attribute allows you to specify the .PL files and which files they should modify. I add the $(INSTALLSITELIB) $(INSTALLSITEARCH) as arguments so the perl program will receive those macros from the makefile. Then, for example, I would transform a package like the following:
package Test::Bin; use 5.008002; use strict; use warnings; use '###LIBPREFIX###'; # Use some easily matchable phrases use '###ARCPREFIX###'; 1; __END__
by using this .PL file:
#!/usr/bin/perl -w -pi~ # Use command line options to read and write file(s). use strict; our ($lib, $arc); BEGIN { $lib = shift @ARGV; # Shift off the arguments so they are $arc = shift @ARGV; # not processed as files } s/\Q###LIBPREFIX###\E/$lib/; # perform substitutions s/\Q###ARCPREFIX###\E/$arc/; 1; __END__
The end result is at least similar to what you are looking for:
package Test::Bin; use 5.008002; use strict; use warnings; use '/home/orderthruchaos/local/lib/perl5/site_perl/5.8.2'; use '/home/orderthruchaos/local/lib/perl5/site_perl/5.8.2/i686-linux'; require Exporter; our $VERSION = '0.01'; 1; __END__
Hope this helps.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://373674]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-19 22:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found