source: ProjectBuilder/devel/pb/lib/ProjectBuilder/Display.pm@ 512

Last change on this file since 512 was 512, checked in by Bruno Cornec, 16 years ago

Transport pb_display functions using gettext from Base into a separate module to allow Base to have only basic perl deps only abd be used in setupvm easily.

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