Changeset 8049


Ignore:
Timestamp:
07/07/10 04:13:48 (3 years ago)
Author:
GeorgeClark
Message:

Item9267: Defer some module loading to improve performance of resource
handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/bin/configure

    r8044 r8049  
    242242} 
    243243 
     244my $loadBasicModule = \&_loadBasicModule;   # Save a reference for use later.   
     245 
    244246foreach my $module ( 'FindBin', 'File::Spec', 'Config', 'CGI qw(:any)', ) { 
    245247    _loadBasicModule($module); 
     
    284286    'Cwd',                               'Data::Dumper', 
    285287    'File::Copy',                        'File::Temp', 
     288    'Foswiki::Configure::TemplateParser', 
     289  ) 
     290{ 
     291    _loadBasicModule($module); 
     292} 
     293 
     294$| = 1;    # no buffering on STDOUT 
     295 
     296########################################################### 
     297# From this point on we shouldn't have any more "fatal" (to configure) 
     298# errors, so we can report errors in the browser (i.e. without using die) 
     299 
     300# We are configuring $Foswiki::cfg, so we need to be in package Foswiki from 
     301# now on. 
     302package Foswiki; 
     303 
     304# We keep the actual config, and the default from Foswiki.spec, separate 
     305use vars qw( %cfg $defaultCfg ); 
     306 
     307# Declared in Foswiki to support checkers 
     308use vars qw( $query ); 
     309 
     310# 'constants' used in Foswiki.spec 
     311use vars qw( $TRUE $FALSE ); 
     312$TRUE  = 1; 
     313$FALSE = 0; 
     314our $badLSC; 
     315 
     316# Remember what we detected previously, for use by Checkers 
     317if ( $scriptName =~ /(\.\w+)$/ ) { 
     318    $Foswiki::cfg{DETECTED}{ScriptExtension} = $1; 
     319} 
     320 
     321# duplicated here, should use the one in Util.pm 
     322sub getScriptName { 
     323    my @script = File::Spec->splitdir( $ENV{SCRIPT_NAME} || 'THISSCRIPT' ); 
     324    my $scriptName = pop(@script); 
     325    $scriptName =~ s/.*[\/\\]//;    # Fix for Item3511, on Win XP 
     326    return $scriptName; 
     327} 
     328 
     329########################################################### 
     330# Grope the OS. This duplicates a bit of code in Foswiki.pm, 
     331# but it has to be duplicated because we don't want to deal 
     332# with loading Foswiki just yet. 
     333 
     334unless ( $Foswiki::cfg{DetailedOS} ) { 
     335    $Foswiki::cfg{DetailedOS} = $^O; 
     336    unless ( $Foswiki::cfg{DetailedOS} ) { 
     337        require Config; 
     338        $Foswiki::cfg{DetailedOS} = $Config::Config{osname}; 
     339    } 
     340} 
     341unless ( $Foswiki::cfg{OS} ) { 
     342    if ( $Foswiki::cfg{DetailedOS} =~ /darwin/i ) {    # MacOS X 
     343        $Foswiki::cfg{OS} = 'UNIX'; 
     344    } 
     345    elsif ( $Foswiki::cfg{DetailedOS} =~ /Win/i ) { 
     346        $Foswiki::cfg{OS} = 'WINDOWS'; 
     347    } 
     348    elsif ( $Foswiki::cfg{DetailedOS} =~ /vms/i ) { 
     349        $Foswiki::cfg{OS} = 'VMS'; 
     350    } 
     351    elsif ( $Foswiki::cfg{DetailedOS} =~ /bsdos/i ) { 
     352        $Foswiki::cfg{OS} = 'UNIX'; 
     353    } 
     354    elsif ( $Foswiki::cfg{DetailedOS} =~ /dos/i ) { 
     355        $Foswiki::cfg{OS} = 'DOS'; 
     356    } 
     357    elsif ( $Foswiki::cfg{DetailedOS} =~ /^MacOS$/i ) {    # MacOS 9 or earlier 
     358        $Foswiki::cfg{OS} = 'MACINTOSH'; 
     359    } 
     360    elsif ( $Foswiki::cfg{DetailedOS} =~ /os2/i ) { 
     361        $Foswiki::cfg{OS} = 'OS2'; 
     362    } 
     363    else { 
     364        $Foswiki::cfg{OS} = 'UNIX'; 
     365    } 
     366} 
     367 
     368our $query = new CGI; 
     369 
     370my $url = $query->url(); 
     371my $action = $query->param('action') || 'Configure'; 
     372 
     373our $DEFAULT_FIELD_WIDTH_NO_CSS = '40'; 
     374 
     375# Handle serving an resource embedded in the configure page, before generating 
     376# any other output 
     377if ( $action eq 'resource' ) { 
     378    my $resource = $query->param('resource'); 
     379    $resource =~ /^([-\w]+\.\w+)$/;    # filter-in and untaint 
     380    $resource = $1; 
     381    if ( defined($resource) ) { 
     382 
     383        #ignore $query->param('type') and set it using the extension 
     384        my $type = 'image/gif'; 
     385        if ( $resource =~ /\.ico$/ ) { 
     386            $type = 'resource/x-icon'; 
     387        } 
     388        elsif ( $resource =~ /\.js$/ ) { 
     389            $type = 'text/javascript'; 
     390        } 
     391 
     392        my $parser = Foswiki::Configure::TemplateParser->new; 
     393        my $text = $parser->getResource($resource); 
     394 
     395        # SMELL: this call is correct, but causes a perl error 
     396        # on some versions of CGI.pm 
     397        # print $query->header(-type => $query->param('type')); 
     398        # So use this instead: 
     399        print 'Content-type: ' . $type . "\n\n"; 
     400        print $text; 
     401    } 
     402    exit 0; 
     403} 
     404 
     405sub log { 
     406    my ($message) = @_; 
     407 
     408    $message ||= ''; 
     409    my $log = $Foswiki::cfg{DebugFileName} || 'ConfigureError.log'; 
     410    my $file; 
     411    if ( open( $file, '>>', $log ) ) { 
     412        print $file "$message\n"; 
     413        close($file); 
     414    } 
     415} 
     416 
     417# Load all the bits of the configure module that we explicitly use 
     418# The loadBasicModule does some extra analysis on errors. 
     419foreach my $module ( 
    286420    'Foswiki::Configure::Checker',       'Foswiki::Configure::Item', 
    287421    'Foswiki::Configure::Load',          'Foswiki::Configure::Pluggable', 
     
    293427    'Foswiki::Configure::UIs::Section',  'Foswiki::Configure::Value', 
    294428    'Foswiki::Configure::Valuer',        'Foswiki::Configure::GlobalControls', 
    295     'Foswiki::Configure::TemplateParser', 
    296429  ) 
    297430{ 
    298     _loadBasicModule($module); 
    299 } 
    300  
    301 $| = 1;    # no buffering on STDOUT 
    302  
    303 ########################################################### 
    304 # From this point on we shouldn't have any more "fatal" (to configure) 
    305 # errors, so we can report errors in the browser (i.e. without using die) 
    306  
    307 # We are configuring $Foswiki::cfg, so we need to be in package Foswiki from 
    308 # now on. 
    309 package Foswiki; 
    310  
    311 # We keep the actual config, and the default from Foswiki.spec, separate 
    312 use vars qw( %cfg $defaultCfg ); 
    313  
    314 # Declared in Foswiki to support checkers 
    315 use vars qw( $query ); 
    316  
    317 # 'constants' used in Foswiki.spec 
    318 use vars qw( $TRUE $FALSE ); 
    319 $TRUE  = 1; 
    320 $FALSE = 0; 
    321 our $badLSC; 
    322  
    323 # Remember what we detected previously, for use by Checkers 
    324 if ( $scriptName =~ /(\.\w+)$/ ) { 
    325     $Foswiki::cfg{DETECTED}{ScriptExtension} = $1; 
    326 } 
    327  
    328 # duplicated here, should use the one in Util.pm 
    329 sub getScriptName { 
    330     my @script = File::Spec->splitdir( $ENV{SCRIPT_NAME} || 'THISSCRIPT' ); 
    331     my $scriptName = pop(@script); 
    332     $scriptName =~ s/.*[\/\\]//;    # Fix for Item3511, on Win XP 
    333     return $scriptName; 
    334 } 
    335  
    336 ########################################################### 
    337 # Grope the OS. This duplicates a bit of code in Foswiki.pm, 
    338 # but it has to be duplicated because we don't want to deal 
    339 # with loading Foswiki just yet. 
    340  
    341 unless ( $Foswiki::cfg{DetailedOS} ) { 
    342     $Foswiki::cfg{DetailedOS} = $^O; 
    343     unless ( $Foswiki::cfg{DetailedOS} ) { 
    344         require Config; 
    345         $Foswiki::cfg{DetailedOS} = $Config::Config{osname}; 
    346     } 
    347 } 
    348 unless ( $Foswiki::cfg{OS} ) { 
    349     if ( $Foswiki::cfg{DetailedOS} =~ /darwin/i ) {    # MacOS X 
    350         $Foswiki::cfg{OS} = 'UNIX'; 
    351     } 
    352     elsif ( $Foswiki::cfg{DetailedOS} =~ /Win/i ) { 
    353         $Foswiki::cfg{OS} = 'WINDOWS'; 
    354     } 
    355     elsif ( $Foswiki::cfg{DetailedOS} =~ /vms/i ) { 
    356         $Foswiki::cfg{OS} = 'VMS'; 
    357     } 
    358     elsif ( $Foswiki::cfg{DetailedOS} =~ /bsdos/i ) { 
    359         $Foswiki::cfg{OS} = 'UNIX'; 
    360     } 
    361     elsif ( $Foswiki::cfg{DetailedOS} =~ /dos/i ) { 
    362         $Foswiki::cfg{OS} = 'DOS'; 
    363     } 
    364     elsif ( $Foswiki::cfg{DetailedOS} =~ /^MacOS$/i ) {    # MacOS 9 or earlier 
    365         $Foswiki::cfg{OS} = 'MACINTOSH'; 
    366     } 
    367     elsif ( $Foswiki::cfg{DetailedOS} =~ /os2/i ) { 
    368         $Foswiki::cfg{OS} = 'OS2'; 
    369     } 
    370     else { 
    371         $Foswiki::cfg{OS} = 'UNIX'; 
    372     } 
    373 } 
    374  
    375 our $query = new CGI; 
    376  
    377 my $url = $query->url(); 
    378 my $action = $query->param('action') || 'Configure'; 
    379  
    380 our $DEFAULT_FIELD_WIDTH_NO_CSS = '40'; 
    381  
    382 # Handle serving an resource embedded in the configure page, before generating 
    383 # any other output 
    384 if ( $action eq 'resource' ) { 
    385     my $resource = $query->param('resource'); 
    386     $resource =~ /^([-\w]+\.\w+)$/;    # filter-in and untaint 
    387     $resource = $1; 
    388     if ( defined($resource) ) { 
    389  
    390         #ignore $query->param('type') and set it using the extension 
    391         my $type = 'image/gif'; 
    392         if ( $resource =~ /\.ico$/ ) { 
    393             $type = 'resource/x-icon'; 
    394         } 
    395         elsif ( $resource =~ /\.js$/ ) { 
    396             $type = 'text/javascript'; 
    397         } 
    398  
    399         my $parser = Foswiki::Configure::TemplateParser->new; 
    400         my $text = $parser->getResource($resource); 
    401  
    402         # SMELL: this call is correct, but causes a perl error 
    403         # on some versions of CGI.pm 
    404         # print $query->header(-type => $query->param('type')); 
    405         # So use this instead: 
    406         print 'Content-type: ' . $type . "\n\n"; 
    407         print $text; 
    408     } 
    409     exit 0; 
    410 } 
    411  
    412 sub log { 
    413     my ($message) = @_; 
    414  
    415     $message ||= ''; 
    416     my $log = $Foswiki::cfg{DebugFileName} || 'ConfigureError.log'; 
    417     my $file; 
    418     if ( open( $file, '>>', $log ) ) { 
    419         print $file "$message\n"; 
    420         close($file); 
    421     } 
     431    &$loadBasicModule($module); 
    422432} 
    423433 
Note: See TracChangeset for help on using the changeset viewer.