Data::Tabulate::Plugin::ASCIITable - generate ASCII tables with C<Data::Tabulate>


Data-Tabulate-Plugin-ASCIITable documentation Contained in the Data-Tabulate-Plugin-ASCIITable distribution.

Index


Code Index:

NAME

Top

Data::Tabulate::Plugin::ASCIITable - generate ASCII tables with Data::Tabulate

VERSION

Top

Version 0.01

SYNOPSIS

Top



    use Data::Tabulate;

    my @array = (1..10);
    my $foo = Data::Tabulate->new();
    print $foo->render('ASCIITable',{data => [@array]});

EXPORT

Top

A list of functions that can be exported. You can delete this section if you don't export anything, such as for a purely object-oriented module.

METHODS

Top

new

create a new object of Data::Tabulate::Plugin::ASCIITable

output

returns a string that contains the ASCII table

AUTHOR

Top

Renee Baecker, <module at renee-baecker.de>

BUGS

Top

Please report any bugs or feature requests to bug-data-tabulate-plugin-asciitable at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data::Tabulate::Plugin::ASCIITable. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Data::Tabulate::Plugin::ASCIITable

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Data::Tabulate::Plugin::ASCIITable

* CPAN Ratings

http://cpanratings.perl.org/d/Data::Tabulate::Plugin::ASCIITable

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data::Tabulate::Plugin::ASCIITable

* Search CPAN

http://search.cpan.org/dist/Data::Tabulate::Plugin::ASCIITable

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


Data-Tabulate-Plugin-ASCIITable documentation Contained in the Data-Tabulate-Plugin-ASCIITable distribution.
package Data::Tabulate::Plugin::ASCIITable;

use warnings;
use strict;
use Text::ASCIITable;

our $VERSION = '0.01';

sub new{
    return bless {}, shift;
}

sub output{
    my ($self,@data) = @_;
    my $obj = Text::ASCIITable->new();
    my @headings = $self->_header_length(@data);
    $obj->setCols(@headings);
    for(@data){
        my @row = map{defined($_) ? $_ : ' '}@$_;
        $obj->addRow(@row);
    }
    
    my $table = ''.$obj;
    my $sep   = $/;
    $table = join($sep , (split(/$sep/,$table,4))[0,3]);
    return $table;
}

sub _header_length{
    my ($self,@data) = @_;
    
    my $cols = scalar(@{$data[0]});
    my %hash;
    @hash{(1..$cols)} = map{length $data[0]->[$_]}(0..$cols-1);
    for my $row(@data){
        for my $index(0..$cols-1){
            next unless defined $row->[$index];
            if(length $row->[$index] > $hash{$index+1}){
                $hash{$index+1} = length $row->[$index];
            }
        }
    }
    my @return = map{' ' x $hash{$_}}(1..$cols);
    return @return;
}

1; # End of Data::Tabulate::Plugin::ASCIITable