<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Term::UI::History;

use strict;
use base 'Exporter';
use base 'Log::Message::Simple';

=pod

=head1 NAME

Term::UI::History - history function

=head1 SYNOPSIS

    use Term::UI::History qw[history];

    history("Some message");

    ### retrieve the history in printable form
    $hist  = Term::UI::History-&gt;history_as_string;

    ### redirect output
    local $Term::UI::History::HISTORY_FH = \*STDERR;

=head1 DESCRIPTION

This module provides the C&lt;history&gt; function for C&lt;Term::UI&gt;,
printing and saving all the C&lt;UI&gt; interaction.

Refer to the C&lt;Term::UI&gt; manpage for details on usage from
C&lt;Term::UI&gt;.

This module subclasses C&lt;Log::Message::Simple&gt;. Refer to its
manpage for additional functionality available via this package.

=head1 FUNCTIONS

=head2 history("message string" [,VERBOSE])

Records a message on the stack, and prints it to C&lt;STDOUT&gt;
(or actually C&lt;$HISTORY_FH&gt;, see the C&lt;GLOBAL VARIABLES&gt; section
below), if the C&lt;VERBOSE&gt; option is true.

The C&lt;VERBOSE&gt; option defaults to true.

=cut

BEGIN {
    use Log::Message private =&gt; 0;

    use vars      qw[ @EXPORT $HISTORY_FH ];
    @EXPORT     = qw[ history ];
    my $log     = new Log::Message;
    $HISTORY_FH = \*STDOUT;

    for my $func ( @EXPORT ) {
        no strict 'refs';

        *$func = sub {  my $msg     = shift;
                        $log-&gt;store(
                                message =&gt; $msg,
                                tag     =&gt; uc $func,
                                level   =&gt; $func,
                                extra   =&gt; [@_]
                        );
                };
    }

    sub history_as_string {
        my $class = shift;

        return join $/, map { $_-&gt;message } __PACKAGE__-&gt;stack;
    }
}


{
    package # hide this from PAUSE
      Log::Message::Handlers;

    sub history {
        my $self    = shift;
        my $verbose = shift;
           $verbose = 1 unless defined $verbose;    # default to true

        ### so you don't want us to print the msg? ###
        return if defined $verbose &amp;&amp; $verbose == 0;

        local $| = 1;
        my $old_fh = select $Term::UI::History::HISTORY_FH;

        print $self-&gt;message . "\n";
        select $old_fh;

        return;
    }
}


=head1 GLOBAL VARIABLES

=over 4

=item $HISTORY_FH

This is the filehandle all the messages sent to C&lt;history()&gt; are being
printed. This defaults to C&lt;*STDOUT&gt;.

=back

=head1 See Also

C&lt;Log::Message::Simple&gt;, C&lt;Term::UI&gt;

=head1 AUTHOR

This module by
Jos Boumans E&lt;lt&gt;kane@cpan.orgE&lt;gt&gt;.

=head1 COPYRIGHT

This module is
copyright (c) 2005 Jos Boumans E&lt;lt&gt;kane@cpan.orgE&lt;gt&gt;.
All rights reserved.

This library is free software;
you may redistribute and/or modify it under the same
terms as Perl itself.

=cut

1;

# Local variables:
# c-indentation-style: bsd
# c-basic-offset: 4
# indent-tabs-mode: nil
# End:
# vim: expandtab shiftwidth=4:
</pre></body></html>