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

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