|
Posted by shanleiguang on May 8, 2008, 10:42 am
Please log in for more thread options
Hello all -
I've written a new module called Pretty::Table that I'm planning to
put on CPAN. Take a look at the documentation and tell me what you
think, thanks.
=head1 NAME
C<Pretty::Table> - to print pretty text table
=head1 Example
use Pretty::Table;
my $pt = Pretty::Table->new(
data_type => 'row', #row mode
data_format => 'ucfirst', #upper char
if_multi_lines => 1, #enable multi-lines mode
max_col_length => 10, #set max_col_length to 10
);
my $dr = [
['id','name','sex','age','email'],
['01','tommy','male',27],
['02','jarry','male',26],
['03','shanleiguang',26,'shanleiguang@gmail.com'],
];
$pt->set_data_ref($dr);
$pt->set_title('Contacts');
$pt->set_align('left');
$pt->set_data_format('ucfirst');
$pt->insert(['05','jackie','male',27,'jakie@somedoain.com']);
$pt->insert(['04','marry','female',26], 4);
print $pt->output();
$pt->set_data_type('col');
$pt->set_deco_cross('*');
$pt->set_if_has_title(0);
print $pt->output();
=head1 Example Output
+---------------------------------------------+
| Contacts |
+----+------------+--------+-----+------------+
| id | name | sex | age | email |
+----+------------+--------+-----+------------+
| 01 | tommy | male | 27 | |
+----+------------+--------+-----+------------+
| 02 | jarry | male | 26 | |
+----+------------+--------+-----+------------+
| 03 | shanleigua | male | 26 | shanleigua |
| | ng | | | ng@gmail.c |
| | | | | om |
+----+------------+--------+-----+------------+
| 04 | marry | female | 26 | |
+----+------------+--------+-----+------------+
*-------*-------*-------*------------*--------*
| id | 01 | 02 | 03 | 04 |
*-------*-------*-------*------------*--------*
| name | tommy | jarry | shanleigua | marry |
| | | | ng | |
*-------*-------*-------*------------*--------*
| sex | male | male | male | female |
*-------*-------*-------*------------*--------*
| age | 27 | 26 | 26 | 26 |
*-------*-------*-------*------------*--------*
| email | | | shanleigua | |
| | | | ng@gmail.c | |
| | | | om | |
*-------*-------*-------*------------*--------*
=head2 Methods
=over
=item C<Pretty::Table-E<gt>set_data_type(<'row'|'col']>)
my $dr = [
['id','name','sex','age'], #be a 'row' or a 'col'
[...],
];
=item C<Pretty::Table-
E<gt>set_data_format(<'normal'|'uc'|'lc'|'ucfirst'>)
normal - default, not format
uc - upper character
lc - lower character
ucfirst - upper first character
=item C<Pretty::Table-E<gt>set_data_ref(<$dr>)
$dr is a 2D ArrayRef
my $dr = [
['id','name','sex','age'], #be a 'row' or a 'col'
[...],
];
=item C<Pretty::Table-E<gt>set_if_has_title(<1|0>)
if has table header title, default is 1
=item C<Pretty::Table-E<gt>set_title(<$title>)
default is __PACKAGE__ (Pretty::Table)
=item C<Pretty::Table-E<gt>set_indent(<$indent>)
default is 2
=item C<Pretty::Table-E<gt>set_align(<'left'|'center'|'right'>)
default is 'left'
=item C<Pretty::Table-E<gt>set_margin_left(<$margin_left>)
default is 1, no need to change
=item C<Pretty::Table-E<gt>set_margin_right(<$margin_right>)
default is 1, no need to change
=item C<Pretty::Table-E<gt>set_deco_horizontal(<$deco_h>)
default is '|', no need to change
=item C<Pretty::Table-E<gt>set_deco_vertical(<$deco_v>)
default is '-', no need to change
=item C<Pretty::Table-E<gt>set_deco_cross(<$deco_c>)
default is '+', '*' is also pretty
=item C<Pretty::Table-E<gt>set_empty_fill(<$empty_fill>)
default is ' '(space), no need to change
=item C<Pretty::Table-E<gt>set_if_multi_lines(<1|0>)
default is 1, enable multi-lines mode
=item C<Pretty::Table-E<gt>set_max_col_length(<$max_col_length>)
default is 40, 'if_multi_lines' must enabled
=back
=head1 AUTHOR
=cut
|
|
Posted by Darin McBride on May 8, 2008, 11:23 am
Please log in for more thread options
shanleiguang@gmail.com wrote:
> Hello all -
> I've written a new module called Pretty::Table that I'm planning to
> put on CPAN. Take a look at the documentation and tell me what you
> think, thanks.
It looks awfully similar to Text::Table... :-) I don't personally have any
issue with multiple ways to do things, but I'd suggest at least putting in
your POD an explanation of why someone may prefer your module over
Text::Table (and why anyone may prefer Text::Table over your module).
|
| Similar Threads | Posted | | RFC: DBIx::Counter - persistent counter class | April 14, 2005, 3:15 am |
| use DBI - how to properly get the data out | October 15, 2004, 1:02 pm |
| Averaging data | September 27, 2005, 9:47 pm |
| Excel Data conversion | July 27, 2004, 2:37 pm |
| data structure from XML::LibXML | October 6, 2004, 6:22 pm |
| Image data parsing | October 27, 2004, 3:36 pm |
| AuthCookieNTLM - No Post Data | December 6, 2004, 9:25 am |
| AuthCookieNTLM - No Post Data | December 6, 2004, 10:01 am |
| Extracting value from data within an element. | November 30, 2005, 5:26 am |
| MakeMaker and data files | March 22, 2006, 8:02 am |
|