source: ProjectBuilder/devel/pb-modules/lib/ProjectBuilder/Display.pm@ 681

Last change on this file since 681 was 681, checked in by Bruno Cornec, 15 years ago
  • Differentiate between Scripts for VE and VM with 2 tags
  • Have a working newve, setupve and cms2ve sequence for rinse and centos5 at least (rest to be tested)
  • Planned usage of chroot (tested) and schroot (not tested)
  • Remove the external locale dependece to use the one provided by perl !
  • Fix CentOS support in Distribution module
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::gettext;
20use POSIX qw(locale_h);
21use ProjectBuilder::Base;
22
23# Inherit from the "Exporter" module which handles exporting functions.
24
25use Exporter;
26
27# Export, by default, all the functions into the namespace of
28# any code which uses this module.
29
30our $pbdisplaytype = "text";
31 # default display mode for messages
32our $pblocale = "C";
33
34our @ISA = qw(Exporter);
35our @EXPORT = qw(pb_display pb_display_init $pbdisplaytype $pblocale);
36
37=pod
38
39=head1 NAME
40
41ProjectBuilder::Display, part of the project-builder.org - module dealing with display functions suitable for perl project development
42
43=head1 DESCRIPTION
44
45This modules provides display functions suitable for perl project development
46
47=head1 SYNOPSIS
48
49 use ProjectBuilder::Display;
50
51 #
52 # Manages prints of the program
53 #
54 pb_display_init("text","fr_FR:UTF-8");
55 pb_display("Message to print\n");
56
57=head1 USAGE
58
59=over 4
60
61=item B<pb_display_init>
62
63This function initializes the environment used by the pb_display function.
64
65The first parameter is the type of display which will be used. Could be "text", "web", "newt",...
66The second parameter is the loacle to be used.
67
68The 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.
69
70=cut
71
72sub pb_display_init {
73
74$pbdisplaytype = shift || "text";
75$pblocale = shift || "C";
76
77setlocale(LC_ALL, $pblocale);
78pb_log(1,"Using $pbdisplaytype interface with $pblocale locale\n");
79
80if ($pbdisplaytype =~ /text/) {
81} elsif ($pbdisplaytype = /newt/) {
82} else {
83 die "display system $pbdisplaytype unsupported";
84}
85}
86
87=item B<pb_display>
88
89This function prints the messages passed as parameter using the configuration set up with the B<pb_display_init> function.
90
91Here is a usage example:
92
93 pb_display_init("text","fr_FR.UTF-8");
94 pb_display("Hello World\n");
95
96 will print:
97
98 Bonjour Monde
99
100=cut
101
102sub pb_display {
103
104my $msg = shift;
105
106if ($pbdisplaytype =~ /text/) {
107 print STDOUT gettext($msg);
108 }
109}
110
1111;
Note: See TracBrowser for help on using the repository browser.