[Catalyst-commits] r9120 - in Catalyst-Runtime/5.80/trunk: . lib lib/Catalyst lib/Catalyst/DispatchType

jhannah at dev.catalyst.perl.org jhannah at dev.catalyst.perl.org
Thu Jan 22 01:45:16 GMT 2009


Author: jhannah
Date: 2009-01-22 01:45:16 +0000 (Thu, 22 Jan 2009)
New Revision: 9120

Modified:
   Catalyst-Runtime/5.80/trunk/Changes
   Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Path.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Regex.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Stats.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm
Log:
Text::SimpleTable's now go as wide as $ENV{COLUMNS}
Patch written by Oleg Kostyuk <cub.uanic at gmail.com>


Modified: Catalyst-Runtime/5.80/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.80/trunk/Changes	2009-01-21 03:51:16 UTC (rev 9119)
+++ Catalyst-Runtime/5.80/trunk/Changes	2009-01-22 01:45:16 UTC (rev 9120)
@@ -1,6 +1,8 @@
 # This file documents the revision history for Perl extension Catalyst.
 
 5.8000_05
+        - Text::SimpleTable's go as wide as $ENV{COLUMNS} (jhannah)
+          Patch written by Oleg Kostyuk <cub.uanic at gmail.com>
         - Improve docs for visit (mateu)
         - Add docs for finalize hook (dhoss)
         - Added ru/ua translations to error page

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm	2009-01-21 03:51:16 UTC (rev 9119)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm	2009-01-22 01:45:16 UTC (rev 9120)
@@ -5,6 +5,7 @@
 
 use Text::SimpleTable;
 use Catalyst::ActionChain;
+use Catalyst::Utils;
 use URI;
 
 has _endpoints => (
@@ -67,9 +68,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' ]
+    );
 
     my $has_unattached_actions;
     my $unattached_actions = Text::SimpleTable->new(

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Path.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Path.pm	2009-01-21 03:51:16 UTC (rev 9119)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Path.pm	2009-01-22 01:45:16 UTC (rev 9120)
@@ -4,6 +4,7 @@
 extends 'Catalyst::DispatchType';
 
 use Text::SimpleTable;
+use Catalyst::Utils;
 use URI;
 
 has _paths => (
@@ -35,7 +36,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.80/trunk/lib/Catalyst/DispatchType/Regex.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Regex.pm	2009-01-21 03:51:16 UTC (rev 9119)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Regex.pm	2009-01-22 01:45:16 UTC (rev 9120)
@@ -4,6 +4,7 @@
 extends 'Catalyst::DispatchType::Path';
 
 use Text::SimpleTable;
+use Catalyst::Utils;
 use Text::Balanced ();
 
 has _compiled => (
@@ -35,7 +36,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.80/trunk/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm	2009-01-21 03:51:16 UTC (rev 9119)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm	2009-01-22 01:45:16 UTC (rev 9120)
@@ -10,6 +10,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;
@@ -583,10 +584,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.80/trunk/lib/Catalyst/Stats.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Stats.pm	2009-01-21 03:51:16 UTC (rev 9119)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Stats.pm	2009-01-22 01:45:16 UTC (rev 9120)
@@ -3,6 +3,7 @@
 use Moose;
 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;
 
@@ -88,7 +89,8 @@
 sub report {
     my $self = shift;
 
-    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->traverse(
                 sub {

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm	2009-01-21 03:51:16 UTC (rev 9119)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm	2009-01-22 01:45:16 UTC (rev 9120)
@@ -19,6 +19,8 @@
 
 =head1 DESCRIPTION
 
+Catalyst Utilities. 
+
 =head1 METHODS
 
 =head2 appprefix($class)
@@ -334,6 +336,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.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm	2009-01-21 03:51:16 UTC (rev 9119)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm	2009-01-22 01:45:16 UTC (rev 9120)
@@ -989,7 +989,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" );
         }
@@ -1021,7 +1022,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 );
@@ -2617,6 +2619,8 @@
 
 omega: Andreas Marienborg
 
+Oleg Kostyuk <cub.uanic at gmail.com>
+
 phaylon: Robert Sedlacek <phaylon at dunkelheit.at>
 
 rafl: Florian Ragwitz <rafl at debian.org>




More information about the Catalyst-commits mailing list