Merge 'trunk' into 'namespace_handling_refactor'
Rafael Kitover [Thu, 25 Jun 2009 01:05:10 +0000 (01:05 +0000)]
r5375@hlagh (orig r10489):  caelum | 2009-06-09 05:46:43 -0700
added test for ->view() with one view not returning a blessed instance
r5452@hlagh (orig r10494):  t0m | 2009-06-10 08:21:32 -0700
Add conflict line to Makefile.PL for Component::ACCEPT_CONTEXT

r5453@hlagh (orig r10497):  rafl | 2009-06-10 13:16:25 -0700
This is version 5.80.
r5454@hlagh (orig r10498):  lukes | 2009-06-10 14:20:57 -0700
prevent encoding plus signs in uri_for args
r5455@hlagh (orig r10499):  dandv | 2009-06-10 23:59:56 -0700
Fixed typos, added parameters for content_like

r5456@hlagh (orig r10500):  dandv | 2009-06-11 00:10:46 -0700
Fixed run-on sentence in COPYRIGHT and s/program/library/

r5457@hlagh (orig r10501):  dandv | 2009-06-11 00:27:56 -0700
Cosmetic: removed trailing whitespace

r5458@hlagh (orig r10502):  caelum | 2009-06-11 05:42:00 -0700
fix $c->view() bug hopefully
r5540@hlagh (orig r10551):  hobbs | 2009-06-16 11:57:17 -0700
Doc patch warning of C<< $c->req->param >>'s fuzzy behavior.

r5541@hlagh (orig r10574):  t0m | 2009-06-17 09:03:51 -0700
Back out 10498 and 10097
r5542@hlagh (orig r10575):  jshirley | 2009-06-17 09:18:29 -0700
Adding failing test for uri_for behaviors
r5543@hlagh (orig r10576):  jshirley | 2009-06-17 09:19:53 -0700
Fixing test count
r5544@hlagh (orig r10579):  t0m | 2009-06-17 18:21:17 -0700
Test dinks
r5545@hlagh (orig r10581):  caelum | 2009-06-17 21:13:07 -0700
slight test fix, but test is still probably wrong
r5554@hlagh (orig r10583):  zarquon | 2009-06-18 03:47:36 -0700
attempt to test for the infamous repeating path-uri-escape evil
r5579@hlagh (orig r10594):  t0m | 2009-06-19 13:35:41 -0700
Just initialize a logger which only logs fatal errors, no mock needed
r5580@hlagh (orig r10595):  t0m | 2009-06-19 13:39:19 -0700
Remove Test::MockObject
r5581@hlagh (orig r10596):  t0m | 2009-06-19 13:39:58 -0700
Remove Test::MockObject
r5582@hlagh (orig r10597):  t0m | 2009-06-19 13:41:46 -0700
Remove MockObject
r5583@hlagh (orig r10598):  t0m | 2009-06-19 13:44:15 -0700
1 more MockObject removal
r5584@hlagh (orig r10599):  t0m | 2009-06-19 13:46:45 -0700
Remove MockObject from Makefile.PL
r5596@hlagh (orig r10605):  t0m | 2009-06-20 16:23:19 -0700
Re-add lukes specific regression test from r10498
r5597@hlagh (orig r10606):  t0m | 2009-06-20 16:25:31 -0700
Update test to be TODO, and note this case used to fail on 5.7
r5600@hlagh (orig r10609):  zarquon | 2009-06-20 17:31:39 -0700
this test is not for the regression which you seek
r5670@hlagh (orig r10612):  t0m | 2009-06-22 09:31:09 -0700
Test closures in config in the testapp. Makes everything go bang.
r5671@hlagh (orig r10613):  t0m | 2009-06-22 09:37:26 -0700
Use merge_hashes rather than dclone
r5672@hlagh (orig r10614):  t0m | 2009-06-22 11:06:48 -0700
Fix uri_for_action test by just reverting to as it was in 5.8003 before various lame tests were added and mismerged

1  2 
Changes
Makefile.PL
lib/Catalyst.pm
lib/Catalyst/Controller.pm
lib/Catalyst/Dispatcher.pm
lib/Catalyst/Utils.pm

diff --combined Changes
+++ b/Changes
@@@ -1,10 -1,16 +1,22 @@@
  # This file documents the revision history for Perl extension Catalyst.
  
-         - Use ~ as prefix for plugins or action classes which are located in 
-           MyApp::Plugin / MyApp::Action (mo)
-         - Controller methods without attributes are now considered actions if 
-           they are specified in config->{action(s)} (mo)
+   Bug fixes:
+         -  Revert change to URL encode things passed into $c->uri_for
+            Args and CaptureArgs as this causes breakage to pre-existing
+            applications.
+         -  Remove use of Test::MockObject as it doesn't install from CPAN
+            in some environments.
+         -  Remove use of dclone to deep copy configs and replace with
+            Catalyst::Utils::merge_hashes which has the same effect, of
+            ensuring child classes don't inherit their parent's config,
+            except works correctly with closures.
++  New features:
++        -  Use ~ as prefix for plugins or action classes which are located in 
++           MyApp::Plugin / MyApp::Action (mo)
++        -  Controller methods without attributes are now considered actions if 
++           they are specified in config->{action(s)} (mo)
 +
  5.80005 2009-06-06 14:40:00
  
    Behaviour changes:
diff --combined Makefile.PL
@@@ -34,14 -34,10 +34,11 @@@ requires 'Tree::Simple::Visitor::FindBy
  requires 'URI' => '1.35';
  requires 'Text::Balanced'; # core in 5.8.x but mentioned for completeness
  requires 'MRO::Compat';
 +requires 'String::RewritePrefix' => '0.004'; # Catalyst::Utils::resolve_namespace
  
  recommends 'B::Hooks::OP::Check::StashChange';
  
  test_requires 'Class::Data::Inheritable';
- test_requires 'Test::MockObject' => '1.07'; # Newish (hah, 2006!) version to
-                                             # hopefully avoid broken distro
-                                             # packages (RT#46104)
  test_requires 'Test::Exception';
  
  # aggregate tests if AGGREGATE_TESTS is set and a recent Test::Aggregate is available
@@@ -110,6 -106,7 +107,7 @@@ EO
  # NOTE - This is the version number of the _incompatible_ code,
  #        not the version number of the fixed version.
  my %conflicts = (
+     'Catalyst::Component::ACCEPT_CONTEXT' => '0.06',
      'Catalyst::Plugin::ENV' => '9999', # This plugin is just stupid, full stop
                                         # should have been a core fix.
      'Catalyst::Plugin::Unicode::Encoding' => '0.2',
diff --combined lib/Catalyst.pm
@@@ -493,8 -493,13 +493,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 ) . ')::';
      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
@@@ -558,7 -563,9 +563,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;
  }
  
@@@ -1192,7 -1199,7 +1199,7 @@@ sub uri_for 
        ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} );
  
      carp "uri_for called with undef argument" if grep { ! defined $_ } @args;
-     s/([^A-Za-z0-9\-_.!~*'()])/$URI::Escape::escapes{$1}/go for @args;
+     s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args;
  
      unshift(@args, $path);
  
                $_ = "$_";
                utf8::encode( $_ ) if utf8::is_utf8($_);
                # using the URI::Escape pattern here so utf8 chars survive
-               s/([^A-Za-z0-9\-_.!~*'()])/$URI::Escape::escapes{$1}/go;
+               s/([^A-Za-z0-9\-_.!~*'() ])/$URI::Escape::escapes{$1}/go;
                s/ /+/g;
                "${key}=$_"; } ( ref $val eq 'ARRAY' ? @$val : $val ));
        } @keys);
@@@ -2502,9 -2509,9 +2509,9 @@@ the plugin name does not begin with C<C
  
          $class->_plugins( {} ) unless $class->_plugins;
          $plugins ||= [];
 -
 -        my @plugins = map { s/\A\+// ? $_ : "Catalyst::Plugin::$_" } @$plugins;
 +                
 +        my @plugins = Catalyst::Utils::resolve_namespace($class . '::Plugin', 'Catalyst::Plugin', @$plugins);
-         
          for my $plugin ( reverse @plugins ) {
              Class::MOP::load_class($plugin);
              my $meta = find_meta($plugin);
              grep { $_ && blessed($_) && $_->isa('Moose::Meta::Role') }
              map { find_meta($_) }
              @plugins;
-          
          Moose::Util::apply_all_roles(
              $class => @roles
          ) if @roles;
@@@ -2777,7 -2784,7 +2784,7 @@@ willert: Sebastian Willert <willert@cpa
  
  =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
@@@ -178,28 -178,13 +178,28 @@@ around path_prefix => sub 
  sub get_action_methods {
      my $self = shift;
      my $meta = find_meta($self);
 -    confess("Metaclass for " . ref($meta) ." for " . $meta->name
 -        . " cannot support register_actions.")
 -        unless $meta->can('get_nearest_methods_with_attributes');
 +    confess("Metaclass for "
 +          . ref($meta) . " for "
 +          . $meta->name
 +          . " cannot support register_actions." )
 +      unless $meta->can('get_nearest_methods_with_attributes');
      my @methods = $meta->get_nearest_methods_with_attributes;
 +
 +    # actions specified via config are also action_methods
 +    push(
 +        @methods,
 +        map {
 +            $meta->get_method($_)
 +              || confess( 'Action "' 
 +                  . $_
 +                  . '" is not available from controller '
 +                  . ( ref $self ) )
 +          } keys %{ $self->_controller_actions }
 +    ) if ( ref $self );
      return @methods;
  }
  
 +
  sub register_actions {
      my ( $self, $c ) = @_;
      $self->register_action_methods( $c, $self->get_action_methods );
@@@ -214,6 -199,7 +214,6 @@@ sub register_action_methods 
      foreach my $method (@methods) {
          my $name = $method->name;
          my $attributes = $method->attributes;
 -        next unless $attributes;
          my $attrs = $self->_parse_attrs( $c, $name, @{ $attributes } );
          if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
              $c->log->debug( 'Bad action definition "'
@@@ -390,8 -376,9 +390,8 @@@ sub _parse_PathPrefix_attr 
  
  sub _parse_ActionClass_attr {
      my ( $self, $c, $name, $value ) = @_;
 -    unless ( $value =~ s/^\+// ) {
 -      $value = join('::', $self->_action_class, $value );
 -    }
 +    my $appname = $self->_application;
 +    $value = Catalyst::Utils::resolve_namespace($appname . '::Action', $self->_action_class, $value);
      return ( 'ActionClass', $value );
  }
  
@@@ -488,7 -475,7 +488,7 @@@ Catalyst Contributors, see Catalyst.p
  
  =head1 COPYRIGHT
  
- This program is free software, you can redistribute it and/or modify
+ This library is free software. You can redistribute it and/or modify
  it under the same terms as Perl itself.
  
  =cut
@@@ -61,7 -61,7 +61,7 @@@ application based on the attributes yo
  
  =head1 METHODS
  
- =head2 new 
+ =head2 new
  
  Construct a new dispatcher.
  
@@@ -411,7 -411,7 +411,7 @@@ sub get_action 
      return $self->_action_hash->{"${namespace}/${name}"};
  }
  
- =head2 $self->get_action_by_path( $path ); 
+ =head2 $self->get_action_by_path( $path );
  
  Returns the named action by its full private path.
  
@@@ -640,11 -640,12 +640,11 @@@ sub _load_dispatch_types 
      my ( $self, @types ) = @_;
  
      my @loaded;
 -
      # Preload action types
      for my $type (@types) {
 -        my $class =
 -          ( $type =~ /^\+(.*)$/ ) ? $1 : "Catalyst::DispatchType::${type}";
 -
 +        # first param is undef because we cannot get the appclass
 +        my $class = Catalyst::Utils::resolve_namespace(undef, 'Catalyst::DispatchType', $type);
 +        
          eval { Class::MOP::load_class($class) };
          Catalyst::Exception->throw( message => qq/Couldn't load "$class"/ )
            if $@;
  
  Get the DispatchType object of the relevant type, i.e. passing C<$type> of
  C<Chained> would return a L<Catalyst::DispatchType::Chained> object (assuming
- of course it's being used.) 
+ of course it's being used.)
  
  =cut
  
  sub dispatch_type {
      my ($self, $name) = @_;
 -
 -    unless ($name =~ s/^\+//) {
 -        $name = "Catalyst::DispatchType::" . $name;
 -    }
 +    
 +    # first param is undef because we cannot get the appclass
 +    $name = Catalyst::Utils::resolve_namespace(undef, 'Catalyst::DispatchType', $name);
  
      for (@{ $self->_dispatch_types }) {
          return $_ if ref($_) eq $name;
@@@ -690,12 -692,12 +690,12 @@@ use Moose
  # See also t/lib/TestApp/Plugin/AddDispatchTypes.pm
  
  # Alias _method_name to method_name, add a before modifier to warn..
- foreach my $public_method_name (qw/ 
-         tree 
-         dispatch_types 
-         registered_dispatch_types 
-         method_action_class  
-         action_hash 
+ foreach my $public_method_name (qw/
+         tree
+         dispatch_types
+         registered_dispatch_types
+         method_action_class
+         action_hash
          container_hash
      /) {
      my $private_method_name = '_' . $public_method_name;
@@@ -729,7 -731,7 +729,7 @@@ Catalyst Contributors, see Catalyst.p
  
  =head1 COPYRIGHT
  
- This program 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
diff --combined lib/Catalyst/Utils.pm
@@@ -9,8 -9,6 +9,8 @@@ use URI
  use Carp qw/croak/;
  use Cwd;
  
 +use String::RewritePrefix;
 +
  use namespace::clean;
  
  =head1 NAME
@@@ -23,7 -21,7 +23,7 @@@ See L<Catalyst>
  
  =head1 DESCRIPTION
  
- Catalyst Utilities. 
+ Catalyst Utilities.
  
  =head1 METHODS
  
@@@ -299,7 -297,7 +299,7 @@@ sub merge_hashes 
      my ( $lefthash, $righthash ) = @_;
  
      return $lefthash unless defined $righthash;
-     
      my %merged = %$lefthash;
      for my $key ( keys %$righthash ) {
          my $right_ref = ( ref $righthash->{ $key } || '' ) eq 'HASH';
              $merged{ $key } = $righthash->{ $key };
          }
      }
-     
      return \%merged;
  }
  
@@@ -348,10 -346,10 +348,10 @@@ All you need to get this work, is
  
  1) Install Term::Size::Any, or
  
- 2) Export $COLUMNS from your shell. 
+ 2) Export $COLUMNS from your shell.
  
  (Warning to bash users: 'echo $COLUMNS' may be showing you the bash
- variable, not $ENV{COLUMNS}. 'export COLUMNS=$COLUMNS' and you should see 
+ variable, not $ENV{COLUMNS}. 'export COLUMNS=$COLUMNS' and you should see
  that 'env' now lists COLUMNS.)
  
  As last resort, default value of 80 chars will be used.
@@@ -379,35 -377,13 +379,35 @@@ sub term_width 
      return $_term_width = $width;
  }
  
 +
 +=head2 resolve_namespace
 +
 +Method which adds the namespace for plugins and actions.
 +
 +  __PACKAGE__->setup(qw(MyPlugin));
 +  
 +  # will load Catalyst::Plugin::MyPlugin
 +
 +=cut
 +
 +
 +sub resolve_namespace {
 +    my $appnamespace = shift;
 +    my $namespace = shift;
 +    my @classes = @_;
 +    return String::RewritePrefix->rewrite(
 +        { '' => $namespace.'::', '+' => '', '~' => $appnamespace . '::' }, @classes,
 +      );
 +}
 +
 +
  =head1 AUTHORS
  
  Catalyst Contributors, see Catalyst.pm
  
  =head1 COPYRIGHT
  
- This program 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