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 |
|
---|
12 | package ProjectBuilder::Display;
|
---|
13 |
|
---|
14 | use strict;
|
---|
15 | use lib qw (lib);
|
---|
16 | use Data::Dumper;
|
---|
17 | use Pod::Usage;
|
---|
18 | use English;
|
---|
19 | use POSIX qw(locale_h);
|
---|
20 | use ProjectBuilder::Base;
|
---|
21 |
|
---|
22 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
23 |
|
---|
24 | use Exporter;
|
---|
25 |
|
---|
26 | # Export, by default, all the functions into the namespace of
|
---|
27 | # any code which uses this module.
|
---|
28 |
|
---|
29 | our $pbdisplaytype = "text";
|
---|
30 | # default display mode for messages
|
---|
31 | our $pblocale = "C";
|
---|
32 |
|
---|
33 | our @ISA = qw(Exporter);
|
---|
34 | our @EXPORT = qw(pb_display pb_display_init $pbdisplaytype $pblocale);
|
---|
35 |
|
---|
36 | =pod
|
---|
37 |
|
---|
38 | =head1 NAME
|
---|
39 |
|
---|
40 | ProjectBuilder::Display, part of the project-builder.org - module dealing with display functions suitable for perl project development
|
---|
41 |
|
---|
42 | =head1 DESCRIPTION
|
---|
43 |
|
---|
44 | This 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 |
|
---|
62 | This function initializes the environment used by the pb_display function.
|
---|
63 |
|
---|
64 | The first parameter is the type of display which will be used. Could be "text", "web", "newt",...
|
---|
65 | The second parameter is the loacle to be used.
|
---|
66 |
|
---|
67 | The 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 |
|
---|
71 | sub pb_display_init {
|
---|
72 |
|
---|
73 | $pbdisplaytype = shift || "text";
|
---|
74 | $pblocale = shift || "C";
|
---|
75 |
|
---|
76 | setlocale(LC_ALL, $pblocale);
|
---|
77 | pb_log(1,"Using $pbdisplaytype interface with $pblocale locale\n");
|
---|
78 |
|
---|
79 | if ($pbdisplaytype =~ /text/) {
|
---|
80 | } elsif ($pbdisplaytype = /newt/) {
|
---|
81 | } else {
|
---|
82 | die "display system $pbdisplaytype unsupported";
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | =item B<pb_display>
|
---|
87 |
|
---|
88 | This function prints the messages passed as parameter using the configuration set up with the B<pb_display_init> function.
|
---|
89 |
|
---|
90 | Here 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 |
|
---|
101 | sub pb_display {
|
---|
102 |
|
---|
103 | my $msg = shift;
|
---|
104 |
|
---|
105 | if ($pbdisplaytype =~ /text/) {
|
---|
106 | print STDOUT gettext($msg);
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | 1;
|
---|