From 3087d61cc08fccf59944c298574ab44bffe31f9b Mon Sep 17 00:00:00 2001 From: espie Date: Thu, 23 Jun 2016 12:44:10 +0000 Subject: [PATCH] add fh variation of printing code. Systematically use it with STDOUT/STDERR for classical functions. --- usr.sbin/pkg_add/OpenBSD/State.pm | 47 ++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/usr.sbin/pkg_add/OpenBSD/State.pm b/usr.sbin/pkg_add/OpenBSD/State.pm index 0411d77f07a..6d93213661d 100644 --- a/usr.sbin/pkg_add/OpenBSD/State.pm +++ b/usr.sbin/pkg_add/OpenBSD/State.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: State.pm,v 1.34 2015/04/06 11:07:24 espie Exp $ +# $OpenBSD: State.pm,v 1.35 2016/06/23 12:44:10 espie Exp $ # # Copyright (c) 2007-2014 Marc Espie # @@ -257,50 +257,65 @@ sub fatal $self->_fatal($self->f(@_)); } -sub _print +sub _fhprint { my $self = shift; + my $fh = shift; $self->sync_display; - print @_; + print $fh @_; +} +sub _print +{ + my $self = shift; + $self->_fhprint(\*STDOUT, @_); } sub _errprint { my $self = shift; - $self->sync_display; - print STDERR @_; + $self->_fhprint(\*STDERR, @_); } -sub print +sub fhprint { my $self = shift; - $self->_print($self->f(@_)); + my $fh = shift; + $self->_fhprint($fh, $self->f(@_)); } -sub say +sub fhsay { my $self = shift; + my $fh = shift; if (@_ == 0) { - $self->_print("\n"); + $self->_fhprint($fh, "\n"); } else { - $self->_print($self->f(@_), "\n"); + $self->_fhprint($fh, $self->f(@_), "\n"); } } +sub print +{ + my $self = shift; + $self->fhprint(\*STDOUT, @_); +} + +sub say +{ + my $self = shift; + $self->fhsay(\*STDOUT, @_); +} + sub errprint { my $self = shift; - $self->_errprint($self->f(@_)); + $self->fhprint(\*STDERR, @_); } sub errsay { my $self = shift; - if (@_ == 0) { - $self->_errprint("\n"); - } else { - $self->_errprint($self->f(@_), "\n"); - } + $self->fhsay(\*STDERR, @_); } sub do_options -- 2.20.1