NAME
Maplat::Helpers::BuildNum - get the build number of the application
SYNOPSIS
use Maplat::Helpers::BuildNum;
my $buildnum = readBuildNum();
my $buildnum = readBuildNum("buildnum", 1); # when running compiled
my $buildnum = calcBuildNum();
DESCRIPTION
This module is used in conjunction with compiled perl scripts (e.g. when compiled with ActiveState tools or similar).
It's very usefull when upgrading a server to know the build numbers (see below) of a compiled perl program. When used in a scripted environment, the build number is generated on the fly.
calcbuildNum()
Calculates a build number, consisting of the build date and the hostname of the computer used.
readBuildNum()
Returns the build number.
The build number consists of the form
Xdate_hostname
Where date is the build date and time (or date/time of the first call to the function when running non-compiled), hostname the hostname of the computer the binary was build.
"X" is either one of R ("runtime", interpreted script), C (compiled) or "G" (compiled script but unable to read the compiled-in build number, so build-number is generated at runtime).
The function takes two optional arguments, $filename and $iscompiled:
my $buildnum = readBuildNum("buildnum", 1);
This is used when compiled with the ActiveState PDK and must be set depending on your development environment. The $filename is the name of the bound file, consisting of one line, the build number.
Adding an automatic build number to your program
To work correctly, building should be done with a perl script, something like this:
use Maplat::Helpers::BuildNum;
...
my $cmd = "perlapp " .
" --icon " . $opts{icon} .
" --norunlib " .
" --nocompress " .
" --nologo " .
" --manifest " . $opts{mf} .
" --clean " .
" --trim " . join(";", @trimmodules) . " " .
" --force " .
" --bind buildnum[data=" . calcBuildNum . "] " .
" --exe " . $opts{exe} .
" " . $opts{main};
`$cmd`;
Then, at runtime, you can get the current build number:
use Maplat::Helpers::BuildNum;
our $isCompiled = 0;
if(defined($PerlApp::VERSION)) {
$isCompiled = 1;
}
my $buildnum = readBuildNum("buildnum", $isCompiled);
AUTHOR
Rene Schickbauer, <rene.schickbauer@magnapowertrain.com>
COPYRIGHT AND LICENSE
Copyright (C) 2009 by Rene Schickbauer
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.