Merge 'trunk' into 'more_metaclass_compat'
Tomas Doran [Thu, 20 May 2010 20:31:35 +0000 (20:31 +0000)]
r13205@t0mlaptop (orig r13169):  t0m | 2010-04-19 03:40:24 +0100
Document the action config here, as people don't seem to find it and this may help..
r13206@t0mlaptop (orig r13170):  t0m | 2010-04-19 03:41:57 +0100
Bah, accidentally removed..
r13207@t0mlaptop (orig r13171):  t0m | 2010-04-19 08:22:49 +0100
Go away useless warning
r13213@t0mlaptop (orig r13177):  ajgb | 2010-04-21 12:10:51 +0100
Fix not stripping backslashes in DispatchType::Regex::uri_for_action
r15483@t0mlaptop (orig r13190):  rafl | 2010-04-28 23:54:04 +0100
Make sure path_to returns an instance of the right Path::Class class.
r15484@t0mlaptop (orig r13191):  edenc | 2010-04-29 00:29:02 +0100
minor documentation fix for handle_request
r15489@t0mlaptop (orig r13193):  rafl | 2010-05-03 00:16:25 +0100
Allow parameterized roles to be applied as plugins.
r15490@t0mlaptop (orig r13194):  t0m | 2010-05-03 00:27:43 +0100
Back out crazy heuristics
r15492@t0mlaptop (orig r13196):  rafl | 2010-05-03 00:44:30 +0100
Unbreak tests by actually adding the module they're supposed to test.
r15494@t0mlaptop (orig r13198):  rafl | 2010-05-03 01:51:43 +0100
Remove useless conditional.
r15515@t0mlaptop (orig r13219):  wreis | 2010-05-06 13:34:10 +0100
make uri_for a bit cleaner
r15516@t0mlaptop (orig r13220):  wreis | 2010-05-06 14:30:19 +0100
minor fix for Changes file | add me as a contributor
r15517@t0mlaptop (orig r13221):  rafl | 2010-05-07 22:11:10 +0100
Pass along options to load_class for plugins.
r15518@t0mlaptop (orig r13222):  rafl | 2010-05-07 22:48:51 +0100
Changelogging.
r15519@t0mlaptop (orig r13223):  rafl | 2010-05-07 23:06:26 +0100
Version 5.80023.
r15535@t0mlaptop (orig r13239):  ribasushi | 2010-05-12 12:48:40 +0100
Better stats API explanation (SpiceMan)
r15559@t0mlaptop (orig r13263):  t0m | 2010-05-15 10:42:58 +0100
 r13208@spaceinvaders (orig r13172):  t0m | 2010-04-19 09:54:56 +0200
 Branch to try and fix the request uri stuff.

 r13209@spaceinvaders (orig r13173):  t0m | 2010-04-19 09:58:37 +0200
 Just add comments to tests, no functional changes
 r13210@spaceinvaders (orig r13174):  t0m | 2010-04-19 09:59:14 +0200
 Get it mostly working, except uri_for is still buggered
 r15488@spaceinvaders (orig r13192):  t0m | 2010-05-03 00:26:22 +0200
 Revert to old behaviour, allow config for new behaviour. Config option name is rubbish, needs fixing
 r15532@spaceinvaders (orig r13236):  t0m | 2010-05-09 01:09:01 +0200
 I hate this name less. Others may feel differently
 r15556@spaceinvaders (orig r13260):  t0m | 2010-05-15 10:52:16 +0200
 Simplify madness some more, back to how it looked in the original fix_path_info_decoding branch so that we aren't using dodgy heuristics to determine the path. Alter the prepare_path tests so that they're testing the appropriate config option so that we now have tests for both code paths
 r15557@spaceinvaders (orig r13261):  t0m | 2010-05-15 11:20:16 +0200
 Add a pile of docs for the new use_request_uri_for_path setting
 r15558@spaceinvaders (orig r13262):  t0m | 2010-05-15 11:38:06 +0200
 Add recommendation

r15560@t0mlaptop (orig r13264):  t0m | 2010-05-15 10:55:07 +0100
Changelog, bump versions, add new contributor :)
r15567@t0mlaptop (orig r13271):  jhannah | 2010-05-19 23:36:21 +0100
We appear to have a bug where if lazy => 1 isn't set an exception
occurs.

r15575@t0mlaptop (orig r13279):  jhannah | 2010-05-20 20:46:31 +0100
Oops. I should have TODO'd this one.  rafl++

1  2 
lib/Catalyst.pm
t/lib/TestApp.pm

diff --combined lib/Catalyst.pm
@@@ -14,6 -14,7 +14,7 @@@ use Catalyst::Request::Upload
  use Catalyst::Response;
  use Catalyst::Utils;
  use Catalyst::Controller;
+ use Data::OptList;
  use Devel::InnerPackage ();
  use File::stat;
  use Module::Pluggable::Object ();
@@@ -78,7 -79,7 +79,7 @@@ __PACKAGE__->stats_class('Catalyst::Sta
  
  # Remember to update this in Catalyst::Runtime as well!
  
- our $VERSION = '5.80022';
+ our $VERSION = '5.80024';
  
  sub import {
      my ( $class, @arguments ) = @_;
@@@ -280,14 -281,15 +281,15 @@@ Specifies a comma-delimited list of lo
  
  =head2 -Stats
  
- Enables statistics collection and reporting. You can also force this setting
- from the system environment with CATALYST_STATS or <MYAPP>_STATS. The
- environment settings override the application, with <MYAPP>_STATS having the
- highest priority.
+ Enables statistics collection and reporting.
  
- e.g.
+    use Catalyst qw/-Stats=1/;
  
-    use Catalyst qw/-Stats=1/
+ You can also force this setting from the system environment with CATALYST_STATS
+ or <MYAPP>_STATS. The environment settings override the application, with
+ <MYAPP>_STATS having the highest priority.
+ Stats are also enabled if L<< debugging |/"-Debug" >> is enabled.
  
  =head1 METHODS
  
@@@ -1279,13 -1281,11 +1281,11 @@@ sub uri_for 
      carp "uri_for called with undef argument" if grep { ! defined $_ } @args;
      foreach my $arg (@args) {
          utf8::encode($arg) if utf8::is_utf8($arg);
-     }
-     s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args;
-     if (blessed $path) { # Action object only.
-         s|/|%2F|g for @args;
+         $arg =~ s/([^$URI::uric])/$URI::Escape::escapes{$1}/go;
      }
  
      if ( blessed($path) ) { # action object
+         s|/|%2F|g for @args;
          my $captures = [ map { s|/|%2F|g; $_; }
                          ( scalar @args && ref $args[0] eq 'ARRAY'
                           ? @{ shift(@args) }
          $path = '/' if $path eq '';
      }
  
-     undef($path) if (defined $path && $path eq '');
      unshift(@args, $path);
  
      unless (defined $path && $path =~ s!^/!!) { # in-place strip
@@@ -1890,7 -1888,7 +1888,7 @@@ namespaces
  
  sub get_actions { my $c = shift; $c->dispatcher->get_actions( $c, @_ ) }
  
- =head2 $c->handle_request( $class, @arguments )
+ =head2 $app->handle_request( @arguments )
  
  Called to handle each HTTP request.
  
@@@ -2408,6 -2406,10 +2406,6 @@@ sub setup_components 
          # we know M::P::O found a file on disk so this is safe
  
          Catalyst::Utils::ensure_class_loaded( $component, { ignore_loaded => 1 } );
 -
 -        # Needs to be done as soon as the component is loaded, as loading a sub-component
 -        # (next time round the loop) can cause us to get the wrong metaclass..
 -        $class->_controller_init_base_classes($component);
      }
  
      for my $component (@comps) {
              : $class->expand_component_module( $component, $config );
          for my $component (@expanded_components) {
              next if $comps{$component};
 -            $class->_controller_init_base_classes($component); # Also cover inner packages
              $class->components->{ $component } = $class->setup_component($component);
          }
      }
@@@ -2469,6 -2472,19 +2467,6 @@@ sub expand_component_module 
  
  =cut
  
 -# FIXME - Ugly, ugly hack to ensure the we force initialize non-moose base classes
 -#         nearest to Catalyst::Controller first, no matter what order stuff happens
 -#         to be loaded. There are TODO tests in Moose for this, see
 -#         f2391d17574eff81d911b97be15ea51080500003
 -sub _controller_init_base_classes {
 -    my ($app_class, $component) = @_;
 -    return unless $component->isa('Catalyst::Controller');
 -    foreach my $class ( reverse @{ mro::get_linear_isa($component) } ) {
 -        Moose::Meta::Class->initialize( $class )
 -            unless find_meta($class);
 -    }
 -}
 -
  sub setup_component {
      my( $class, $component ) = @_;
  
@@@ -2779,22 -2795,29 +2777,29 @@@ the plugin name does not begin with C<C
          my ( $class, $plugins ) = @_;
  
          $class->_plugins( {} ) unless $class->_plugins;
-         $plugins ||= [];
+         $plugins = Data::OptList::mkopt($plugins || []);
  
-         my @plugins = Catalyst::Utils::resolve_namespace($class . '::Plugin', 'Catalyst::Plugin', @$plugins);
+         my @plugins = map {
+             [ Catalyst::Utils::resolve_namespace(
+                   $class . '::Plugin',
+                   'Catalyst::Plugin', $_->[0]
+               ),
+               $_->[1],
+             ]
+          } @{ $plugins };
  
          for my $plugin ( reverse @plugins ) {
-             Class::MOP::load_class($plugin);
-             my $meta = find_meta($plugin);
+             Class::MOP::load_class($plugin->[0], $plugin->[1]);
+             my $meta = find_meta($plugin->[0]);
              next if $meta && $meta->isa('Moose::Meta::Role');
  
-             $class->_register_plugin($plugin);
+             $class->_register_plugin($plugin->[0]);
          }
  
          my @roles =
-             map { $_->name }
-             grep { $_ && blessed($_) && $_->isa('Moose::Meta::Role') }
-             map { find_meta($_) }
+             map  { $_->[0]->name, $_->[1] }
+             grep { blessed($_->[0]) && $_->[0]->isa('Moose::Meta::Role') }
+             map  { [find_meta($_->[0]), $_->[1]] }
              @plugins;
  
          Moose::Util::apply_all_roles(
  Returns an arrayref of the internal execution stack (actions that are
  currently executing).
  
+ =head2 $c->stats
+ Returns the current timing statistics object. By default Catalyst uses
+ L<Catalyst::Stats|Catalyst::Stats>, but can be set otherwise with
+ L<< stats_class|/"$c->stats_class" >>.
+ Even if L<< -Stats|/"-Stats" >> is not enabled, the stats object is still
+ available. By enabling it with C< $c->stats->enabled(1) >, it can be used to
+ profile explicitly, although MyApp.pm still won't profile nor output anything
+ by itself.
  =head2 $c->stats_class
  
- Returns or sets the stats (timing statistics) class.
+ Returns or sets the stats (timing statistics) class. L<Catalyst::Stats|Catalyst::Stats> is used by default.
  
  =head2 $c->use_stats
  
- Returns 1 when stats collection is enabled.  Stats collection is enabled
- when the -Stats options is set, debug is on or when the <MYAPP>_STATS
- environment variable is set.
+ Returns 1 when L<< stats collection|/"-Stats" >> is enabled.
  
  Note that this is a static method, not an accessor and should be overridden
  by declaring C<sub use_stats { 1 }> in your MyApp.pm, not by calling C<< $c->use_stats(1) >>.
@@@ -2914,6 -2946,12 +2928,12 @@@ to be shown in hit debug tables in the 
  
  =item *
  
+ C<use_request_uri_for_path> - Controlls if the C<REQUEST_URI> or C<PATH_INFO> environment
+ variable should be used for determining the request path. See L<Catalyst::Engine::CGI/PATH DECODING>
+ for more information.
+ =item *
  C<using_frontend_proxy> - See L</PROXY SUPPORT>.
  
  =back
@@@ -3143,6 -3181,8 +3163,8 @@@ random: Roland Lammel <lammel@cpan.org
  
  Robert Sedlacek C<< <rs@474.at> >>
  
+ SpiceMan: Marcel Montes
  sky: Arthur Bergman
  
  szbalint: Balint Szilakszi <szbalint@cpan.org>
@@@ -3157,6 -3197,8 +3179,8 @@@ Will Hawes C<info@whawes.co.uk
  
  willert: Sebastian Willert <willert@cpan.org>
  
+ wreis: Wallace Reis <wallace@reis.org.br>
  Yuval Kogman, C<nothingmuch@woobling.org>
  
  =head1 LICENSE
diff --combined t/lib/TestApp.pm
@@@ -16,15 -16,34 +16,39 @@@ use Catalyst::Utils
  use Moose;
  use namespace::autoclean;
  
+ # -----------
+ # t/aggregate/unit_core_ctx_attr.t pukes until lazy is true
+ package Greeting;
+ use Moose;
+ sub hello_notlazy { 'hello there' }
+ sub hello_lazy    { 'hello there' }
+ package TestApp;
+ has 'my_greeting_obj_notlazy' => (
+    is      => 'ro',
+    isa     => 'Greeting',
+    default => sub { Greeting->new() },
+    handles => [ qw( hello_notlazy ) ],
+    lazy    => 0,
+ );
+ has 'my_greeting_obj_lazy' => (
+    is      => 'ro',
+    isa     => 'Greeting',
+    default => sub { Greeting->new() },
+    handles => [ qw( hello_lazy ) ],
+    lazy    => 1,
+ );
+ # -----------
  our $VERSION = '0.01';
  
- TestApp->config( name => 'TestApp', root => '/some/dir' );
+ TestApp->config( name => 'TestApp', root => '/some/dir', use_request_uri_for_path => 1 );
  
 +# Test bug found when re-adjusting the metaclass compat code in Moose
 +# in 292360. Test added to Moose in 4b760d6, but leave this attribute
 +# above ->setup so we have some generated methods to be double sure.
 +has an_attribute_before_we_change_base_classes => ( is => 'ro');
 +
  if ($::setup_leakchecker && eval { Class::MOP::load_class('CatalystX::LeakChecker'); 1 }) {
      with 'CatalystX::LeakChecker';