source: devel/lib/ProjectBuilder/Display.pm @ 1498

Last change on this file since 1498 was 1498, checked in by bruno, 7 years ago

Adding a prefix entry in Makefile.PL (Eric Anderson)

File size: 2.4 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;
21use ProjectBuilder::Version;
22
23# Inherit from the "Exporter" module which handles exporting functions.
24 
25use vars qw($VERSION $REVISION @ISA @EXPORT);
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($VERSION,$REVISION) = pb_version_init();
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.