# @(#)46 1.2 src/43haes/lib/perl/MsgCatalog.pm, hacmp.libcluster, 61haes_r714 11/28/11 15:09:48 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r714 src/43haes/lib/perl/MsgCatalog.pm 1.2 # # Licensed Materials - Property of IBM # # Restricted Materials of IBM # # COPYRIGHT International Business Machines Corp. 2004,2011 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG package MsgCatalog; =head1 NAME MsgCatalog - Perl extension for handling access to AIX message catalogs =head1 SYNOPSIS use MsgCatalog; my $cluster_cat = MsgCatalog::new("cluster.cat"); $cluster_cat->dspmsg(1, 5, "PowerHA SystemMirror"); my $utilities_cat = MsgCatalog::new("utilities.cat"); $utilities_cat->dspmsg(1, 27, "Could not detect node (%1\$s).\n", "$nodename"); =head1 DESCRIPTION This package provides a Perl-like interface for accessing AIX message catalogs. A MsgCatalog object is a 'handle' to a real message catalog so that arbitrary messages can be output. The operations currently supported are: new -- creates an interface to a message catalog dspmsg -- retrieve a message from the catalog =head1 METHODS =cut use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); require Exporter; use Carp; @ISA = qw(Exporter); @EXPORT = qw( ); $VERSION = '0.01'; =head2 new() Description: This is the constructor for MsgCatalog objects. It takes the name of an message catalog and 'ties' the catalog with a new Perl object that's created by this method. Arguments: $: the name of a message catalog @: optional parameters Returns: A new object used to represent the message catalog. Example: my $catalog = MsgCatalog::new( "cluster.cat", LANG=>"en_US" ); =cut sub new() { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; my $catalog = shift || croak "argument 'catalog' is mandatory"; my %args = @_; $self->{CATALOG} = $catalog; $self->{LANG} = $args{LANG}; return bless $self, $class; } =head2 dspmsg() Description: dspmsg() retrieves a message from the object's message catalog using the AIX dspmsg command call. Arguments: $: a reference to the catalog object $: the message catalog set number $: the message number $: the default message @: one or more replacement parameters for the message (optional) Returns: none (the message it output to stdout) Examples: $clstr_cat->dspmsg(1, 5, "PowerHA SystemMirror"); $util_cat->dspmsg(1, 27, "Could not detect node (%1\$s).\n", "$nodename"); =cut sub dspmsg() { my $self = shift; my $set = shift || croak "argument 'set' is mandatory"; my $msg = shift || croak "argument 'msg' is mandatory"; my $default = shift || croak "argument 'default' is mandatory"; my @paramlist = @_; my $cmdstr = (($self->{LANG}) ? ("LANG=" . $self->{LANG}) : "" ); my $params = join ( " ", map { "\"$_\"" } @paramlist); my $cat = $self->{CATALOG}; $cmdstr = "$cmdstr dspmsg -s $set $cat $msg \"$default\" $params"; system("$cmdstr"); } =head2 getmsg() Description: getmsg() retrieves a message from the object's message catalog using the AIX dspmsg command call. Arguments: $: a reference to the catalog object $: the message catalog set number $: the message number $: the default message @: one or more replacement parameters for the message (optional) Returns: The resulting string. Examples: $msg = $clstr_cat->getmsg(1, 5, "PowerHA SystemMirror"); $msg = $util_cat->getmsg(1, 27, "Could not detect node (%1\$s).\n", "$nodename"); =cut sub getmsg() { my $self = shift; my $set = shift || croak "argument 'set' is mandatory"; my $msg = shift || croak "argument 'msg' is mandatory"; my $default = shift || croak "argument 'default' is mandatory"; my @params = @_; my $cmdstr = (($self->{LANG}) ? ("LANG=" . $self->{LANG}) : "" ); $cmdstr = "$cmdstr dspmsg -s $set " . $self->{CATALOG} . " $msg \"$default\" " . join ( " ", map { "\"$_\"" } @params ); open( MSG, "$cmdstr | " ) or return undef; my @retval = ; close MSG; return "@retval"; } # this is a module, so it must end with a plain 1. 1; __END__