Jesse Vincent
2009-09-22 13:40:55 UTC
This is an awful lot of scary hardcoding to make the help command
faster. I'm concerned about the hacks to bin/jifty, but I'm even more
worried about the hardcoding of command and helpfile names. That's
likely to lead to bitrot and out of sync lists of what's actually there.
Sunnavy, can you back this out for now so we can work on a better way to
do this?
faster. I'm concerned about the hacks to bin/jifty, but I'm even more
worried about the hardcoding of command and helpfile names. That's
likely to lead to bitrot and out of sync lists of what's actually there.
Sunnavy, can you back this out for now so we can work on a better way to
do this?
Author: sunnavy
Date: Fri Sep 18 01:12:25 2009
New Revision: 7491
jifty/trunk/bin/jifty
jifty/trunk/lib/Jifty/Script.pm
jifty/trunk/lib/Jifty/Script/Help.pm
hack to speed up "jifty help" about 4.5x faster
Modified: jifty/trunk/bin/jifty
==============================================================================
--- jifty/trunk/bin/jifty (original)
+++ jifty/trunk/bin/jifty Fri Sep 18 01:12:25 2009
@@ -1,16 +1,39 @@
#!/usr/bin/env perl
use warnings;
use strict;
-use UNIVERSAL::require;
BEGIN {
- Jifty::Util->require or die $UNIVERSAL::require::ERROR;
- my $root = Jifty::Util->app_root(quiet => 1);
+
+ # `use Jifty::Everything' is time-consuming,
+ # when people just want to read the help message, waiting sucks.
+ # on my machine, this is 4.5x faster or so, from 0.7s to 0.15s
+ require Jifty::Script;
+ if (
+ || ( $ARGV[0] eq 'help' )
+ && (
+ )
+ )
+ {
+
+ # only_core is to tell Jifty::Script not to use Jifty::Everything to find all
+ # the cmds
+ Jifty::Script->import( only_core => 1 );
+ }
+ else {
+ no warnings 'once';
+ require UNIVERSAL::require;
+ Jifty::Util->require or die $UNIVERSAL::require::ERROR;
+ my $root = Jifty::Util->app_root( quiet => 1 );
+
+ require Jifty;
+ Jifty::Script->import;
+ }
}
-use Jifty;
-use Jifty::Script;
local $SIG{INT} = sub { warn "Stopped\n"; exit; };
Jifty::Script->dispatch();
Modified: jifty/trunk/lib/Jifty/Script.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script.pm (original)
+++ jifty/trunk/lib/Jifty/Script.pm Fri Sep 18 01:12:25 2009
@@ -2,10 +2,21 @@
use App::CLI;
use base qw/App::CLI App::CLI::Command Jifty::Object/;
-use Jifty::Everything;
-Jifty::Everything->plugin_commands;
use Pod::Usage;
+ plugin po schema script server/;
+ AccessControl Glossary Tutorial
+ AccessControl_zhtw JavaScript TutorialRest
+ Actions JavaScript_zhtw Tutorial_de
+ Actions_zhtw Models Tutorial_ja
+ Continuations ObjectModel Tutorial_zhtw
+ Cookbook PageRegions Upgrading
+ Deploying Preload UsingCSSandJS
+ Deploying_zhtw RequestHandling jQueryMigrationGuide
+ FAQ Style /;
+
=head1 NAME
Jifty::Script - Base class for all bin/jifty commands
@@ -105,4 +116,13 @@
) if $self->{man};
}
+sub import {
+ my $self = shift;
+ unless ( $args{only_core} ) {
+ require Jifty::Everything;
+ Jifty::Everything->plugin_commands;
+ }
+}
+
1;
Modified: jifty/trunk/lib/Jifty/Script/Help.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/Help.pm (original)
+++ jifty/trunk/lib/Jifty/Script/Help.pm Fri Sep 18 01:12:25 2009
@@ -3,6 +3,37 @@
use base qw( App::CLI::Command::Help Jifty::Script );
use File::Find qw(find);
+sub run {
+ my $self = shift;
+
+
+ if ( $topic eq 'commands' ) {
+ $self->brief_usage($_) for $self->app->files;
+ }
+ # to find usage of a CMD, App::CLI will require the CMD.pm first
+ # that's too heavy for us because some CMD.pm `use Jifty',
+ # which `use Jifty::Everything'!
+ my $file = $INC{'Jifty/Script/Help.pm'};
+ $file =~ s/Help(?=\.pm$)/ucfirst $topic/e;
+
+ open my $fh, '<:utf8', $file or die $!;
+ require Pod::Simple::Text;
+ my $parser = Pod::Simple::Text->new;
+ my $buf;
+ $parser->output_string( \$buf );
+ $parser->parse_file($fh);
+ print $self->loc_text($buf);
+ }
+ else {
+ $self->SUPER::run($topic);
+ }
+ }
+}
+
sub help_base {
return "Jifty::Manual";
}
_______________________________________________
Jifty-commit mailing list
http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-commit
--Date: Fri Sep 18 01:12:25 2009
New Revision: 7491
jifty/trunk/bin/jifty
jifty/trunk/lib/Jifty/Script.pm
jifty/trunk/lib/Jifty/Script/Help.pm
hack to speed up "jifty help" about 4.5x faster
Modified: jifty/trunk/bin/jifty
==============================================================================
--- jifty/trunk/bin/jifty (original)
+++ jifty/trunk/bin/jifty Fri Sep 18 01:12:25 2009
@@ -1,16 +1,39 @@
#!/usr/bin/env perl
use warnings;
use strict;
-use UNIVERSAL::require;
BEGIN {
- Jifty::Util->require or die $UNIVERSAL::require::ERROR;
- my $root = Jifty::Util->app_root(quiet => 1);
+
+ # `use Jifty::Everything' is time-consuming,
+ # when people just want to read the help message, waiting sucks.
+ # on my machine, this is 4.5x faster or so, from 0.7s to 0.15s
+ require Jifty::Script;
+ if (
+ || ( $ARGV[0] eq 'help' )
+ && (
+ )
+ )
+ {
+
+ # only_core is to tell Jifty::Script not to use Jifty::Everything to find all
+ # the cmds
+ Jifty::Script->import( only_core => 1 );
+ }
+ else {
+ no warnings 'once';
+ require UNIVERSAL::require;
+ Jifty::Util->require or die $UNIVERSAL::require::ERROR;
+ my $root = Jifty::Util->app_root( quiet => 1 );
+
+ require Jifty;
+ Jifty::Script->import;
+ }
}
-use Jifty;
-use Jifty::Script;
local $SIG{INT} = sub { warn "Stopped\n"; exit; };
Jifty::Script->dispatch();
Modified: jifty/trunk/lib/Jifty/Script.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script.pm (original)
+++ jifty/trunk/lib/Jifty/Script.pm Fri Sep 18 01:12:25 2009
@@ -2,10 +2,21 @@
use App::CLI;
use base qw/App::CLI App::CLI::Command Jifty::Object/;
-use Jifty::Everything;
-Jifty::Everything->plugin_commands;
use Pod::Usage;
+ plugin po schema script server/;
+ AccessControl Glossary Tutorial
+ AccessControl_zhtw JavaScript TutorialRest
+ Actions JavaScript_zhtw Tutorial_de
+ Actions_zhtw Models Tutorial_ja
+ Continuations ObjectModel Tutorial_zhtw
+ Cookbook PageRegions Upgrading
+ Deploying Preload UsingCSSandJS
+ Deploying_zhtw RequestHandling jQueryMigrationGuide
+ FAQ Style /;
+
=head1 NAME
Jifty::Script - Base class for all bin/jifty commands
@@ -105,4 +116,13 @@
) if $self->{man};
}
+sub import {
+ my $self = shift;
+ unless ( $args{only_core} ) {
+ require Jifty::Everything;
+ Jifty::Everything->plugin_commands;
+ }
+}
+
1;
Modified: jifty/trunk/lib/Jifty/Script/Help.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/Help.pm (original)
+++ jifty/trunk/lib/Jifty/Script/Help.pm Fri Sep 18 01:12:25 2009
@@ -3,6 +3,37 @@
use base qw( App::CLI::Command::Help Jifty::Script );
use File::Find qw(find);
+sub run {
+ my $self = shift;
+
+
+ if ( $topic eq 'commands' ) {
+ $self->brief_usage($_) for $self->app->files;
+ }
+ # to find usage of a CMD, App::CLI will require the CMD.pm first
+ # that's too heavy for us because some CMD.pm `use Jifty',
+ # which `use Jifty::Everything'!
+ my $file = $INC{'Jifty/Script/Help.pm'};
+ $file =~ s/Help(?=\.pm$)/ucfirst $topic/e;
+
+ open my $fh, '<:utf8', $file or die $!;
+ require Pod::Simple::Text;
+ my $parser = Pod::Simple::Text->new;
+ my $buf;
+ $parser->output_string( \$buf );
+ $parser->parse_file($fh);
+ print $self->loc_text($buf);
+ }
+ else {
+ $self->SUPER::run($topic);
+ }
+ }
+}
+
sub help_base {
return "Jifty::Manual";
}
_______________________________________________
Jifty-commit mailing list
http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-commit