use Moose::Meta::Class ();
extends 'Catalyst::Component';
use Moose::Util qw/find_meta/;
-use B::Hooks::EndOfScope ();
+use namespace::clean -except => 'meta';
use Catalyst::Exception;
use Catalyst::Exception::Detach;
use Catalyst::Exception::Go;
use utf8;
use Carp qw/croak carp shortmess/;
use Try::Tiny;
+use Safe::Isa;
use Plack::Middleware::Conditional;
use Plack::Middleware::ReverseProxy;
use Plack::Middleware::IIS6ScriptNameFix;
+use Plack::Middleware::IIS7KeepAliveFix;
use Plack::Middleware::LighttpdScriptNameFix;
BEGIN { require 5.008003; }
is => 'rw',
default => sub {
my $self = shift;
- my %p = ( _log => $self->log );
- $p{_uploadtmp} = $self->_uploadtmp if $self->_has_uploadtmp;
- $self->request_class->new(\%p);
+ $self->request_class->new($self->_build_request_constructor_args);
},
lazy => 1,
);
+sub _build_request_constructor_args {
+ my $self = shift;
+ my %p = ( _log => $self->log );
+ $p{_uploadtmp} = $self->_uploadtmp if $self->_has_uploadtmp;
+ \%p;
+}
+
has response => (
is => 'rw',
default => sub {
my $self = shift;
- $self->response_class->new({ _log => $self->log });
+ $self->response_class->new($self->_build_response_constructor_args);
},
lazy => 1,
);
+sub _build_response_constructor_args {
+ my $self = shift;
+ { _log => $self->log };
+}
+
has namespace => (is => 'rw');
sub depth { scalar @{ shift->stack || [] }; }
# Remember to update this in Catalyst::Runtime as well!
-our $VERSION = '5.90011';
+our $VERSION = '5.90017';
sub import {
my ( $class, @arguments ) = @_;
}
$caller->arguments( [@arguments] );
+
+ # FIXME
+ # what is this for?
+ # we call setup_home on import AND on ->setup
+ # is there a reason for it?
+ # anyway there is no point for setup_home without setup_config() so...
+ $caller->setup_config;
$caller->setup_home;
}
sub _application { $_[0] }
+=encoding UTF-8
+
=head1 NAME
Catalyst - The Elegant MVC Web Application Framework
if (
$class->debug and
- my $comps = $class->container->get_all_components($class)
+ my $comps = $class->container->get_all_component_services($class)
) {
- my $column_width = Catalyst::Utils::term_width() - 8 - 9;
- my $t = Text::SimpleTable->new( [ $column_width, 'Class' ], [ 8, 'Type' ] );
- $t->row( $_ => ref($comps->{$_}) ? 'instance' : 'class' ) for keys %$comps;
+ my $column_width = Catalyst::Utils::term_width() - 16 - 9;
+ my $t = Text::SimpleTable->new( [ $column_width, 'Class' ], [ 16, 'Lifecycle' ] );
+
+ # FIXME
+ # I don't really know what we're going to show here
+ while (my ($class, $info) = each %$comps) {
+ my $lifecycle = $info->{backcompat_service}
+ ? $info->{backcompat_service}->lifecycle
+ : $info->{service}->lifecycle
+ ;
+ $t->row( $class, $lifecycle );
+ }
$class->log->debug( "Loaded components:\n" . $t->draw . "\n" );
}
$class->log->info("$name powered by Catalyst $Catalyst::VERSION");
}
- # Make sure that the application class becomes immutable at this point,
- B::Hooks::EndOfScope::on_scope_end {
- return if $@;
- my $meta = Class::MOP::get_metaclass_by_name($class);
- if (
- $meta->is_immutable
- && ! { $meta->immutable_options }->{replace_constructor}
- && (
- $class->isa('Class::Accessor::Fast')
- || $class->isa('Class::Accessor')
- )
- ) {
- warn "You made your application class ($class) immutable, "
- . "but did not inline the\nconstructor. "
- . "This will break catalyst, as your app \@ISA "
- . "Class::Accessor(::Fast)?\nPlease pass "
- . "(replace_constructor => 1)\nwhen making your class immutable.\n";
- }
- $meta->make_immutable(
- replace_constructor => 1,
- ) unless $meta->is_immutable;
- };
-
if ($class->config->{case_sensitive}) {
$class->log->warn($class . "->config->{case_sensitive} is set.");
$class->log->warn("This setting is deprecated and planned to be removed in Catalyst 5.81.");
sub uri_for {
my ( $c, $path, @args ) = @_;
- if (blessed($path) && $path->isa('Catalyst::Controller')) {
+ if ( $path->$_isa('Catalyst::Controller') ) {
$path = $path->path_prefix;
$path =~ s{/+\z}{};
$path .= '/';
$arg =~ s/([^$URI::uric])/$URI::Escape::escapes{$1}/go;
}
- if ( blessed($path) ) { # action object
+ if ( $path->$_isa('Catalyst::Action') ) { # action object
s|/|%2F|g for @args;
my $captures = [ map { s|/|%2F|g; $_; }
( scalar @args && ref $args[0] eq 'ARRAY'
sub components {
my ( $class, $comps ) = @_;
+ # FIXME
+ # this is very wrong
# people create components calling this sub directly, before setup
+ # also, $class->log doesn't work before setup_log
$class->setup_config unless $class->container;
my $container = $class->container;
if ( $comps ) {
+ $class->log->warn(q{You are adding components using Catalyst's components method.});
+ $class->log->warn(q{This behaviour is deprecated, please read});
+ $class->log->warn(q{Catalyst::IOC::Container's documentation for better ways to do that.});
$container->add_component( $_ ) for keys %$comps;
}
$c->finalize_error;
}
- $c->finalize_headers;
+ $c->finalize_headers unless $c->response->finalized_headers;
# HEAD request
if ( $c->request->method eq 'HEAD' ) {
$c->finalize_cookies;
- $c->engine->finalize_headers( $c, @_ );
+ $c->response->finalize_headers();
# Done
$response->finalized_headers(1);
my $uploadtmp = $class->config->{uploadtmp};
my $c = $class->context_class->new({ $uploadtmp ? (_uploadtmp => $uploadtmp) : ()});
+ $c->response->_context($c);
+
#surely this is not the most efficient way to do things...
$c->stats($class->stats_class->new)->enable($c->use_stats);
if ( $c->debug || $c->config->{enable_catalyst_header} ) {
sub run {
my $app = shift;
+ $app->_make_immutable_if_needed;
$app->engine_loader->needs_psgi_engine_compat_hack ?
$app->engine->run($app, @_) :
$app->engine->run( $app, $app->_finalized_psgi_app, @_ );
}
+sub _make_immutable_if_needed {
+ my $class = shift;
+ my $meta = Class::MOP::get_metaclass_by_name($class);
+ my $isa_ca = $class->isa('Class::Accessor::Fast') || $class->isa('Class::Accessor');
+ if (
+ $meta->is_immutable
+ && ! { $meta->immutable_options }->{replace_constructor}
+ && $isa_ca
+ ) {
+ warn("You made your application class ($class) immutable, "
+ . "but did not inline the\nconstructor. "
+ . "This will break catalyst, as your app \@ISA "
+ . "Class::Accessor(::Fast)?\nPlease pass "
+ . "(replace_constructor => 1)\nwhen making your class immutable.\n");
+ }
+ unless ($meta->is_immutable) {
+ # XXX - FIXME warning here as you should make your app immutable yourself.
+ $meta->make_immutable(
+ replace_constructor => 1,
+ );
+ }
+}
+
=head2 $c->set_action( $action, $code, $namespace, $attrs )
Sets an action in a given namespace.
$container_class = Class::MOP::load_first_existing_class("${class}::Container", 'Catalyst::IOC::Container');
}
- my $container = $container_class->new( %args, application_name => "$class", name => "$class" );
+ my $container = $container_class->new( %args, name => $class );
$class->container($container);
my $config = $container->resolve( service => 'config' );
# IIS versions
$psgi_app = Plack::Middleware::IIS6ScriptNameFix->wrap($psgi_app);
+ # And another IIS issue, this time with IIS7.
+ $psgi_app = Plack::Middleware::Conditional->wrap(
+ $psgi_app,
+ builder => sub { Plack::Middleware::IIS7KeepAliveFix->wrap($_[0]) },
+ condition => sub {
+ my ($env) = @_;
+ return $env->{SERVER_SOFTWARE} && $env->{SERVER_SOFTWARE} =~ m!IIS/7\.[0-9]!;
+ },
+ );
+
return $psgi_app;
}
=cut
sub setup_home {
- my ( $class, $home ) = @_;
+ my ( $class, $home_flag ) = @_;
- if ( my $env = Catalyst::Utils::env_value( $class, 'HOME' ) ) {
- $home = $env;
- }
-
- $home ||= Catalyst::Utils::home($class);
+ my $home = $class->container->resolve(
+ service => 'home',
+ parameters => {
+ home_flag => $home_flag
+ },
+ );
if ($home) {
#I remember recently being scolded for assigning config values like this
$class->config->{home} ||= $home;
- $class->config->{root} ||= Path::Class::Dir->new($home)->subdir('root');
+ $class->config->{root} ||= $class->container->resolve(service => 'root_dir');
}
}
Class::MOP::load_class( $plugin );
$class->log->warn( "$plugin inherits from 'Catalyst::Component' - this is deprecated and will not work in 5.81" )
if $plugin->isa( 'Catalyst::Component' );
- $proto->_plugins->{$plugin} = 1;
- unless ($instant) {
+ my $plugin_meta = Moose::Meta::Class->create($plugin);
+ if (!$plugin_meta->has_method('new')
+ && ( $plugin->isa('Class::Accessor::Fast') || $plugin->isa('Class::Accessor') ) ) {
+ $plugin_meta->add_method('new', Moose::Object->meta->get_method('new'))
+ }
+ if (!$instant && !$proto->_plugins->{$plugin}) {
my $meta = Class::MOP::get_metaclass_by_name($class);
$meta->superclasses($plugin, $meta->superclasses);
}
+ $proto->_plugins->{$plugin} = 1;
return $class;
}