#!/apps/perl5/bin/perl -w

#------------------------------------------------------------------------------
#
# Standard pragmas
#
#------------------------------------------------------------------------------

use strict;
require 5.004;

use Tk;
require Tk::Button;
require Tk::ROText;

my $mw = MainWindow->new;

my $pid;

my $attackButton = $mw->Button( 
    -text           => 'GO',
    -command        => sub {

        my $statusBox = $mw->ROText();
        $statusBox->pack;
        $statusBox->insert( 'end', "Here we go!\n" );
        $statusBox->yview( 'end' );

        pipe( READER, WRITER );
        $mw->fileevent(
            \*READER,
            'readable',
            sub {
                my $text = <READER>;
                unless ( defined $text )
                {
                    $mw->fileevent( \*READER, 'readable', undef );
                    $mw->Dialog(
                        -text           => 'Sitemap generation complete',
                        -buttons        => [ 'Exit' ],
                    )->Show();
                }
                print STDERR $text;
                $statusBox->insert( 'end', $text );
                $statusBox->yview( 'end' );
            }
        );
        print WRITER `date`;
        close( WRITER );
    }
);
$attackButton->pack;
MainLoop;
waitpid( $pid, 0 );
