X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst.pm;h=3bf7e4d971e3393083ec3646edb65883ac8ebac7;hb=51f0308d123198167a88df51ea7c8ef3ac8efd2c;hp=768ad238520c1d384ed1318124b0ba0fa893a539;hpb=f45789b1af1b76c31c498f4b713ab48a5f28ba0c;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 768ad23..3bf7e4d 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1,18 +1,19 @@ package Catalyst; use strict; -use base 'Catalyst::Base'; +use base qw[ Catalyst::Base Catalyst::Setup ]; use UNIVERSAL::require; use Catalyst::Exception; use Catalyst::Log; use Catalyst::Utils; +use NEXT; use Text::ASCIITable; use Path::Class; our $CATALYST_SCRIPT_GEN = 4; -__PACKAGE__->mk_classdata($_) for qw/dispatcher engine log/; +__PACKAGE__->mk_classdata($_) for qw/arguments dispatcher engine log/; -our $VERSION = '5.24'; +our $VERSION = '5.31'; our @ISA; =head1 NAME @@ -126,94 +127,19 @@ Returns a hashref containing your applications settings. sub import { my ( $class, @arguments ) = @_; + # We have to limit $class to Catalyst to avoid pushing Catalyst upon every + # callers @ISA. + return unless $class eq 'Catalyst'; + my $caller = caller(0); - - if ( $caller eq 'main' ) { - return; - } - # Prepare inheritance - unless ( $caller->isa($class) ) { + unless ( $caller->isa('Catalyst') ) { no strict 'refs'; push @{"$caller\::ISA"}, $class; } - - if ( $caller->engine ) { - $caller->log->warn( qq/Attempt to re-initialize "$caller"/ ); - return; - } - - # Process options - my $flags = { }; - - foreach (@arguments) { - - if ( /^-Debug$/ ) { - $flags->{log} = ( $flags->{log} ) ? 'debug,' . $flags->{log} : 'debug'; - } - elsif (/^-(\w+)=?(.*)$/) { - $flags->{ lc $1 } = $2; - } - else { - push @{ $flags->{plugins} }, $_; - } - } - - $caller->setup_log ( delete $flags->{log} ); - $caller->setup_plugins ( delete $flags->{plugins} ); - $caller->setup_dispatcher ( delete $flags->{dispatcher} ); - $caller->setup_engine ( delete $flags->{engine} ); - $caller->setup_home ( delete $flags->{home} ); - - for my $flag ( sort keys %{ $flags } ) { - - if ( my $code = $caller->can( 'setup_' . $flag ) ) { - &$code( $caller, delete $flags->{$flag} ); - } - else { - $caller->log->warn(qq/Unknown flag "$flag"/); - } - } - - $caller->log->warn( "You are running an old helper script! " - . "Please update your scripts by regenerating the " - . "application and copying over the new scripts." ) - if ( $ENV{CATALYST_SCRIPT_GEN} - && ( $ENV{CATALYST_SCRIPT_GEN} < $CATALYST_SCRIPT_GEN ) ); - - - if ( $caller->debug ) { - - my @plugins = (); - { - no strict 'refs'; - @plugins = grep { /^Catalyst::Plugin/ } @{"$caller\::ISA"}; - } - - if ( @plugins ) { - my $t = Text::ASCIITable->new; - $t->setOptions( 'hide_HeadRow', 1 ); - $t->setOptions( 'hide_HeadLine', 1 ); - $t->setCols('Class'); - $t->setColWidth( 'Class', 75, 1 ); - $t->addRow($_) for @plugins; - $caller->log->debug( "Loaded plugins:\n" . $t->draw ); - } - - my $dispatcher = $caller->dispatcher; - my $engine = $caller->engine; - my $home = $caller->config->{home}; - - $caller->log->debug(qq/Loaded dispatcher "$dispatcher"/); - $caller->log->debug(qq/Loaded engine "$engine"/); - - $home - ? ( -d $home ) - ? $caller->log->debug(qq/Found home "$home"/) - : $caller->log->debug(qq/Home "$home" doesn't exist/) - : $caller->log->debug(q/Couldn't find home/); - } + $caller->arguments( [ @arguments ] ); + $caller->setup_home; } =item $c->engine @@ -268,258 +194,102 @@ sub plugin { if $class->debug; } -=item $c->setup_dispatcher - -=cut - -sub setup_dispatcher { - my ( $class, $dispatcher ) = @_; - - if ( $dispatcher ) { - $dispatcher = 'Catalyst::Dispatcher::' . $dispatcher; - } - - if ( $ENV{CATALYST_DISPATCHER} ) { - $dispatcher = 'Catalyst::Dispatcher::' . $ENV{CATALYST_DISPATCHER}; - } - - if ( $ENV{ uc($class) . '_DISPATCHER' } ) { - $dispatcher = 'Catalyst::Dispatcher::' . $ENV{ uc($class) . '_DISPATCHER' }; - } - - unless ( $dispatcher ) { - $dispatcher = 'Catalyst::Dispatcher'; - } - - $dispatcher->require; - - if ( $@ ) { - Catalyst::Exception->throw( - message => qq/Couldn't load dispatcher "$dispatcher", "$@"/ - ); - } - - { - no strict 'refs'; - push @{"$class\::ISA"}, $dispatcher; - } - - $class->dispatcher($dispatcher); -} - -=item $c->setup_engine - -=cut - -sub setup_engine { - my ( $class, $engine ) = @_; - - if ( $engine ) { - $engine = 'Catalyst::Engine::' . $engine; - } - - if ( $ENV{CATALYST_ENGINE} ) { - $engine = 'Catalyst::Engine::' . $ENV{CATALYST_ENGINE}; - } - - if ( $ENV{ uc($class) . '_ENGINE' } ) { - $engine = 'Catalyst::Engine::' . $ENV{ uc($class) . '_ENGINE' }; - } - - if ( ! $engine && $ENV{MOD_PERL} ) { - - my ( $software, $version ) = $ENV{MOD_PERL} =~ /^(\S+)\/(\d+(?:[\.\_]\d+)+)/; - - $version =~ s/_//g; - $version =~ s/(\.[^.]+)\./$1/g; - - if ( $software eq 'mod_perl') { - - if ( $version >= 1.99922 ) { - - $engine = 'Catalyst::Engine::Apache::MP20'; - - if ( Apache2::Request->require ) { - $engine = 'Catalyst::Engine::Apache::MP20::Apreq'; - } - } - - elsif ( $version >= 1.9901 ) { - - $engine = 'Catalyst::Engine::Apache::MP19'; - - if ( Apache::Request->require ) { - $engine = 'Catalyst::Engine::Apache::MP19::Apreq'; - } - } - - elsif ( $version >= 1.24 ) { - - $engine = 'Catalyst::Engine::Apache::MP13'; - - if ( Apache::Request->require ) { - $engine = 'Catalyst::Engine::Apache::MP13::Apreq'; - } - } - - else { - Catalyst::Exception->throw( - message => qq/Unsupported mod_perl version: $ENV{MOD_PERL}/ - ); - } - } +=back - elsif ( $software eq 'Zeus-Perl' ) { - $engine = 'Catalyst::Engine::Zeus'; - } +=head1 CASE SENSITIVITY - else { - Catalyst::Exception->throw( - message => qq/Unsupported mod_perl: $ENV{MOD_PERL}/ - ); - } - } +By default Catalyst is not case sensitive, so C becomes +C. - unless ( $engine ) { - $engine = 'Catalyst::Engine::CGI'; - } +But you can activate case sensitivity with a config parameter. - $engine->require; + MyApp->config->{case_sensitive} = 1; - if ( $@ ) { - Catalyst::Exception->throw( - message => qq/Couldn't load engine "$engine", "$@"/ - ); - } - - { - no strict 'refs'; - push @{"$class\::ISA"}, $engine; - } - - $class->engine($engine); -} +=head1 LIMITATIONS -=item $c->setup_home +mod_perl2 support is considered experimental and may contain bugs. -=cut +=head1 SUPPORT -sub setup_home { - my ( $class, $home ) = @_; +IRC: - if ( $ENV{CATALYST_HOME} ) { - $home = $ENV{CATALYST_HOME}; - } + Join #catalyst on irc.perl.org. - if ( $ENV{ uc($class) . '_HOME' } ) { - $home = $ENV{ uc($class) . '_HOME' }; - } +Mailing-Lists: - unless ( $home ) { - $home = Catalyst::Utils::home($class); - } + http://lists.rawmode.org/mailman/listinfo/catalyst + http://lists.rawmode.org/mailman/listinfo/catalyst-dev - if ( $home ) { - $class->config->{home} = $home; - $class->config->{root} = dir($home)->subdir('root'); - } -} +Web: -=item $c->setup_log + http://catalyst.perl.org -=cut +=head1 SEE ALSO -sub setup_log { - my ( $class, $debug ) = @_; +=over 4 - unless ( $class->log ) { - $class->log( Catalyst::Log->new ); - } +=item L - The Catalyst Manual - if ( $ENV{CATALYST_DEBUG} || $ENV{ uc($class) . '_DEBUG' } || $debug ) { - no strict 'refs'; - *{"$class\::debug"} = sub { 1 }; - $class->log->debug('Debug messages enabled'); - } -} +=item L - Core Engine -=item $c->setup_plugins +=item L - The Log Class. -=cut +=item L - The Request Object -sub setup_plugins { - my ( $class, $plugins ) = @_; +=item L - The Response Object - for my $plugin ( @$plugins ) { +=item L - The test suite. - $plugin = "Catalyst::Plugin::$plugin"; +=back - $plugin->require; +=head1 CREDITS - if ( $@ ) { - Catalyst::Exception->throw( - message => qq/Couldn't load plugin "$plugin", "$@"/ - ); - } +Andy Grundman - { - no strict 'refs'; - push @{"$class\::ISA"}, $plugin; - } - } -} +Andrew Ford -=back +Andrew Ruthven -=head1 LIMITATIONS +Autrijus Tang -mod_perl2 support is considered experimental and may contain bugs. +Christian Hansen -=head1 SUPPORT +Christopher Hicks -IRC: +Dan Sully - Join #catalyst on irc.perl.org. +Danijel Milicevic -Mailing-Lists: +David Naughton - http://lists.rawmode.org/mailman/listinfo/catalyst - http://lists.rawmode.org/mailman/listinfo/catalyst-dev +Gary Ashton Jones -Web: +Geoff Richards - http://catalyst.perl.org +Jesse Sheidlower -=head1 SEE ALSO +Jody Belka -=over 4 +Johan Lindstrom -=item L - The Catalyst Manual +Juan Camacho -=item L - Core Engine +Leon Brocard -=item L - The Log Class. +Marcus Ramberg -=item L - The Request Object +Matt S Trout -=item L - The Response Object +Sebastian Riedel -=item L - The test suite. +Tatsuhiko Miyagawa -=back +Ulf Edvinsson =head1 AUTHOR Sebastian Riedel, C -=head1 THANK YOU - -Andy Grundman, Andrew Ford, Andrew Ruthven, Autrijus Tang, Christian Hansen, -Christopher Hicks, Dan Sully, Danijel Milicevic, David Naughton, -Gary Ashton Jones, Geoff Richards, Jesse Sheidlower, Jody Belka, -Johan Lindstrom, Juan Camacho, Leon Brocard, Marcus Ramberg, -Tatsuhiko Miyagawa and all the others who've helped. - =head1 LICENSE This library is free software . You can redistribute it and/or modify it under