The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Puppet::Log - Log facility with an optional Tk display

SYNOPSIS

 use Puppet::Log ;

 my $log = new Puppet::Log('title' =>'log test') ;
 $log -> log("Some text") ;

 # $wmgr can be a toplevel Tk main window or a Tk::Multi::Manager
 $log ->display($wmgr, 1) ; 

DESCRIPTION

This class implements a log facility with an optional Tk display.

I.e once the class is created, you can log messages in it, but the Tk display does no need to be created at the same time. You may invoke later only when you need it.

When the Tk display is not invoked, the log can be either printed on STDOUT or warned on STDERR (or stay hidden). But in any case, the log message will be stored in the class so that all log messages can be retrieved later by the user or by the Tk display when invoked.

Once the Tk display is invoked, it will be updated by new logs.

Constructor

new([title => 'name'], ['how' => 'print' | 'warn' ])

Creates the log object.

The constructor parameters are :

  • title: Title of the Tk log display (optional)

  • name: Name of the log used when printing on STDOUT or STDERR (optional)

  • how: Specifies what to do when a log is sent to the object (either print on STDOUT, warn on STDERR). By default the logs will not be printed or warned. (optional)

  • help The argument may be a string or a sub reference. When the help menu is invoked, either the help string will be displayed in a Tk::Dialog box or the sub will be run. In this case it is the user's responsability to provide a readable help from the sub. (See "help" in Tk::Multi::Manager for further details)

Methods

log(text,...)

Will log the passed text

Optional parameters are:

  • how: will supersede the 'how' parameter passed to the constructor. If 'how' is set to undef, the log will not be printed or warned.

clear()

Clear all stored logs.

getAll()

Return an array made of all stored logs.

display(toplevel_ref | multi_manager_reference, [hidden] )

Will create the log display. The log display is in fact a Tk::Multi::Text window which can managed by a Tk::Multi::Manager object.

toplevel_ref

The parent window object.

multi_manager_reference

The Tk::Multi::Manager reference

hidden

When hidden is 1, the log will not displayed on start-up. (default is to show the log window)

If you don't provide a multi_manager reference, Puppet::Log will consider that you want the Log to appear in its own TopLevel window.

In this case Puppet::Log will create a new Toplevel window and create a Tk::Multi::Manager in it. In this case, it will feature a File->close menu entry to destroy the Log window.

Once the Log window is destroyed, the display method can then be called later to recreate it.

In any case display() returns the manager reference. You may reuse this reference to add another Log display in the Toplevel window that Log just created. So that both log windows are displayed in the same Tk window. (See the t/top_log.t example to see what I mean)

show()

Will raise the log window. Note that this function is ignored if its called before display().

About Puppet::* classes

Puppet classes are a set of utility classes which can be used by any object. If you use directly the Puppet::*Body class, you get the plain functionnality. And if you use the Puppet::* class, you can get the same functionnality and a Tk Gui to manage it.

The basic idea is when you construct a Puppet::* object, you have all the functionnality of the object without the GUI. Then, when the need arises, you may (or the class may decide to) open the GUI of the object. On the other hand, if the need does not arise, you may create a lot of objects without cluttering your display.

AUTHOR

Dominique Dumont, Dominique_Dumont@grenoble.hp.com

Copyright (c) 1998-1999,2006 Dominique Dumont. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1), Puppet::LogBody(3), Tk(3), Tk::Multi::Text(3), Tk::Multi::Manager(3)