The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Term::Report - Easy way to create dynamic 'reports' from within scripts.

SYNOPSIS

    use Term::Report;

    my $items = 10000;
    my $report = Term::Report->new(
            startRow => 4,
            numFormat => 1,
            statusBar => [label => 'Report Status: ', subText => 'Locating widgets', subTextAlign => 'center'],
    );

    my $status = $report->{statusBar};  ## Alias this cause I'm lazy
    $status->setItems($items);
    $status->start;

    $report->printLine("Total widgets I found so far... ");
    my $discard = 0;

    for (1..$items){
        $report->finePrint($report->currentRow(), $report->lineLength('curText')+1, $_);

        if (!($_%(rand(1000)+1000))){
            $discard++;
            $status->subText("Discarding bad widget");
            for my $t (1..1000000){ ## Fake like we are doing something
                $status->subText($status->subText() . "..") if !($t%900000);
            }
        }
        else{
            $status->subText("Locating widgets");
        }

        $status->update;
    }

    $report->printLine("\n  $discard widgets were discarded\n");

    $status->reset;
    $status->setItems($items-$discard);
    $status->subText('Processing widgets');
    $status->start;

    $report->printLine("\nInventorying widgets... ");

    for (1..($items-$discard)){
        $report->finePrint($report->currentRow(), $report->lineLength('curText')+1, $_);
        $status->update;
    }

    $report->printBarReport(
        "\n\n\n\n    Summary for widgets: \n\n",
        {
            "       Total:        " => $items,
            "       Good Widgets: " => $items-$discard,
            "       Bad Widgets:  " => $discard,
        }
    );

DESCRIPTION

Term::Report can be used to generate nicely formatted dynamic output. It can also use Term::StatusBar to show progress and Number::Format so numbers show up more readable. All output is sent to STDOUT.

METHODS

new(parameters)

        startRow  - This indicates which row to start at. Default is 1.
        startCol  - This indicates which column to start at. Default is 1.
        numFormat - This indicates if you want to use Number::Format. Default is undef.
        statusBar - This indicats if you want to use Term::StatusBar. Default is undef.

numFormat and statusBar can be passed in 2 different ways.

The first way is as a simple flag: numFormat => 1

Or as an array reference with parameters for a Number::Format object: numFormat => [-MON_DECIMAL_POINT => ',', -INT_CURR_SYMBOL => '']

statusBar behaves the same way except takes parameters appropriate for Term::StatusBar.

finePrint($row, $col, @text)

This gives more control over where to place text.

printLine(@text)

This places text after the last known text has been placed. It tries very hard to "Do The Right Thing", but I am certain there are more 'bugs' in it.

lineLength('m')

Returns length($obj->{m})

AUTHOR

Shay Harding <sharding@ccbill.com>

COPYRIGHT

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

SEE ALSO

Term::StatusBar, Number::Format, Term::ANSIScreen