Merge 'trunk' into 'psgi'
Tomas Doran [Mon, 16 Aug 2010 18:31:59 +0000 (18:31 +0000)]
r15645@spaceinvaders (orig r13336):  t0m | 2010-06-10 10:54:11 +0100
Fix $self vs $class, davewood++
r15660@spaceinvaders (orig r13351):  rainboxx | 2010-06-15 12:53:05 +0100
Applied doc patches that might help to figure out how to receive component's config values.
r15672@spaceinvaders (orig r13363):  jester | 2010-06-22 21:47:45 +0100
Fixed typo

r15674@spaceinvaders (orig r13365):  bricas | 2010-06-24 13:52:20 +0100
add typo fix to Changes
r15689@spaceinvaders (orig r13380):  arcanez | 2010-07-03 01:04:07 +0100
remove extra '
r15716@spaceinvaders (orig r13407):  hobbs | 2010-07-09 10:40:44 +0100
Try harder to make finalize_error encoding-safe.

r15750@spaceinvaders (orig r13441):  t0m | 2010-07-28 22:39:41 +0100
 r15666@spaceinvaders (orig r13357):  jnapiorkowski | 2010-06-16 20:12:46 +0100
 new branch
 r15667@spaceinvaders (orig r13358):  jnapiorkowski | 2010-06-16 20:55:08 +0100
 broke out and documented action_class method
 r15749@spaceinvaders (orig r13440):  t0m | 2010-07-28 22:39:32 +0100
 Changelog

r15755@spaceinvaders (orig r13446):  t0m | 2010-07-28 23:00:14 +0100
 r15662@spaceinvaders (orig r13353):  t0m | 2010-06-15 22:15:31 +0100
 Branch for rt58057

 r15663@spaceinvaders (orig r13354):  t0m | 2010-06-15 22:17:32 +0100
 Commit standalone test, test which makes the TestApp blow up and the nasty workaround
 r15726@spaceinvaders (orig r13417):  t0m | 2010-07-23 13:29:21 +0100
 I know hobbs has a patch to add a load of these, but we should at least add (es)
 r15753@spaceinvaders (orig r13444):  t0m | 2010-07-28 22:56:25 +0100
 Entirely the wrong branch, idiot. Remove r13417
 r15754@spaceinvaders (orig r13445):  t0m | 2010-07-28 23:00:05 +0100
 Document the horrible, changelog. I'm going to merge this and fix a real issue as I don't have time to fuck around inside Moose right now and it's been waiting way too long already

r15756@spaceinvaders (orig r13447):  t0m | 2010-07-28 23:26:21 +0100
Fix TODO tests.
r15757@spaceinvaders (orig r13448):  t0m | 2010-07-28 23:26:31 +0100
Whitespace
r15760@spaceinvaders (orig r13451):  t0m | 2010-07-28 23:53:56 +0100
 r13095@spaceinvaders (orig r13059):  caelum | 2010-03-22 09:27:45 +0000
 branch to fix running under CGI on IIS
 r13097@spaceinvaders (orig r13061):  caelum | 2010-03-22 10:40:52 +0000
 fix for CGI on IIS
 r15759@spaceinvaders (orig r13450):  t0m | 2010-07-28 23:52:15 +0100
 Changelog

r15764@spaceinvaders (orig r13455):  t0m | 2010-07-29 01:58:32 +0100
Version 5.80025
r15766@spaceinvaders (orig r13457):  zarquon | 2010-07-29 11:26:51 +0100
advertise Catalyst::Plugin::SmartURI
r15767@spaceinvaders (orig r13458):  zarquon | 2010-07-29 11:28:09 +0100
stupid typo
r15777@spaceinvaders (orig r13468):  lukes | 2010-08-04 15:25:18 +0100
moved component name sort that happens in setup_components to locate_components to allow methods to wrap around locate_components
r15779@spaceinvaders (orig r13470):  rbuels | 2010-08-04 21:04:14 +0100
don't load Catalyst::Exception in Utils.pm BEGIN, because some Scripts::* load Utils before MyApp.pm, meaning that ::Exception::CATALYST_EXCEPTION_CLASS in MyApp.pm will not be respected

12 files changed:
Changes
lib/Catalyst.pm
lib/Catalyst/Component.pm
lib/Catalyst/Controller.pm
lib/Catalyst/Engine.pm
lib/Catalyst/Runtime.pm
lib/Catalyst/Script/Server.pm
lib/Catalyst/Utils.pm
t/custom_exception_class_simple.t
t/lib/TestApp/Controller/Moose/NoAttributes.pm [new file with mode: 0644]
t/lib/TestAppClassExceptionSimpleTest.pm
t/unit_core_methodattributes_method_metaclass_on_subclasses.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 25bcbc3..f17bba2 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,12 +1,26 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+5.80025 2010-07-29 01:50:00
+
+ New features:
+  - An 'action_class' method has been added to Catalyst::Controller to
+    allow controller base classes, roles or traits
+    (e.g. Catalyst::Controller::ActionRole) to more easily override
+    the default action creation.
+
  Bug fixes:
   - Fix the --mech and --mechanize options to the myapp_create.pl script
     to operate correctly by fixing the options passed down into the script.
+  - Fix controllers with no method attributes (where the action definitions
+    are entirely contained in config). RT#58057
+  - Fix running as a CGI under IIS at non-root locations.
 
  Documentation:
   - Fix missing - in the docs when describing the --mechanize option at one
     point.
+  - Explained the common practice how to access the component's config
+    values.
+  - Fixed typo in Catalyst/Script/Server.pm (RT #58474)
 
 5.80024 2010-05-15 11:55:44
 
index c0683b8..b9cf01c 100644 (file)
@@ -81,7 +81,7 @@ __PACKAGE__->stats_class('Catalyst::Stats');
 
 # Remember to update this in Catalyst::Runtime as well!
 
-our $VERSION = '5.80024';
+our $VERSION = '5.80025';
 
 sub import {
     my ( $class, @arguments ) = @_;
@@ -894,7 +894,7 @@ component is constructed.
 For example:
 
     MyApp->config({ 'Model::Foo' => { bar => 'baz', overrides => 'me' } });
-    MyApp::Model::Foo->config({ quux => 'frob', 'overrides => 'this' });
+    MyApp::Model::Foo->config({ quux => 'frob', overrides => 'this' });
 
 will mean that C<MyApp::Model::Foo> receives the following data when
 constructed:
@@ -905,6 +905,21 @@ constructed:
         overrides => 'me',
     });
 
+It's common practice to use a Moose attribute
+on the receiving component to access the config value.
+
+    package MyApp::Model::Foo;
+
+    use Moose;
+
+    # this attr will receive 'baz' at construction time
+    has 'bar' => ( 
+        is  => 'rw',
+        isa => 'Str',
+    );
+
+You can then get the value 'baz' by calling $c->model('Foo')->bar
+
 =cut
 
 around config => sub {
@@ -1229,7 +1244,9 @@ sub setup_finalize {
 
 Constructs an absolute L<URI> object based on the application root, the
 provided path, and the additional arguments and query parameters provided.
-When used as a string, provides a textual URI.
+When used as a string, provides a textual URI.  If you need more flexibility
+than this (i.e. the option to provide relative URIs etc.) see
+L<Catalyst::Plugin::SmartURI>.
 
 If no arguments are provided, the URI for the current action is returned.
 To return the current action and also provide @args, use
@@ -2401,8 +2418,7 @@ sub setup_components {
 
     my $config  = $class->config->{ setup_components };
 
-    my @comps = sort { length $a <=> length $b }
-                $class->locate_components($config);
+    my @comps = $class->locate_components($config);
     my %comps = map { $_ => 1 } @comps;
 
     my $deprecatedcatalyst_component_names = grep { /::[CMV]::/ } @comps;
@@ -2457,7 +2473,8 @@ sub locate_components {
         %$config
     );
 
-    my @comps = $locator->plugins;
+    # XXX think about ditching this sort entirely
+    my @comps = sort { length $a <=> length $b } $locator->plugins;
 
     return @comps;
 }
@@ -3146,6 +3163,8 @@ wreis: Wallace Reis <wallace@reis.org.br>
 
 Yuval Kogman, C<nothingmuch@woobling.org>
 
+rainboxx: Matthias Dietrich, C<perl@rainboxx.de>
+
 =head1 LICENSE
 
 This library is free software. You can redistribute it and/or modify it under
index 1b2d462..28da155 100644 (file)
@@ -170,7 +170,7 @@ to be stored in the application's component hash.
 
 C<< my $component_instance = $component->COMPONENT($app, $arguments); >>
 
-If this method is present (as it is on all Catalyst::Component subclasses,
+If this method is present (as it is on all Catalyst::Component subclasses),
 it is called by Catalyst during setup_components with the application class
 as $app and any config entry on the application for this component (for example,
 in the case of MyApp::Controller::Foo this would be
@@ -185,7 +185,7 @@ something like this:
 
   sub COMPONENT {
       my ($class, $app, $args) = @_;
-      $args = $self->merge_config_hashes($self->config, $args);
+      $args = $class->merge_config_hashes($class->config, $args);
       return $class->new($app, $args);
   }
 
@@ -200,6 +200,12 @@ key value pair, or you can specify a hashref. In either case the keys
 will be merged with any existing config settings. Each component in
 a Catalyst application has its own config hash.
 
+The component's config hash is merged with any config entry on the
+application for this component and passed to C<new()> (as mentioned
+above at L</COMPONENT>). The common practice to access the merged
+config is to use a Moose attribute for each config entry on the
+receiving component.
+
 =head2 $c->process()
 
 This is the default method called on a Catalyst component in the dispatcher.
index fbc8768..b1c4c94 100644 (file)
@@ -225,7 +225,9 @@ sub register_action_methods {
 
     foreach my $method (@methods) {
         my $name = $method->name;
-        my $attributes = $method->attributes;
+        # Horrible hack! All method metaclasses should have an attributes
+        # method, core Moose bug - see r13354.
+        my $attributes = $method->can('attributes') ? $method->attributes : [];
         my $attrs = $self->_parse_attrs( $c, $name, @{ $attributes } );
         if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
             $c->log->debug( 'Bad action definition "'
@@ -248,16 +250,25 @@ sub register_action_methods {
     }
 }
 
-sub create_action {
+sub action_class {
     my $self = shift;
     my %args = @_;
 
     my $class = (exists $args{attributes}{ActionClass}
-                    ? $args{attributes}{ActionClass}[0]
-                    : $self->_action_class);
+        ? $args{attributes}{ActionClass}[0]
+        : $self->_action_class);
+
     Class::MOP::load_class($class);
+    return $class;
+}
+
+sub create_action {
+    my $self = shift;
+    my %args = @_;
 
+    my $class = $self->action_class(%args);
     my $action_args = $self->config->{action_args};
+
     my %extra_args = (
         %{ $action_args->{'*'}           || {} },
         %{ $action_args->{ $args{name} } || {} },
@@ -529,6 +540,11 @@ action methods for this package.
 Creates action objects for a set of action methods using C< create_action >,
 and registers them with the dispatcher.
 
+=head2 $self->action_class(%args)
+
+Used when a controller is creating an action to determine the correct base
+action class to use.
+
 =head2 $self->create_action(%args)
 
 Called with a hash of data to be use for construction of a new
index 29a2188..1fdbfeb 100644 (file)
@@ -14,6 +14,8 @@ use Moose::Util::TypeConstraints;
 use Plack::Loader;
 use Plack::Middleware::Conditional;
 use Plack::Middleware::ReverseProxy;
+use Encode ();
+use utf8;
 
 use namespace::clean -except => 'meta';
 
@@ -155,6 +157,14 @@ sub finalize_error {
 
     $c->res->content_type('text/html; charset=utf-8');
     my $name = ref($c)->config->{name} || join(' ', split('::', ref $c));
+    
+    # Prevent Catalyst::Plugin::Unicode::Encoding from running.
+    # This is a little nasty, but it's the best way to be clean whether or
+    # not the user has an encoding plugin.
+
+    if ($c->can('encoding')) {
+      $c->{encoding} = '';
+    }
 
     my ( $title, $error, $infos );
     if ( $c->debug ) {
@@ -303,11 +313,12 @@ sub finalize_error {
 </body>
 </html>
 
-
     # Trick IE. Old versions of IE would display their own error page instead
     # of ours if we'd give it less than 512 bytes.
     $c->res->{body} .= ( ' ' x 512 );
 
+    $c->res->{body} = Encode::encode("UTF-8", $c->res->{body});
+
     # Return 500
     $c->res->status(500);
 }
index 0c37ca2..3925404 100644 (file)
@@ -7,7 +7,7 @@ BEGIN { require 5.008004; }
 
 # Remember to update this in Catalyst as well!
 
-our $VERSION = '5.80024';
+our $VERSION = '5.80025';
 
 =head1 NAME
 
index 003a57e..22ed5b6 100644 (file)
@@ -236,7 +236,7 @@ Catalyst::Script::Server - Catalyst test server
                       a restart when modified
                       (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
    --rdir --restart_directory  the directory to search for
-                      modified files, can be set mulitple times
+                      modified files, can be set multiple times
                       (defaults to '[SCRIPT_DIR]/..')
    --sym  --follow_symlinks   follow symlinks in search directories
                       (defaults to false. this is a no-op on Win32)
index 53bf795..d72441e 100644 (file)
@@ -1,7 +1,6 @@
 package Catalyst::Utils;
 
 use strict;
-use Catalyst::Exception;
 use File::Spec;
 use HTTP::Request;
 use Path::Class;
@@ -140,6 +139,13 @@ sub class2tempdir {
         eval { $tmpdir->mkpath };
 
         if ($@) {
+            # don't load Catalyst::Exception as a BEGIN in Utils,
+            # because Utils often gets loaded before MyApp.pm, and if
+            # Catalyst::Exception is loaded before MyApp.pm, it does
+            # not honor setting
+            # $Catalyst::Exception::CATALYST_EXCEPTION_CLASS in
+            # MyApp.pm
+            require Catalyst::Exception;
             Catalyst::Exception->throw(
                 message => qq/Couldn't create tmpdir '$tmpdir', "$@"/ );
         }
index 8c8c0c2..24983fa 100644 (file)
@@ -4,9 +4,17 @@ use strict;
 use warnings;
 use FindBin qw/$Bin/;
 use lib "$Bin/lib";
-use Test::More tests => 1;
+use Test::More tests => 2;
 use Test::Exception;
 
 lives_ok {
     require TestAppClassExceptionSimpleTest;
 } 'Can load application';
+
+
+lives_ok {
+    Catalyst::Exception->throw
+} 'throw is properly stubbed out';
+
+
+
diff --git a/t/lib/TestApp/Controller/Moose/NoAttributes.pm b/t/lib/TestApp/Controller/Moose/NoAttributes.pm
new file mode 100644 (file)
index 0000000..7770816
--- /dev/null
@@ -0,0 +1,16 @@
+package TestApp::Controller::Moose::NoAttributes;
+use Moose;
+extends qw/Catalyst::Controller/;
+
+__PACKAGE__->config(
+   actions => {
+       test => { Local => undef }
+   }
+);
+
+sub test {
+}
+
+no Moose;
+1;
+
index aef61be..cc0ba44 100644 (file)
@@ -10,6 +10,8 @@ package TestAppClassExceptionSimpleTest;
 use strict;
 use warnings;
 
+use Catalyst::Utils; #< some of the scripts use Catalyst::Utils before MyApp.pm
+
 BEGIN { $Catalyst::Exception::CATALYST_EXCEPTION_CLASS = 'TestAppClassExceptionSimpleTest::Exception'; }
 
 use Catalyst;
diff --git a/t/unit_core_methodattributes_method_metaclass_on_subclasses.t b/t/unit_core_methodattributes_method_metaclass_on_subclasses.t
new file mode 100644 (file)
index 0000000..b6f5054
--- /dev/null
@@ -0,0 +1,30 @@
+use strict;
+use Test::More;
+
+{
+    package NoAttributes::CT;
+    use Moose;
+    BEGIN { extends qw/Catalyst::Controller/; };
+
+    sub test {}
+}
+{
+    package NoAttributes::RT;
+    use Moose;
+    extends qw/Catalyst::Controller/;
+
+    sub test {}
+}
+
+foreach my $class (qw/ CT RT /) {
+    my $class_name = 'NoAttributes::' . $class;
+    my $meta = $class_name->meta;
+    my $meth = $meta->find_method_by_name('test');
+    {
+        local $TODO = "Known MX::MethodAttributes issue";
+        ok $meth->can('attributes'), 'method metaclass has ->attributes method for ' . $class;;
+    }
+}
+
+done_testing;
+