X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=a7519840460a3787617e17d51bf0ccaa4ace6b96;hp=75652fb5771a3b1ce229bddf816605520deb1598;hb=79f5d5718d885ee1c3f288159a31562f9cf5b02f;hpb=b553e30c12cade787e4c26ca54f19983577bdb30 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 75652fb..a751984 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1,11 +1,14 @@ package Catalyst; use Moose; +use Moose::Meta::Class (); extends 'Catalyst::Component'; use Moose::Util qw/find_meta/; use bytes; -use Scope::Upper (); +use B::Hooks::EndOfScope (); use Catalyst::Exception; +use Catalyst::Exception::Detach; +use Catalyst::Exception::Go; use Catalyst::Log; use Catalyst::Request; use Catalyst::Request::Upload; @@ -57,8 +60,8 @@ sub finalize_output { shift->finalize_body(@_) }; our $COUNT = 1; our $START = time; our $RECURSION = 1000; -our $DETACH = "catalyst_detach\n"; -our $GO = "catalyst_go\n"; +our $DETACH = Catalyst::Exception::Detach->new; +our $GO = Catalyst::Exception::Go->new; #I imagine that very few of these really need to be class variables. if any. #maybe we should just make them attributes with a default? @@ -75,7 +78,7 @@ __PACKAGE__->stats_class('Catalyst::Stats'); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.80002'; +our $VERSION = '5.80005'; { my $dev_version = $VERSION =~ /_\d{2}$/; @@ -492,8 +495,13 @@ sub clear_errors { $c->error(0); } -# search components given a name and some prefixes sub _comp_search_prefixes { + my $c = shift; + return map $c->components->{ $_ }, $c->_comp_names_search_prefixes(@_); +} + +# search components given a name and some prefixes +sub _comp_names_search_prefixes { my ( $c, $name, @prefixes ) = @_; my $appclass = ref $c || $c; my $filter = "^${appclass}::(" . join( '|', @prefixes ) . ')::'; @@ -509,18 +517,18 @@ sub _comp_search_prefixes { my $query = ref $name ? $name : qr/^$name$/i; my @result = grep { $eligible{$_} =~ m{$query} } keys %eligible; - return map { $c->components->{ $_ } } @result if @result; + return @result if @result; # if we were given a regexp to search against, we're done. return if ref $name; # regexp fallback $query = qr/$name/i; - @result = map { $c->components->{ $_ } } grep { $eligible{ $_ } =~ m{$query} } keys %eligible; + @result = grep { $eligible{ $_ } =~ m{$query} } keys %eligible; # no results? try against full names if( !@result ) { - @result = map { $c->components->{ $_ } } grep { m{$query} } keys %eligible; + @result = grep { m{$query} } keys %eligible; } # don't warn if we didn't find any results, it just might not exist @@ -557,7 +565,9 @@ sub _comp_names { my $filter = "^${appclass}::(" . join( '|', @prefixes ) . ')::'; - my @names = map { s{$filter}{}; $_; } $c->_comp_search_prefixes( undef, @prefixes ); + my @names = map { s{$filter}{}; $_; } + $c->_comp_names_search_prefixes( undef, @prefixes ); + return @names; } @@ -903,7 +913,9 @@ Returns the engine instance. See L. =head2 $c->path_to(@path) Merges C<@path> with C<< $c->config->{home} >> and returns a -L object. +L object. Note you can usually use this object as +a filename, but sometimes you will have to explicitly stringify it +yourself by calling the C<<->stringify>> method. For example: @@ -1099,10 +1111,17 @@ EOF # Note however that we have to do the work on scope end, so that method # modifiers work correctly in MyApp (as you have to call setup _before_ # applying modifiers). - Scope::Upper::reap(sub { + B::Hooks::EndOfScope::on_scope_end { + return if $@; my $meta = Class::MOP::get_metaclass_by_name($class); + if ( $meta->is_immutable && ! { $meta->immutable_options }->{inline_constructor} ) { + warn "You made your application class ($class) immutable, " + . "but did not inline the constructor.\n" + . "This will break catalyst, please pass " + . "(replace_constructor => 1) when making your class immutable.\n"; + } $meta->make_immutable(replace_constructor => 1) unless $meta->is_immutable; - }, Scope::Upper::SCOPE(1)); + }; $class->setup_finalize; } @@ -1153,7 +1172,7 @@ using C<< $c->req->captures >>. $c->uri_for($c->action, $c->req->captures); # For the Foo action in the Bar controller - $c->uri_for($c->controller->('Bar')->action_for('Foo'), $c->req->captures); + $c->uri_for($c->controller('Bar')->action_for('Foo'), $c->req->captures); =back @@ -1492,10 +1511,10 @@ sub execute { my $last = pop( @{ $c->stack } ); if ( my $error = $@ ) { - if ( !ref($error) and $error eq $DETACH ) { + if ( blessed($error) and $error->isa('Catalyst::Exception::Detach') ) { die $DETACH if($c->depth > 1); } - elsif ( !ref($error) and $error eq $GO ) { + elsif ( blessed($error) and $error->isa('Catalyst::Exception::Go') ) { die $GO if($c->depth > 0); } else { @@ -2168,8 +2187,7 @@ sub setup_components { sub _controller_init_base_classes { my ($app_class, $component) = @_; foreach my $class ( reverse @{ mro::get_linear_isa($component) } ) { - next unless $class =~ /^$app_class/; - Moose->init_meta( for_class => $class ) + Moose::Meta::Class->initialize( $class ) unless find_meta($class); } } @@ -2473,9 +2491,6 @@ the plugin name does not begin with C. my ( $proto, $plugin, $instant ) = @_; my $class = ref $proto || $proto; - # no ignore_loaded here, the plugin may already have been - # defined in memory and we don't want to error on "no file" if so - Class::MOP::load_class( $plugin ); $proto->_plugins->{$plugin} = 1; @@ -2496,14 +2511,26 @@ the plugin name does not begin with C. $class->_plugins( {} ) unless $class->_plugins; $plugins ||= []; - for my $plugin ( reverse @$plugins ) { + + my @plugins = Catalyst::Utils::resolve_namespace($class . '::Plugin', 'Catalyst::Plugin', @$plugins); - unless ( $plugin =~ s/\A\+// ) { - $plugin = "Catalyst::Plugin::$plugin"; - } + for my $plugin ( reverse @plugins ) { + Class::MOP::load_class($plugin); + my $meta = find_meta($plugin); + next if $meta && $meta->isa('Moose::Meta::Role'); $class->_register_plugin($plugin); } + + my @roles = + map { $_->name } + grep { $_ && blessed($_) && $_->isa('Moose::Meta::Role') } + map { find_meta($_) } + @plugins; + + Moose::Util::apply_all_roles( + $class => @roles + ) if @roles; } } @@ -2695,6 +2722,8 @@ dkubb: Dan Kubb Drew Taylor +dwc: Daniel Westermann-Clark + esskar: Sascha Kiefer fireartist: Carl Franks @@ -2743,6 +2772,8 @@ phaylon: Robert Sedlacek rafl: Florian Ragwitz +random: Roland Lammel + sky: Arthur Bergman the_jester: Jesse Sheidlower @@ -2755,7 +2786,7 @@ willert: Sebastian Willert =head1 LICENSE -This library is free software, you can redistribute it and/or modify it under +This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself. =cut