[jifty-devel] [Jifty-commit] r7491 - in jifty/trunk: lib/Jifty lib/Jifty/Script

Jesse Vincent jesse at bestpractical.com
Tue Sep 22 09:40:55 EDT 2009


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?


On Fri, Sep 18, 2009 at 01:12:26AM -0400, Jifty commits wrote:
> Author: sunnavy
> Date: Fri Sep 18 01:12:25 2009
> New Revision: 7491
> 
> Modified:
>    jifty/trunk/bin/jifty
>    jifty/trunk/lib/Jifty/Script.pm
>    jifty/trunk/lib/Jifty/Script/Help.pm
> 
> Log:
> 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);
> -    unshift @INC, "$root/lib" if ($root);
> +
> +    # `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
> +        || ( $ARGV[0] eq 'help' )
> +        && (
> +            @ARGV == 1 || grep { lc $ARGV[1] eq lc $_ } @Jifty::Script::CORE_CMDS,
> +            @Jifty::Script::CORE_MAN,
> +        )
> +      )
> +    {
> +
> +   # 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 );
> +        unshift @INC, "$root/lib" if ($root);
> +
> +        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;
>  
> +our @CORE_CMDS = qw/action adopt app env fastcgi help modperl2 model
> +  plugin po schema script server/;
> +our @CORE_MAN = qw/
> +  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;
> +    my %args = @_;
> +    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;
> +    my @topics = @_;
> +
> +    push @topics, 'commands' unless (@topics);
> +
> +    foreach my $topic (@topics) {
> +        if ( $topic eq 'commands' ) {
> +            $self->brief_usage($_) for $self->app->files;
> +        }
> +        elsif ( grep { $topic eq $_ } @Jifty::Script::CORE_CMDS ) {
> +            # 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
> Jifty-commit at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-commit
> 

-- 


More information about the jifty-devel mailing list