Here is another my 2 cents (in attachment).
This patch allow to use more than 80 chars in tables output, like list
of loaded components or actions - width will be auto-selected based on
terminal width or on enviroment variable. Useful and convenient for
debugging, imho. Feel free to correct either POD and code.
Some explanation about selected values for constants:
1) use constant WIDTH_MAX => 110;
I tried to use wider values, and as for me it looks worse - toooooo
wide :) May be, 120... Anyway, this value should not be more that 130,
imho. Probably, you'll want to try change it by yourself and find more
appropriate value.
2) use constant WIDTH_MIN => 70;
For some reason with too narrow screens I got 99% CPU load O_o
Seems like minor bug with Text::SimpleTable, when calculated width (my
$column_width) is 0 or negative. Imho, in such case Text::SimpleTable
should assume width with value 1, but it don't. I don't looked into it
really, this is only assumption. And having WIDTH_MIN is simplest way
to avoid such cases, I think.
Will be glad to hear some feedback :)
--
Sincerely yours,
Oleg Kostyuk (CUB-UANIC)
diff -ur 1/usr/local/share/perl/5.10.0/Catalyst/Dispatcher.pm 2/usr/local/share/perl/5.10.0/Catalyst/Dispatcher.pm
--- 1/usr/local/share/perl/5.10.0/Catalyst/Dispatcher.pm 2009-01-05 23:41:35.000000000 +0200
+++ 2/usr/local/share/perl/5.10.0/Catalyst/Dispatcher.pm 2009-01-06 08:30:16.000000000 +0200
@@ -8,6 +8,7 @@
use Catalyst::ActionContainer;
use Catalyst::DispatchType::Default;
use Catalyst::DispatchType::Index;
+use Catalyst::Utils ();
use Text::SimpleTable;
use Tree::Simple;
use Tree::Simple::Visitor::FindByPath;
@@ -474,10 +475,11 @@
return unless $c->debug;
+ my $column_width = Catalyst::Utils::term_width() - 20 - 36 - 12;
my $privates = Text::SimpleTable->new(
[ 20, 'Private' ],
[ 36, 'Class' ],
- [ 12, 'Method' ]
+ [ $column_width, 'Method' ]
);
my $has_private = 0;
diff -ur 1/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Chained.pm 2/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Chained.pm
--- 1/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Chained.pm 2009-01-06 07:40:14.000000000 +0200
+++ 2/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Chained.pm 2009-01-06 08:30:25.000000000 +0200
@@ -4,6 +4,7 @@
use base qw/Catalyst::DispatchType/;
use Text::SimpleTable;
use Catalyst::ActionChain;
+use Catalyst::Utils ();
use URI;
# please don't perltidy this. hairy code within.
@@ -43,8 +44,10 @@
return unless $self->{endpoints};
+ my $column_width = Catalyst::Utils::term_width() - 35 - 9;
my $paths = Text::SimpleTable->new(
- [ 35, 'Path Spec' ], [ 36, 'Private' ]
+ [ 35, 'Path Spec' ],
+ [ $column_width, 'Private' ]
);
ENDPOINT: foreach my $endpoint (
diff -ur 1/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Path.pm 2/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Path.pm
--- 1/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Path.pm 2009-01-06 07:39:05.000000000 +0200
+++ 2/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Path.pm 2009-01-06 08:30:45.000000000 +0200
@@ -3,6 +3,7 @@
use strict;
use base qw/Catalyst::DispatchType/;
use Text::SimpleTable;
+use Catalyst::Utils ();
use URI;
=head1 NAME
@@ -25,7 +26,11 @@
sub list {
my ( $self, $c ) = @_;
- my $paths = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] );
+ my $column_width = Catalyst::Utils::term_width() - 35 - 9;
+ my $paths = Text::SimpleTable->new(
+ [ 35, 'Path' ],
+ [ $column_width, 'Private' ]
+ );
foreach my $path ( sort keys %{ $self->{paths} } ) {
my $display_path = $path eq '/' ? $path : "/$path";
foreach my $action ( @{ $self->{paths}->{$path} } ) {
diff -ur 1/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Regex.pm 2/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Regex.pm
--- 1/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Regex.pm 2009-01-06 07:41:13.000000000 +0200
+++ 2/usr/local/share/perl/5.10.0/Catalyst/DispatchType/Regex.pm 2009-01-06 08:30:55.000000000 +0200
@@ -3,6 +3,7 @@
use strict;
use base qw/Catalyst::DispatchType::Path/;
use Text::SimpleTable;
+use Catalyst::Utils ();
use Text::Balanced ();
=head1 NAME
@@ -25,7 +26,11 @@
sub list {
my ( $self, $c ) = @_;
- my $re = Text::SimpleTable->new( [ 35, 'Regex' ], [ 36, 'Private' ] );
+ my $column_width = Catalyst::Utils::term_width() - 35 - 9;
+ my $re = Text::SimpleTable->new(
+ [ 35, 'Regex' ],
+ [ $column_width, 'Private' ]
+ );
for my $regex ( @{ $self->{compiled} } ) {
my $action = $regex->{action};
$re->row( $regex->{path}, "/$action" );
diff -ur 1/usr/local/share/perl/5.10.0/Catalyst/Stats.pm 2/usr/local/share/perl/5.10.0/Catalyst/Stats.pm
--- 1/usr/local/share/perl/5.10.0/Catalyst/Stats.pm 2009-01-06 07:42:19.000000000 +0200
+++ 2/usr/local/share/perl/5.10.0/Catalyst/Stats.pm 2009-01-06 08:34:14.000000000 +0200
@@ -6,6 +6,7 @@
use Text::SimpleTable ();
use Tree::Simple qw/use_weak_refs/;
use Tree::Simple::Visitor::FindByUID;
+use Catalyst::Utils ();
sub new {
my $class = shift;
@@ -97,7 +98,11 @@
$self->profile(end => $self->{stack}->[$i]->getNodeValue->{action});
}
- my $t = Text::SimpleTable->new( [ 62, 'Action' ], [ 9, 'Time' ] );
+ my $column_width = Catalyst::Utils::term_width() - 9 - 13;
+ my $t = Text::SimpleTable->new(
+ [ $column_width, 'Action' ],
+ [ 9, 'Time' ]
+ );
my @results;
$self->{tree}->traverse(
sub {
diff -ur 1/usr/local/share/perl/5.10.0/Catalyst/Utils.pm 2/usr/local/share/perl/5.10.0/Catalyst/Utils.pm
--- 1/usr/local/share/perl/5.10.0/Catalyst/Utils.pm 2009-01-06 07:24:44.000000000 +0200
+++ 2/usr/local/share/perl/5.10.0/Catalyst/Utils.pm 2009-01-06 08:47:07.000000000 +0200
@@ -329,6 +329,48 @@
return;
}
+=head2 term_width
+
+Try to guess terminal width to use with formatting of debug output
+All you need to get this work, is:
+ 1) export $COLUMNS from your shell, or
+ 2) install Term::Size::Any and Term::Size::Perl (nix) or Term::Size::Win32 (win)
+As last resort, default value of 80 chars will be used.
+
+=cut
+
+use constant WIDTH_DEF => 80;
+use constant WIDTH_MAX => 110;
+use constant WIDTH_MIN => 70;
+my $_term_width;
+
+sub term_width {
+ return $_term_width if $_term_width;
+
+ my ($class) = @_;
+ my $width = WIDTH_DEF;
+
+ my $ret = eval '
+ use Term::Size::Any;
+ my ($columns, $rows) = Term::Size::Any::chars;
+ return $columns;
+ ';
+
+ unless ($@) {
+ $width = $ret;
+ } else {
+ $width = $ENV{COLUMNS}
+ if exists($ENV{COLUMNS})
+ && $ENV{COLUMNS} =~ m/^\d+$/
+ && $ENV{COLUMNS} >= WIDTH_DEF;
+ }
+
+ $width = WIDTH_MAX if $width > WIDTH_MAX;
+ $width = WIDTH_MIN if $width < WIDTH_MIN;
+
+ return $_term_width = $width;
+}
+
=head1 AUTHOR
Sebastian Riedel, C<[email protected]>
diff -ur 1/usr/local/share/perl/5.10.0/Catalyst.pm 2/usr/local/share/perl/5.10.0/Catalyst.pm
--- 1/usr/local/share/perl/5.10.0/Catalyst.pm 2009-01-06 08:16:54.000000000 +0200
+++ 2/usr/local/share/perl/5.10.0/Catalyst.pm 2009-01-06 08:19:40.000000000 +0200
@@ -854,7 +854,8 @@
my @plugins = map { "$_ " . ( $_->VERSION || '' ) } $class->registered_plugins;
if (@plugins) {
- my $t = Text::SimpleTable->new(74);
+ my $column_width = Catalyst::Utils::term_width() - 6;
+ my $t = Text::SimpleTable->new($column_width);
$t->row($_) for @plugins;
$class->log->debug( "Loaded plugins:\n" . $t->draw . "\n" );
}
@@ -886,7 +887,11 @@
$class->setup_components;
if ( $class->debug ) {
- my $t = Text::SimpleTable->new( [ 63, 'Class' ], [ 8, 'Type' ] );
+ my $column_width = Catalyst::Utils::term_width() - 8 - 9;
+ my $t = Text::SimpleTable->new(
+ [ $column_width, 'Class' ],
+ [ 8, 'Type' ]
+ );
for my $comp ( sort keys %{ $class->components } ) {
my $type = ref $class->components->{$comp} ? 'instance' : 'class';
$t->row( $comp, $type );
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/