develooper Front page | perl.module-authors | Postings from April 2008

Application Building

Thread Next
From:
Austin Schutz
Date:
April 25, 2008 12:43
Subject:
Application Building
	Ok, so here's what must be a question with a really simple answer:
how do I write a perl app?

	For example: I want to display a jpeg.


MyApp/script/display.pl:

#!/path/to/perl
use Myapp::Display;
Myapp::Diplay->new()->display('example.jpg');
__END__

MyApp/lib/Myapp/Display.pm
  ...

MyApp/share/example.jpg
  ...

MyApp/Build.PL:
my $build = new Module::Build (
   script_files => [ 'script/display.pl' ],
   jpeg_files => { 'share/example.jpg' => 'share/example.jpg' }
);
$build->add_build_element('jpeg');
$build->create_build_script;

   

	Ok, so now I do:

/path/to/perl ./Build.PL install_base=$HOME/MyApp
./Build install

...
...


	If I put #!perl at the top of display.pl it will have a path to perl
(though not the one I specified), but it won't have "use lib $HOME/MyApp/lib"
at the top of the script, so it can't run.
	Furthermore, there's no way for the script to know what was used
for install_base, so there's no way for the script to know where the data
file is located.

	This must be something people do, right? Currently I hard code paths
and force the installation to be where I want it, but this seems really
sub-optimal, doesn't work for having test environments, etc.
	I've been considering parsing $0 at the top of the script, is that
what other people do?

	Austin

Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About