Mark Allen


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


    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 );

    # 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 );


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.



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.


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


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.


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



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


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


Delete the given column from the collection.


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


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


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


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


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


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.


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


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.


Copyright (C) 2010 Mark Allen




Mark Allen <mrallen1@yahoo.com>


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

Hosting generously
sponsored by Bytemark