use strict;
use base 'Catalyst::Component';
use bytes;
-use UNIVERSAL::require;
use Catalyst::Exception;
use Catalyst::Log;
use Catalyst::Request;
require Module::Pluggable::Fast;
-# Helper script generation
-our $CATALYST_SCRIPT_GEN = 27;
-
__PACKAGE__->mk_classdata($_)
for qw/components arguments dispatcher engine log dispatcher_class
engine_class context_class request_class response_class setup_finished/;
### in lib/MyApp.pm
use Catalyst qw/-Debug/; # include plugins here as well
- ### In libMyApp/Controller/Root.pm (autocreated)
+ ### In lib/MyApp/Controller/Root.pm (autocreated)
sub foo : Global { # called for /foo, /foo/1, /foo/1/2, etc.
my ( $self, $c, @args ) = @_; # args are qw/1 2/ for /foo/1/2
$c->stash->{template} = 'foo.tt'; # set the template
if (@_) {
my $stash = @_ > 1 ? {@_} : $_[0];
croak('stash takes a hash or hashref') unless ref $stash;
- while ( my ( $key, $val ) = each %$stash ) {
- $c->{stash}->{$key} = $val;
+ foreach my $key ( keys %$stash ) {
+ $c->{stash}->{$key} = $stash->{$key};
}
}
return $c->{stash};
Overload to enable debug messages (same as -Debug option).
+Note that this is a static method, not an accessor and should be overloaded
+by declaring "sub debug { 1 }" in your MyApp.pm, not by calling $c->debug(1).
+
=cut
sub debug { 0 }
}
}
- $class->log->warn(
- <<"EOF") if ( $ENV{CATALYST_SCRIPT_GEN} && ( $ENV{CATALYST_SCRIPT_GEN} < $Catalyst::CATALYST_SCRIPT_GEN ) );
+ eval { require Catalyst::Devel; };
+ if( !$@ && $ENV{CATALYST_SCRIPT_GEN} && ( $ENV{CATALYST_SCRIPT_GEN} < $Catalyst::Devel::CATALYST_SCRIPT_GEN ) ) {
+ $class->log->warn(<<"EOF");
You are running an old script!
Please update by running (this will overwrite existing files):
or (this will not overwrite existing files):
catalyst.pl -scripts $class
EOF
-
+ }
+
if ( $class->debug ) {
my @plugins = ();
$dispatcher = $class->dispatcher_class;
}
- $dispatcher->require;
-
- if ($@) {
- Catalyst::Exception->throw(
- message => qq/Couldn't load dispatcher "$dispatcher", "$@"/ );
+ unless (Class::Inspector->loaded($dispatcher)) {
+ require Class::Inspector->filename($dispatcher);
}
# dispatcher instance
$engine = $class->engine_class;
}
- $engine->require;
-
- if ($@) {
- Catalyst::Exception->throw( message =>
-qq/Couldn't load engine "$engine" (maybe you forgot to install it?), "$@"/
- );
+ unless (Class::Inspector->loaded($engine)) {
+ require Class::Inspector->filename($engine);
}
# check for old engines that are no longer compatible
my ( $proto, $plugin, $instant ) = @_;
my $class = ref $proto || $proto;
- $plugin->require;
-
- if ( my $error = $@ ) {
- my $type = $instant ? "instant " : '';
- Catalyst::Exception->throw(
- message => qq/Couldn't load ${type}plugin "$plugin", $error/ );
+ unless (Class::Inspector->loaded($plugin)) {
+ require Class::Inspector->filename($plugin);
}
$proto->_plugins->{$plugin} = 1;