[512] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
| 3 | # Display subroutines brought by the the Project-Builder project
|
---|
| 4 | # which can be easily used by whatever perl project
|
---|
| 5 | #
|
---|
[2032] | 6 | # Copyright B. Cornec 2007-2016
|
---|
[512] | 7 | # Provided under the GPL v2
|
---|
| 8 | #
|
---|
| 9 | # $Id$
|
---|
| 10 | #
|
---|
| 11 |
|
---|
| 12 | package ProjectBuilder::Display;
|
---|
| 13 |
|
---|
| 14 | use strict;
|
---|
| 15 | use lib qw (lib);
|
---|
| 16 | use Data::Dumper;
|
---|
| 17 | use Pod::Usage;
|
---|
| 18 | use English;
|
---|
[681] | 19 | use POSIX qw(locale_h);
|
---|
[512] | 20 | use ProjectBuilder::Base;
|
---|
[1148] | 21 | use ProjectBuilder::Version;
|
---|
[512] | 22 |
|
---|
| 23 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
| 24 |
|
---|
[1156] | 25 | use vars qw($VERSION $REVISION @ISA @EXPORT);
|
---|
[512] | 26 | use Exporter;
|
---|
| 27 |
|
---|
| 28 | # Export, by default, all the functions into the namespace of
|
---|
| 29 | # any code which uses this module.
|
---|
| 30 |
|
---|
| 31 | our $pbdisplaytype = "text";
|
---|
| 32 | # default display mode for messages
|
---|
| 33 | our $pblocale = "C";
|
---|
| 34 |
|
---|
| 35 | our @ISA = qw(Exporter);
|
---|
| 36 | our @EXPORT = qw(pb_display pb_display_init $pbdisplaytype $pblocale);
|
---|
[1156] | 37 | ($VERSION,$REVISION) = pb_version_init();
|
---|
[512] | 38 |
|
---|
| 39 | =pod
|
---|
| 40 |
|
---|
| 41 | =head1 NAME
|
---|
| 42 |
|
---|
| 43 | ProjectBuilder::Display, part of the project-builder.org - module dealing with display functions suitable for perl project development
|
---|
| 44 |
|
---|
| 45 | =head1 DESCRIPTION
|
---|
| 46 |
|
---|
| 47 | This modules provides display functions suitable for perl project development
|
---|
| 48 |
|
---|
| 49 | =head1 SYNOPSIS
|
---|
| 50 |
|
---|
| 51 | use ProjectBuilder::Display;
|
---|
| 52 |
|
---|
| 53 | #
|
---|
| 54 | # Manages prints of the program
|
---|
| 55 | #
|
---|
| 56 | pb_display_init("text","fr_FR:UTF-8");
|
---|
| 57 | pb_display("Message to print\n");
|
---|
| 58 |
|
---|
| 59 | =head1 USAGE
|
---|
| 60 |
|
---|
| 61 | =over 4
|
---|
| 62 |
|
---|
| 63 | =item B<pb_display_init>
|
---|
| 64 |
|
---|
| 65 | This function initializes the environment used by the pb_display function.
|
---|
| 66 |
|
---|
| 67 | The first parameter is the type of display which will be used. Could be "text", "web", "newt",...
|
---|
| 68 | The second parameter is the loacle to be used.
|
---|
| 69 |
|
---|
| 70 | The call to B<pb_display_init> is typically done after getting a parameter on the CLI indicating the locale used or the type of interface to report messages to.
|
---|
| 71 |
|
---|
| 72 | =cut
|
---|
| 73 |
|
---|
| 74 | sub pb_display_init {
|
---|
| 75 |
|
---|
| 76 | $pbdisplaytype = shift || "text";
|
---|
| 77 | $pblocale = shift || "C";
|
---|
| 78 |
|
---|
| 79 | setlocale(LC_ALL, $pblocale);
|
---|
| 80 | pb_log(1,"Using $pbdisplaytype interface with $pblocale locale\n");
|
---|
| 81 |
|
---|
| 82 | if ($pbdisplaytype =~ /text/) {
|
---|
| 83 | } elsif ($pbdisplaytype = /newt/) {
|
---|
| 84 | } else {
|
---|
| 85 | die "display system $pbdisplaytype unsupported";
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | =item B<pb_display>
|
---|
| 90 |
|
---|
| 91 | This function prints the messages passed as parameter using the configuration set up with the B<pb_display_init> function.
|
---|
| 92 |
|
---|
| 93 | Here is a usage example:
|
---|
| 94 |
|
---|
| 95 | pb_display_init("text","fr_FR.UTF-8");
|
---|
| 96 | pb_display("Hello World\n");
|
---|
| 97 |
|
---|
| 98 | will print:
|
---|
| 99 |
|
---|
| 100 | Bonjour Monde
|
---|
| 101 |
|
---|
| 102 | =cut
|
---|
| 103 |
|
---|
| 104 | sub pb_display {
|
---|
| 105 |
|
---|
| 106 | my $msg = shift;
|
---|
| 107 |
|
---|
| 108 | if ($pbdisplaytype =~ /text/) {
|
---|
| 109 | print STDOUT gettext($msg);
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | 1;
|
---|