# ========== Copyright Header Begin ==========================================
# OpenSPARC T2 Processor File: OutputDirector.pm
# Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
# 4150 Network Circle, Santa Clara, California 95054, U.S.A.
# * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# For the avoidance of doubt, and except that if any non-GPL license
# choice is available it will apply instead, Sun elects to use only
# the General Public License version 2 (GPLv2) at this time for any
# software where a choice of GPL license versions is made
# available with the language indicating that GPLv2 or any later version
# may be used, or where a choice of which version of the GPL is applied is
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# ========== Copyright Header End ============================================
##############################################################################
my $this = fields
::new
($class);
foreach my $key (keys %args) {
$this->{$key} = $args{$key};
##############################################################################
unless defined $this->{print_status
};
sub { printf STDOUT
@_; }
unless defined $this->{printf_status
};
unless defined $this->{print_error
};
sub { printf STDERR
@_; }
unless defined $this->{printf_error
};
##############################################################################
$this->{print_status
}->(@args);
##############################################################################
$this->{printf_status
}->(@args);
##############################################################################
$this->{print_error
}->(@args);
##############################################################################
$this->{printf_error
}->(@args);
##############################################################################
OutputDirector - Object interface to output streams to allow easy redirection
my $OUT = OutputDirector->new();
$OUT->print_status("Hello, world!\n");
$OUT->print_error("Things are not good.\n");
This module provides an object interface for status and error output
streams. The intent is that a module that uses an OutputDirector
can be trivially modified to redirect output.
This module provides an object interface to status and error streams.
The intent is that a module or script that uses an OutputDirector can
be easily (and dynamically) modified to redirect its output.
The OutputDirector is created by the class method new(). The
arguments to new form a hash of arguments whose legal keys are as follows:
Value is a coderef to use in the print_status method. Default method
prints arguments to STDOUT.
Value is a coderef to use in the printf_status method. Default method
prints formatted string to STDOUT.
Value is a coderef to use in the print_error method. Default method
prints arguments to STDERR.
Value is a coderef to use in the printf_error method. Default method
prints formatted string to STDERR.
The default OutputDirector is constructed as shown in the default
section. If, for instance, you wanted to redefine how messages are
printed to the error stream, use:
my $OUT = OutputDirector->new(
print_error => \&my_print_error,
printf_error => \&my_printf_error,
$OUT->print_error("This string goes to my_print_error\n");
The OutputDirector has 4 object methods:
=item print_status(@args)
Print the arguments to the status stream.
=item printf_status($format, @args)
Print formatted string to the status stream.
Print the arguments to the error stream.
=item printf_error($format, @args)
Print formatted string to the error stream.