Tk-Stderr

 view release on metacpan or  search on metacpan

Stderr.pm  view on Meta::CPAN

##==============================================================================
## Tk::Stderr - capture program standard error output
##==============================================================================
## $Id: Stderr.pm,v 1.2 2003/04/01 03:58:42 kevin Exp $
##==============================================================================
require 5.006;

package Tk::Stderr;
use strict;
use warnings;
use vars qw($VERSION @ISA);
($VERSION) = q$Revision: 1.2 $ =~ /Revision:\s+(\S+)/ or $VERSION = "0.0";
use base qw(Tk::Derived Tk::MainWindow);

use Tk::ROText;
use Tk::Frame;

=pod

=head1 NAME

Tk::Stderr - capture standard error output, display in separate window

=head1 SYNOPSIS

	use Tk::Stderr;

	$mw = MainWindow->new->InitStderr;
	print STDERR 'stuff';   ## goes to standard error window
	warn 'eek!';            ## likewise

=head1 DESCRIPTION

This module captures that standard error of a program and redirects it to a read
only text widget, which doesn't appear until necessary. When it does appear, the
user can close it; it'll appear again when there is more output.

=cut

##==============================================================================
## Populate
##==============================================================================
sub Populate {
	my ($mw, $args) = @_;
	my $private = $mw->privateData;
	$private->{ReferenceCount} = 0;
	$private->{Enabled} = 0;

	$mw->SUPER::Populate($args);

	$mw->withdraw;
	$mw->protocol(WM_DELETE_WINDOW => [ $mw => 'withdraw' ]);

	my $f = $mw->Frame(
		Name => 'stderr_frame',
	)->pack(-fill => 'both', -expand => 1);

	my $text = $f->Scrolled(
		'ROText',
		Name => 'stderr_text',
		-scrollbars => 'osoe',
	)->pack(-fill => 'both', -expand => 1);
	
	$mw->Advertise('text' => $text);
	
	$mw->ConfigSpecs(
		'-title' => [ qw/METHOD title Title/, 'Standard Error Output' ],
	);

	$mw->Redirect(1);
	
	return $mw;
}



( run in 1.664 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )