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

NAME

Table::Simple - Easily output perl object attributes to an ASCII table

SYNOPSIS

    use Table::Simple;
    use Table::Simple::Output;
    use My::Data;
    use My::Data::Collection;

    my $collection = new My::Data::Collection;
    my $data = My::Data->new( a => 1, b => "foo", baz => 0.1 );
    $collection->add($data1);

    # Lather, rinse, repeat last two lines.

    my $table = new Table::Simple;

    foreach my $data ( $collection->get_data ) {
         $table->extract_row( $data );
    }

    my $table_output = Table::Simple::Output->new( table => $table );
    $table_output->print_table;

DESCRIPTION

Oh good grief, another table formatter? Really?

Yes, and I had a good reason - I didn't find anything that did what I wanted, which was to lazily extract attribute names and values from objects without me having to tell the formatter what they were.

So, given one or more perl objects (either a plain old blessed hashref or a Moose object) this module will pull the attribute names and values and then output them into a formmatted ASCII table. This might be useful to you if you want to take a bunch of perl objects and say, dump them into Markdown for ultra lazy wiki pages which document the states of various things. (That's what I will be using this module for myself.)

I also wanted to use Moose in a project which wouldn't take a LOT of time to complete, but wasn't just a trivial contrived exercise either.

This module is well behaved by skipping attributes which begin with an underscore and prevent you from adding columns after you've processed any rows.

ATTRIBUTES

type

This attribute stores the type of a passed object, so you can't combine objects of type "Foo" with type "Bar."

This is set automatically, so you normally shouldn't need to manipulate it.

row_count

This attribute stores the number of rows that have been processed by the table so far. It's a read-only attribute.

columns

This attribute is a collection of Table::Simple::Column objects which represent the attribute names of the perl objects being processed.

This attribute has a number of methods which permit you to manipulate how columns are interpreted and formatted for output.

name

You can optionally supply a name to the table which will be the title of a table in the output phase.

METHODS

get_columns

This method gets all columns, preserving the order in which they were added to the collection.

reorder_columns

This method changes the order of columns. NOTE: Any columns which are omitted will be deleted!

delete_column

Delete the given column from the collection.

has_columns

This method returns true if the collection has any columns. (See has_column to test whether a specific column exists.)

get_column_names

This method returns the names of all columns, preserving the order in which they were added to the collection.

has_column

This method returns true if the columns attribute contains the column name given.

get_column

This method gets the Table::Simple::Column object with the given name.

add_column

This method adds a Table::Simple::Column object to the columns collection. You normally shouldn't need to do this.

extract_columns

Given a perl object, this method extracts the non-private attribute names (that is, those which do not start with an underscore) and creates Table::Simple::Column objects for them. It preserves the order in which columns were added to the collection.

It will complain if you pass an argument that isn't blessed, or if you try to extract columns after you've added rows.

set_type

This method sets the type attribute based on the perl object's package name.

extract_row

This method extract row values from attribute names in a given perl object.

If you haven't already set the table type, or extract columns, this method will automagically do that.

It returns the current row count.

LICENSE

Copyright (C) 2010 Mark Allen

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

AUTHOR

Mark Allen <mrallen1@yahoo.com>

SEE ALSO

Moose, Table::Simple::Column, Table::Simple::Output