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

Last change on this file since 2397 was 2032, checked in by Bruno Cornec, 8 years ago
  • Copyright update for 2016
File size: 2.4 KB
RevLine 
[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
12package ProjectBuilder::Display;
13
14use strict;
15use lib qw (lib);
16use Data::Dumper;
17use Pod::Usage;
18use English;
[681]19use POSIX qw(locale_h);
[512]20use ProjectBuilder::Base;
[1148]21use ProjectBuilder::Version;
[512]22
23# Inherit from the "Exporter" module which handles exporting functions.
24
[1156]25use vars qw($VERSION $REVISION @ISA @EXPORT);
[512]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);
[1156]37($VERSION,$REVISION) = pb_version_init();
[512]38
39=pod
40
41=head1 NAME
42
43ProjectBuilder::Display, part of the project-builder.org - module dealing with display functions suitable for perl project development
44
45=head1 DESCRIPTION
46
47This 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
65This function initializes the environment used by the pb_display function.
66
67The first parameter is the type of display which will be used. Could be "text", "web", "newt",...
68The second parameter is the loacle to be used.
69
70The 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
74sub pb_display_init {
75
76$pbdisplaytype = shift || "text";
77$pblocale = shift || "C";
78
79setlocale(LC_ALL, $pblocale);
80pb_log(1,"Using $pbdisplaytype interface with $pblocale locale\n");
81
82if ($pbdisplaytype =~ /text/) {
83} elsif ($pbdisplaytype = /newt/) {
84} else {
85 die "display system $pbdisplaytype unsupported";
86}
87}
88
89=item B<pb_display>
90
91This function prints the messages passed as parameter using the configuration set up with the B<pb_display_init> function.
92
93Here 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
104sub pb_display {
105
106my $msg = shift;
107
108if ($pbdisplaytype =~ /text/) {
109 print STDOUT gettext($msg);
110 }
111}
112
1131;
Note: See TracBrowser for help on using the repository browser.