Text-SimpleTable-1.2/0000755000076500000240000000000011223446123013155 5ustar sristaffText-SimpleTable-1.2/.perltidyrc0000644000076500000240000000240411223133333015333 0ustar sristaff# Perl Best Practices (plus errata) .perltidyrc file -l=98 # Max line width is 98 cols -i=4 # Indent level is 4 cols -ci=4 # Continuation indent is 4 cols #-st # Output to STDOUT -se # Errors to STDERR -vt=2 # Maximal vertical tightness -cti=0 # No extra indentation for closing brackets -pt=1 # Medium parenthesis tightness -bt=1 # Medium brace tightness -sbt=1 # Medium square bracket tightness -bbt=1 # Medium block brace tightness -nsfs # No space before semicolons -nolq # Don't outdent long quoted strings -wbb="% + - * / x != == >= <= =~ < > | & **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=" # Break before all operators # extras/overrides/deviations from PBP --maximum-line-length=78 # be less generous --warning-output # Show warnings --maximum-consecutive-blank-lines=2 # default is 1 --nohanging-side-comments # troublesome for commented out code -isbc # block comments may only be indented if they have some space characters before the # -ci=2 # Continuation indent is 2 cols # we use version control, so just rewrite the file -b # for the up-tight folk :) -pt=2 # High parenthesis tightness -bt=2 # High brace tightness -sbt=2 # High square bracket tightness Text-SimpleTable-1.2/Changes0000644000076500000240000000121611223444074014453 0ustar sristaffTis file documents the revision history for Perl extension Text::SimpleTable. 1.2 2009-07-02 00:00:00 - Fixed infinite loop bug. 1.1 2009-07-02 00:00:00 - Added hr method. (bricas) 1.0 2009-07-02 00:00:00 - Fixed pod coverage. - Cleanup. 0.05 2008-08-28 00:00:00 - Adden new contact information - No more os x garbage files (hopefully) 0.04 2008-08-28 00:00:00 - Removed Build.PL 0.03 2006-01-17 22:00:00 - Fixed bug where text items of '0' were not displayed 0.02 2005-11-07 00:00:00 - Added support for newlines 0.01 2005-10-24 00:00:00 - first release Text-SimpleTable-1.2/lib/0000755000076500000240000000000011223446123013723 5ustar sristaffText-SimpleTable-1.2/lib/Text/0000755000076500000240000000000011223446123014647 5ustar sristaffText-SimpleTable-1.2/lib/Text/SimpleTable.pm0000644000076500000240000002056211223443573017421 0ustar sristaff# Copyright (C) 2005-2009, Sebastian Riedel. package Text::SimpleTable; use strict; our $VERSION = '1.2'; # Top our $TOP_LEFT = '.-'; our $TOP_BORDER = '-'; our $TOP_SEPARATOR = '-+-'; our $TOP_RIGHT = '-.'; # Middle our $MIDDLE_LEFT = '+-'; our $MIDDLE_BORDER = '-'; our $MIDDLE_SEPARATOR = '-+-'; our $MIDDLE_RIGHT = '-+'; # Left our $LEFT_BORDER = '| '; our $SEPARATOR = ' | '; our $RIGHT_BORDER = ' |'; # Bottom our $BOTTOM_LEFT = "'-"; our $BOTTOM_SEPARATOR = "-+-"; our $BOTTOM_BORDER = '-'; our $BOTTOM_RIGHT = "-'"; # Wrapper our $WRAP = '-'; sub new { my ($class, @args) = @_; # Instantiate $class = ref $class || $class; my $self = bless {}, $class; # Columns and titles my $cache = []; my $max = 0; for my $arg (@args) { my $width; my $name; if (ref $arg) { $width = $arg->[0]; $name = $arg->[1]; } else { $width = $arg } # Fix size $width = 2 if $width < 2; # Wrap my $title = $name ? $self->_wrap($name, $width) : []; # Column my $col = [$width, [], $title]; $max = @{$col->[2]} if $max < @{$col->[2]}; push @$cache, $col; } # Padding for my $col (@$cache) { push @{$col->[2]}, '' while @{$col->[2]} < $max; } $self->{columns} = $cache; return $self; } # The implementation is not very elegant, but gets the job done very well sub draw { my $self = shift; # Shortcut return unless $self->{columns}; my $rows = @{$self->{columns}->[0]->[1]} - 1; my $columns = @{$self->{columns}} - 1; my $output = ''; # Top border for my $j (0 .. $columns) { my $column = $self->{columns}->[$j]; my $width = $column->[0]; my $text = $TOP_BORDER x $width; if (($j == 0) && ($columns == 0)) { $text = "$TOP_LEFT$text$TOP_RIGHT"; } elsif ($j == 0) { $text = "$TOP_LEFT$text$TOP_SEPARATOR" } elsif ($j == $columns) { $text = "$text$TOP_RIGHT" } else { $text = "$text$TOP_SEPARATOR" } $output .= $text; } $output .= "\n"; my $title = 0; for my $column (@{$self->{columns}}) { $title = @{$column->[2]} if $title < @{$column->[2]}; } if ($title) { # Titles for my $i (0 .. $title - 1) { for my $j (0 .. $columns) { my $column = $self->{columns}->[$j]; my $width = $column->[0]; my $text = $column->[2]->[$i] || ''; $text = sprintf "%-${width}s", $text; if (($j == 0) && ($columns == 0)) { $text = "$LEFT_BORDER$text$RIGHT_BORDER"; } elsif ($j == 0) { $text = "$LEFT_BORDER$text$SEPARATOR" } elsif ($j == $columns) { $text = "$text$RIGHT_BORDER" } else { $text = "$text$SEPARATOR" } $output .= $text; } $output .= "\n"; } # Title separator $output .= $self->_draw_hr; } # Rows for my $i (0 .. $rows) { # Check for hr if (!grep { defined $self->{columns}->[$_]->[1]->[$i] } 0 .. $columns) { $output .= $self->_draw_hr; next; } for my $j (0 .. $columns) { my $column = $self->{columns}->[$j]; my $width = $column->[0]; my $text = (defined $column->[1]->[$i]) ? $column->[1]->[$i] : ''; $text = sprintf "%-${width}s", $text; if (($j == 0) && ($columns == 0)) { $text = "$LEFT_BORDER$text$RIGHT_BORDER"; } elsif ($j == 0) { $text = "$LEFT_BORDER$text$SEPARATOR" } elsif ($j == $columns) { $text = "$text$RIGHT_BORDER" } else { $text = "$text$SEPARATOR" } $output .= $text; } $output .= "\n"; } # Bottom border for my $j (0 .. $columns) { my $column = $self->{columns}->[$j]; my $width = $column->[0]; my $text = $BOTTOM_BORDER x $width; if (($j == 0) && ($columns == 0)) { $text = "$BOTTOM_LEFT$text$BOTTOM_RIGHT"; } elsif ($j == 0) { $text = "$BOTTOM_LEFT$text$BOTTOM_SEPARATOR" } elsif ($j == $columns) { $text = "$text$BOTTOM_RIGHT" } else { $text = "$text$BOTTOM_SEPARATOR" } $output .= $text; } $output .= "\n"; return $output; } sub hr { my $self = shift; for (0 .. @{$self->{columns}} - 1) { push @{$self->{columns}->[$_]->[1]}, undef; } return $self; } sub row { my ($self, @texts) = @_; my $size = @{$self->{columns}} - 1; # Shortcut return $self if $size < 0; for (1 .. $size) { last if $size <= @texts; push @texts, ''; } my $cache = []; my $max = 0; for my $i (0 .. $size) { my $text = shift @texts; my $column = $self->{columns}->[$i]; my $width = $column->[0]; my $pieces = $self->_wrap($text, $width); push @{$cache->[$i]}, @$pieces; $max = @$pieces if @$pieces > $max; } for my $col (@{$cache}) { push @{$col}, '' while @{$col} < $max } for my $i (0 .. $size) { my $column = $self->{columns}->[$i]; my $store = $column->[1]; push @{$store}, @{$cache->[$i]}; } return $self; } sub _draw_hr { my $self = shift; my $columns = @{$self->{columns}} - 1; my $output = ''; for my $j (0 .. $columns) { my $column = $self->{columns}->[$j]; my $width = $column->[0]; my $text = $MIDDLE_BORDER x $width; if (($j == 0) && ($columns == 0)) { $text = "$MIDDLE_LEFT$text$MIDDLE_RIGHT"; } elsif ($j == 0) { $text = "$MIDDLE_LEFT$text$MIDDLE_SEPARATOR" } elsif ($j == $columns) { $text = "$text$MIDDLE_RIGHT" } else { $text = "$text$MIDDLE_SEPARATOR" } $output .= $text; } $output .= "\n"; return $output; } # Wrap text sub _wrap { my ($self, $text, $width) = @_; my @cache; my @parts = split "\n", $text; for my $part (@parts) { while (length $part > $width) { my $subtext; $subtext = substr $part, 0, $width - length($WRAP), ''; push @cache, "$subtext$WRAP"; } push @cache, $part if defined $part; } return \@cache; } 1; __END__ =head1 NAME Text::SimpleTable - Simple Eyecandy ASCII Tables =head1 SYNOPSIS use Text::SimpleTable; my $t1 = Text::SimpleTable->new(5, 10); $t1->row('foobarbaz', 'yadayadayada'); print $t1->draw; .-------+------------. | foob- | yadayaday- | | arbaz | ada | '-------+------------' my $t2 = Text::SimpleTable->new([5, 'Foo'], [10, 'Bar']); $t2->row('foobarbaz', 'yadayadayada'); $t2->row('barbarbarbarbar', 'yada'); print $t2->draw; .-------+------------. | Foo | Bar | +-------+------------+ | foob- | yadayaday- | | arbaz | ada | | barb- | yada | | arba- | | | rbar- | | | bar | | '-------+------------' my $t3 = Text::SimpleTable->new([5, 'Foo'], [10, 'Bar']); $t3->row('foobarbaz', 'yadayadayada'); $t3->hr; $t3->row('barbarbarbarbar', 'yada'); print $t3->draw; .-------+------------. | Foo | Bar | +-------+------------+ | foob- | yadayaday- | | arbaz | ada | +-------+------------+ | barb- | yada | | arba- | | | rbar- | | | bar | | '-------+------------' =head1 DESCRIPTION Simple eyecandy ASCII tables. =head1 METHODS L implements the following methods. =head2 C my $t = Text::SimpleTable->new(5, 10); my $t = Text::SimpleTable->new([5, 'Col1', 10, 'Col2']); =head2 C my $ascii = $t->draw; =head2 C
$t = $t->hr; =head2 C $t = $t->row('col1 data', 'col2 data'); =head1 AUTHOR Sebastian Riedel, C. =head1 CREDITS In alphabetical order: Brian Cassidy =head1 COPYRIGHT Copyright (C) 2005-2009, Sebastian Riedel. This program is free software, you can redistribute it and/or modify it under the same terms as Perl 5.10. =cut Text-SimpleTable-1.2/Makefile.PL0000644000076500000240000000056711223133031015126 0ustar sristaff#!perl # Copyright (C) 2005-2009, Sebastian Riedel. use strict; use warnings; use ExtUtils::MakeMaker; # Son, when you participate in sporting events, # it's not whether you win or lose, it's how drunk you get. WriteMakefile( NAME => 'Text::SimpleTable', VERSION_FROM => 'lib/Text/SimpleTable.pm', AUTHOR => 'Sebastian Riedel ' ); Text-SimpleTable-1.2/MANIFEST0000644000076500000240000000034611223446123014311 0ustar sristaff.perltidyrc Changes lib/Text/SimpleTable.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP t/01use.t t/02pod.t t/03podcoverage.t t/04tables.t META.yml Module meta-data (added by MakeMaker) Text-SimpleTable-1.2/MANIFEST.SKIP0000644000076500000240000000005511223136412015050 0ustar sristaff^blib ^pm_to_blib .*\.old$ ^Makefile$ ^\.git Text-SimpleTable-1.2/META.yml0000644000076500000240000000057111223446123014431 0ustar sristaff--- #YAML:1.0 name: Text-SimpleTable version: 1.2 abstract: ~ license: ~ author: - Sebastian Riedel generated_by: ExtUtils::MakeMaker version 6.42 distribution_type: module requires: meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 Text-SimpleTable-1.2/t/0000755000076500000240000000000011223446123013420 5ustar sristaffText-SimpleTable-1.2/t/01use.t0000644000076500000240000000021211223133234014531 0ustar sristaff#!perl # Copyright (C) 2005-2009, Sebastian Riedel. use strict; use warnings; use Test::More tests => 1; use_ok('Text::SimpleTable'); Text-SimpleTable-1.2/t/02pod.t0000644000076500000240000000053711223133162014532 0ustar sristaff#!perl # Copyright (C) 2005-2009, Sebastian Riedel. use strict; use warnings; use Test::More; eval "use Test::Pod 1.14"; plan skip_all => 'Test::Pod 1.14 required' if $@; plan skip_all => 'set TEST_POD to enable this test (developer only!)' unless $ENV{TEST_POD}; # Marge, it takes two to lie. One to lie and one to listen. all_pod_files_ok(); Text-SimpleTable-1.2/t/03podcoverage.t0000644000076500000240000000063711223133203016244 0ustar sristaff#!perl # Copyright (C) 2005-2009, Sebastian Riedel. use strict; use warnings; use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@; plan skip_all => 'set TEST_POD to enable this test (developer only!)' unless $ENV{TEST_POD}; # Marge, I'm going to miss you so much. And it's not just the sex. # It's also the food preparation. all_pod_coverage_ok(); Text-SimpleTable-1.2/t/04tables.t0000644000076500000240000000327211223444043015226 0ustar sristaff#!perl # Copyright (C) 2005-2009, Sebastian Riedel. use strict; use warnings; use Test::More tests => 6; use_ok('Text::SimpleTable'); # No titles and multiple rows my $t1 = Text::SimpleTable->new(5, 10); $t1->row('Catalyst', 'rockz!'); $t1->row('DBIx::Class', 'suckz!'); $t1->row('Template::Toolkit', 'rockz!'); is($t1->draw, <new([5, 'ROCKZ!'], [10, 'Suckz!'], [7, 'rockz!']); $t2->row('Catalyst', 'DBIx::Class', 'Template::Toolkit', 'HTML::Mason'); is($t2->draw, <new(5); $t3->row('Everything works!'); is($t3->draw, <new(5); $t4->row('Everything works!'); $t4->hr; $t4->row('Everything works!'); is($t4->draw, <new(1); $t5->row('Works!'); $t5->hr; $t5->row('Works!'); is($t5->draw, <