Merge branch 'expand_modules'
Florian Ragwitz [Thu, 4 Feb 2010 05:50:05 +0000 (05:50 +0000)]
expand_modules:
Allow models and components to specify the names of any components they generate
Branching to allow components to specify any modules they may have created

Changes
lib/Catalyst.pm
lib/Catalyst/Component.pm
lib/Catalyst/Engine/CGI.pm
lib/Catalyst/Runtime.pm
t/aggregate/live_component_controller_action_chained.t
t/aggregate/unit_core_component.t
t/aggregate/unit_core_engine_cgi-prepare_path.t
t/aggregate/unit_core_uri_for.t

diff --git a/Changes b/Changes
index 12cc5f2..b0a04fb 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,30 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+5.80019 2010-01-29 01:04:09
+
+  Bug fixed:
+   - Calls to $c->uri_for with private paths as strings (e.g.
+     $c->uri_for('controller/action', 'arg1', 'arg2') ) no longer have
+     / encoded to %2F. This is due to $c->uri_for('static', 'css/foo', $bar)
+     which should not be encoded.
+     Calls with an action object (rather than a string), or uri_for action
+     will still encode / in args and captures to %2F
+
+   - The above noted / => %2F encoding in uri_for_action or uri_for with
+     an action object has been fixed to not just encode the first slash in
+     any set of args/captures.
+
+   - nginx and lighttpd FCGI requests with URI encoded sections as the first
+     path part have been fixed to operate correctly.
+
+   - A source of bogus warnings in Catalyst::Component::BUILDARGS has been
+     removed.
+
+  Documentation:
+   - Improve the documentation about -Home and how Catalyst finds the home path
+     for applications.
+   - Various minor typo fixes.
+
   New features:
    - Allow passing additional arguments to action constructors.
 
@@ -12,6 +37,7 @@
 
   Documentation:
    - Clarify that uri_for_action works on private paths, with example.
+   - Clarify documentation about debug
 
   Deprecations:
    - Saying use Catalyst::Test; (without an application name or () to stop
index cd40aef..24e45bd 100644 (file)
@@ -78,7 +78,7 @@ __PACKAGE__->stats_class('Catalyst::Stats');
 
 # Remember to update this in Catalyst::Runtime as well!
 
-our $VERSION = '5.80018';
+our $VERSION = '5.80019';
 $VERSION = eval $VERSION;
 
 sub import {
@@ -243,6 +243,9 @@ environment with CATALYST_DEBUG or <MYAPP>_DEBUG. The environment
 settings override the application, with <MYAPP>_DEBUG having the highest
 priority.
 
+This sets the log level to 'debug' and enables full debug output on the
+error screen. If you only want the latter, see L<< $c->debug >>.
+
 =head2 -Engine
 
 Forces Catalyst to use a specific engine. Omit the
@@ -262,6 +265,14 @@ is replaced with the uppercased name of your application, any "::" in
 the name will be replaced with underscores, e.g. MyApp::Web should use
 MYAPP_WEB_HOME. If both variables are set, the MYAPP_HOME one will be used.
 
+If none of these are set, Catalyst will attempt to automatically detect the
+home directory. If you are working in a development envirnoment, Catalyst
+will try and find the directory containing either Makefile.PL, Build.PL or
+dist.ini. If the application has been installed into the system (i.e.
+you have done C<make install>), then Catalyst will use the path to your
+application module, without the .pm extension (ie, /foo/MyApp if your
+application was installed at /foo/MyApp.pm)
+
 =head2 -Log
 
     use Catalyst '-Log=warn,fatal,error';
@@ -923,6 +934,8 @@ You can enable debug mode in several ways:
 
 =back
 
+The first three also set the log level to 'debug'.
+
 Calling C<< $c->debug(1) >> has no effect.
 
 =cut
@@ -1246,8 +1259,19 @@ sub uri_for {
         $path .= '/';
     }
 
+    undef($path) if (defined $path && $path eq '');
+
+    my $params =
+      ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} );
+
+    carp "uri_for called with undef argument" if grep { ! defined $_ } @args;
+    s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args;
+    if (blessed $path) { # Action object only.
+        s|/|%2F|g for @args;
+    }
+
     if ( blessed($path) ) { # action object
-        my $captures = [ map { s|/|%2F|; $_; }
+        my $captures = [ map { s|/|%2F|g; $_; }
                         ( scalar @args && ref $args[0] eq 'ARRAY'
                          ? @{ shift(@args) }
                          : ()) ];
@@ -1261,15 +1285,6 @@ sub uri_for {
         $path = '/' if $path eq '';
     }
 
-    undef($path) if (defined $path && $path eq '');
-
-    my $params =
-      ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} );
-
-    carp "uri_for called with undef argument" if grep { ! defined $_ } @args;
-    s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args;
-    s|/|%2F| for @args;
-
     unshift(@args, $path);
 
     unless (defined $path && $path =~ s!^/!!) { # in-place strip
index bccd3f9..1b2d462 100644 (file)
@@ -85,8 +85,6 @@ sub BUILDARGS {
         } elsif (Class::MOP::is_class_loaded($_[0]) &&
                 $_[0]->isa('Catalyst') && ref($_[1]) eq 'HASH') {
             $args = $_[1];
-        } elsif ($_[0] eq $_[1]) {
-            $args = $_[1];
         } else {
             $args = +{ @_ };
         }
index 1443a2f..4c0d9b9 100644 (file)
@@ -168,7 +168,8 @@ sub prepare_path {
             if (substr($req_uri, 0, 1) ne '/') {
                 my ($match) = $req_uri =~ m|^([^/]+)|;
                 my ($path_info_part) = $path_info =~ m|^(.*?\Q$match\E)|;
-                substr($req_uri, 0, length($match), $path_info_part);
+                substr($req_uri, 0, length($match), $path_info_part)
+                    if $path_info_part;
             }
             $path_info = $req_uri;
         }
index c65bfbb..b1bbaae 100644 (file)
@@ -7,7 +7,7 @@ BEGIN { require 5.008004; }
 
 # Remember to update this in Catalyst as well!
 
-our $VERSION='5.80018';
+our $VERSION='5.80019';
 
 $VERSION = eval $VERSION;
 
index fef26ef..b0be898 100644 (file)
@@ -1085,7 +1085,8 @@ sub run_tests {
             'request ' . $path . ' ok');
         # Just check that the path matches, as who the hell knows or cares
         # where the app is based (live tests etc)
-        ok( index($content, $path) > 1, 'uri can round trip through uri_for' );
+        ok( index($content, $path) > 1, 'uri can round trip through uri_for' )
+            or diag("Expected $path, got $content");
     }
 }
 
index 9fb578a..69ac6c0 100644 (file)
@@ -1,4 +1,4 @@
-use Test::More tests => 23;
+use Test::More tests => 22;
 use strict;
 use warnings;
 
@@ -91,18 +91,3 @@ is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok');
     is_deeply($args, [qw/foo3 bar3/], 'args passed to ACCEPT_CONTEXT ok');
 }
 
-# BUILDARGS logic
-{
-    {
-        package MyController;
-        @MyController::ISA = ('Catalyst::Controller');
-    }
-    my $warning;
-    local $SIG{__WARN__} = sub {
-        $warning = shift;
-        diag($warning);
-    };
-    my $controller = MyController->new('MyApp', undef);
-    like( $warning, qr/uninitialized value in string eq/, "no warning for == comparison");
-
-}
index f8b08ef..76bad62 100644 (file)
@@ -62,6 +62,31 @@ use Catalyst::Engine::CGI;
     is ''.$r->base, 'http://www.foo.com/';
 }
 
+# nginx example from espent with path /"foo"
+{
+    my $r = get_req (
+        PATH_INFO => '"foo"',
+        SCRIPT_NAME => '/',
+        REQUEST_URI => '/%22foo%22',
+    );
+    is ''.$r->path, '%22foo%22';
+    is ''.$r->uri, 'http://www.foo.com/%22foo%22';
+    is ''.$r->base, 'http://www.foo.com/';
+}
+
+# nginx example from espent with path /"foo" and the app based at /oslobilder
+{
+    my $r = get_req (
+        PATH_INFO => 'oslobilder/"foo"',
+        SCRIPT_NAME => '/oslobilder/',
+        REQUEST_URI => '/oslobilder/%22foo%22',
+    );
+    is ''.$r->path, '%22foo%22';
+    is ''.$r->uri, 'http://www.foo.com/oslobilder/%22foo%22';
+    is ''.$r->base, 'http://www.foo.com/oslobilder/';
+}
+
+
 
 
 # FIXME - Test proxy logic
index 170e91b..da40bea 100644 (file)
@@ -1,16 +1,17 @@
 use strict;
 use warnings;
-
-use Test::More tests => 20;
+use FindBin qw/$Bin/;
+use lib "$FindBin::Bin/../lib";
+use Test::More;
 use URI;
 
-use_ok('Catalyst');
+use_ok('TestApp');
 
 my $request = Catalyst::Request->new( {
                 base => URI->new('http://127.0.0.1/foo')
               } );
-
-my $context = Catalyst->new( {
+my $dispatcher = TestApp->dispatcher;
+my $context = TestApp->new( {
                 request => $request,
                 namespace => 'yada',
               } );
@@ -143,3 +144,21 @@ TODO: {
     is_deeply($query_params_base, $query_params_test,
               "uri_for() doesn't mess up query parameter hash in the caller");
 }
+
+
+{
+    my $path_action = $dispatcher->get_action_by_path(
+                       '/action/path/six'
+                     );
+
+    # 5.80018 is only encoding the first of the / in the arg.
+    is(
+        Catalyst::uri_for( $context, $path_action, 'foo/bar/baz' )->as_string,
+        'http://127.0.0.1/action/path/six/foo%2Fbar%2Fbaz',
+        'Escape all forward slashes in args as %2F'
+    );
+}
+
+
+done_testing;
+