[Catalyst-commits] r9121 - in Catalyst-Runtime/5.70/trunk: . lib
lib/Catalyst lib/Catalyst/DispatchType
jhannah at dev.catalyst.perl.org
jhannah at dev.catalyst.perl.org
Thu Jan 22 01:53:47 GMT 2009
Author: jhannah
Date: 2009-01-22 01:53:47 +0000 (Thu, 22 Jan 2009)
New Revision: 9121
Modified:
Catalyst-Runtime/5.70/trunk/Changes
Catalyst-Runtime/5.70/trunk/lib/Catalyst.pm
Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Chained.pm
Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Path.pm
Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Regex.pm
Catalyst-Runtime/5.70/trunk/lib/Catalyst/Dispatcher.pm
Catalyst-Runtime/5.70/trunk/lib/Catalyst/Stats.pm
Catalyst-Runtime/5.70/trunk/lib/Catalyst/Utils.pm
Log:
Text::SimpleTable's now go as wide as $ENV{COLUMNS} (jhannah)
Patch written by Oleg Kostyuk <cub.uanic at gmail.com>
Also nuked Stats.pm report() -- my patch to 5.80/trunk a couple
weeks back added tests and everything over there.
Modified: Catalyst-Runtime/5.70/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.70/trunk/Changes 2009-01-22 01:45:16 UTC (rev 9120)
+++ Catalyst-Runtime/5.70/trunk/Changes 2009-01-22 01:53:47 UTC (rev 9121)
@@ -1,6 +1,8 @@
# This file documents the revision history for Perl extension Catalyst.
5.71000 2009-01-19 17:50:00
+ - Text::SimpleTable's go as wide as $ENV{COLUMNS} (jhannah)
+ Patch written by Oleg Kostyuk <cub.uanic at gmail.com>
- backport go doc patch
- added ru/ua translations to error page
- backport stripping build_requires
Modified: Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Chained.pm
===================================================================
--- Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Chained.pm 2009-01-22 01:45:16 UTC (rev 9120)
+++ Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Chained.pm 2009-01-22 01:53:47 UTC (rev 9121)
@@ -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,9 +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' ], [ 36, 'Private' ], [ $column_width, 'Private' ]
+ );
ENDPOINT: foreach my $endpoint (
sort { $a->reverse cmp $b->reverse }
Modified: Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Path.pm
===================================================================
--- Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Path.pm 2009-01-22 01:45:16 UTC (rev 9120)
+++ Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Path.pm 2009-01-22 01:53:47 UTC (rev 9121)
@@ -3,6 +3,7 @@
use strict;
use base qw/Catalyst::DispatchType/;
use Text::SimpleTable;
+use Catalyst::Utils;
use URI;
=head1 NAME
@@ -25,7 +26,10 @@
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} } ) {
Modified: Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Regex.pm
===================================================================
--- Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Regex.pm 2009-01-22 01:45:16 UTC (rev 9120)
+++ Catalyst-Runtime/5.70/trunk/lib/Catalyst/DispatchType/Regex.pm 2009-01-22 01:53:47 UTC (rev 9121)
@@ -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,8 @@
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" );
Modified: Catalyst-Runtime/5.70/trunk/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.70/trunk/lib/Catalyst/Dispatcher.pm 2009-01-22 01:45:16 UTC (rev 9120)
+++ Catalyst-Runtime/5.70/trunk/lib/Catalyst/Dispatcher.pm 2009-01-22 01:53:47 UTC (rev 9121)
@@ -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;
@@ -571,10 +572,9 @@
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' ]
+ [ 20, 'Private' ], [ 36, 'Class' ], [ $column_width, 'Method' ]
);
my $has_private = 0;
Modified: Catalyst-Runtime/5.70/trunk/lib/Catalyst/Stats.pm
===================================================================
--- Catalyst-Runtime/5.70/trunk/lib/Catalyst/Stats.pm 2009-01-22 01:45:16 UTC (rev 9120)
+++ Catalyst-Runtime/5.70/trunk/lib/Catalyst/Stats.pm 2009-01-22 01:53:47 UTC (rev 9121)
@@ -4,6 +4,7 @@
use warnings;
use Time::HiRes qw/gettimeofday tv_interval/;
use Text::SimpleTable ();
+use Catalyst::Utils;
use Tree::Simple qw/use_weak_refs/;
use Tree::Simple::Visitor::FindByUID;
@@ -92,12 +93,8 @@
sub report {
my $self = shift;
-# close any remaining open nodes
- for (my $i = $#{$self->{stack}}; $i > 0; $i--) {
- $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 {
Modified: Catalyst-Runtime/5.70/trunk/lib/Catalyst/Utils.pm
===================================================================
--- Catalyst-Runtime/5.70/trunk/lib/Catalyst/Utils.pm 2009-01-22 01:45:16 UTC (rev 9120)
+++ Catalyst-Runtime/5.70/trunk/lib/Catalyst/Utils.pm 2009-01-22 01:53:47 UTC (rev 9121)
@@ -20,6 +20,8 @@
=head1 DESCRIPTION
+Catalyst Utilities.
+
=head1 METHODS
=head2 appprefix($class)
@@ -331,6 +333,45 @@
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) Install Term::Size::Any, or
+
+2) Export $COLUMNS from your shell.
+
+(Warning to bash users: 'echo $COLUMNS' may be showing you the bash
+variable, not $ENV{COLUMNS}. 'export COLUMNS=$COLUMNS' and you should see
+that 'env' now lists COLUMNS.)
+
+As last resort, default value of 80 chars will be used.
+
+=cut
+
+my $_term_width;
+
+sub term_width {
+ return $_term_width if $_term_width;
+
+ my $width = eval '
+ use Term::Size::Any;
+ my ($columns, $rows) = Term::Size::Any::chars;
+ return $columns;
+ ';
+
+ if ($@) {
+ $width = $ENV{COLUMNS}
+ if exists($ENV{COLUMNS})
+ && $ENV{COLUMNS} =~ m/^\d+$/;
+ }
+
+ $width = 80 unless ($width && $width >= 80);
+ return $_term_width = $width;
+}
+
=head1 AUTHORS
Catalyst Contributors, see Catalyst.pm
Modified: Catalyst-Runtime/5.70/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.70/trunk/lib/Catalyst.pm 2009-01-22 01:45:16 UTC (rev 9120)
+++ Catalyst-Runtime/5.70/trunk/lib/Catalyst.pm 2009-01-22 01:53:47 UTC (rev 9121)
@@ -956,7 +956,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" );
}
@@ -988,7 +989,8 @@
$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 );
@@ -2589,6 +2591,8 @@
omega: Andreas Marienborg
+Oleg Kostyuk <cub.uanic at gmail.com>
+
phaylon: Robert Sedlacek <phaylon at dunkelheit.at>
sky: Arthur Bergman
More information about the Catalyst-commits
mailing list