Changeset 397 in ProjectBuilder for devel/pb/lib/ProjectBuilder/Base.pm


Ignore:
Timestamp:
Apr 19, 2008, 1:03:02 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • pb_syntax is now shared
  • creation of 2 new shared functions pb_syntax_init and pb_temp_init
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/lib/ProjectBuilder/Base.pm

    r396 r397  
    1818use Data::Dumper;
    1919use Time::localtime qw(localtime);
     20use Pod::Usage;
    2021use English;
    2122
     
    2728# any code which uses this module.
    2829 
    29 our $debug = 0;
    30 our $LOG = \*STDOUT;
     30our $debug = 0;         # Global debug level
     31our $LOG = \*STDOUT;    # File descriptor of the log file
     32our $synmsg = "Error";  # Global error message
    3133
    3234our @ISA = qw(Exporter);
     
    341343=cut
    342344
    343 # get content of a file in a variable
    344345sub pb_get_content {
    345346
     
    356357}
    357358
     359=item B<pb_syntax_init>
     360
     361This function initializes the global variable used by the pb_syntax function.
     362
     363The parameter is the message string which will be printed when calling pb_syntax
     364
     365=cut
     366
     367sub pb_syntax_init {
     368
     369$synmsg = shift || "Error";
     370}
     371
     372=item B<pb_syntax>
     373
     374This function prints the syntax expected by the application, based on pod2usage, and exits.
     375The first parameter is the return value of the exit.
     376The second parameter is the verbosity as expected by pod2usage.
     377
     378Cf: man Pod::Usage
     379
     380=cut
     381
     382sub pb_syntax {
     383
     384my $exit_status = shift || -1;
     385my $verbose_level = shift || 0;
     386
     387my $filehandle = \*STDERR;
     388
     389$filehandle = \*STDOUT if ($exit_status == 0);
     390
     391pod2usage( { -message => $synmsg,
     392             -exitval => $exit_status  ,
     393             -verbose => $verbose_level,
     394             -output  => $filehandle } );
     395}
     396
     397=item B<pb_temp_init>
     398
     399This function initializes the environemnt variable PBTMP to a random value. This directory can be safely used during the whole program, it will be removed at the end automatically.
     400
     401=cut
     402
     403sub pb_temp_init {
     404
     405if (not defined $ENV{'TMPDIR'}) {
     406    $ENV{'TMPDIR'}="/tmp";
     407}
     408$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
     409}
     410
     411=back
     412
     413=head1 WEB SITES
     414
     415The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
     416
     417=head1 USER MAILING LIST
     418
     419None exists for the moment.
     420
     421=head1 AUTHORS
     422
     423The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
     424
     425=head1 COPYRIGHT
     426
     427Project-Builder.org is distributed under the GPL v2.0 license
     428described in the file C<COPYING> included with the distribution.
     429
     430=cut
     431
    3584321;
Note: See TracChangeset for help on using the changeset viewer.