Merge 'trunk' into 'Catalyst-Test-base-href'
Tomas Doran [Thu, 26 Aug 2010 00:18:07 +0000 (00:18 +0000)]
r15777@t0mlaptop (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@t0mlaptop (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
r15823@t0mlaptop (orig r13513):  dduncan | 2010-08-22 04:25:42 +0100
C-R-5-8 : Makefile.PL : remove bogus comment
r15824@t0mlaptop (orig r13514):  ferz | 2010-08-22 15:03:36 +0100
Discovered some inconsistency in precedence behavior of chained actions.

r15825@t0mlaptop (orig r13515):  ferz | 2010-08-22 16:04:58 +0100
Checks for any action now.

r15826@t0mlaptop (orig r13516):  bricas | 2010-08-23 18:55:43 +0100
Fix two warnings:
 - Fix warning about "excludes" during role application
 - Fix warning from MooseX::Getopt regarding duplicate "help" aliases

r15830@t0mlaptop (orig r13520):  hobbs | 2010-08-25 02:31:50 +0100
Add the app for ChainedActionsApp test. It's still failing, but differently now...

r15838@t0mlaptop (orig r13528):  t0m | 2010-08-25 14:46:22 +0100
Fix bug with parse_on_demand
r15839@t0mlaptop (orig r13529):  t0m | 2010-08-25 14:47:01 +0100
Back out 13528, cocked that up.
r15840@t0mlaptop (orig r13530):  t0m | 2010-08-25 14:47:23 +0100
Fix bug with parse_on_demand (take 2)
r15844@t0mlaptop (orig r13534):  t0m | 2010-08-25 23:53:20 +0100
Fix RT#59738, show_internal_actions produces warnings in debug mode
r15845@t0mlaptop (orig r13535):  t0m | 2010-08-26 00:07:21 +0100
Fix test output, as per RT#56590
r15846@t0mlaptop (orig r13536):  t0m | 2010-08-26 00:14:42 +0100
Update changelog
r15847@t0mlaptop (orig r13537):  t0m | 2010-08-26 00:17:50 +0100
Test::Aggregate does not like __END__
r15848@t0mlaptop (orig r13538):  t0m | 2010-08-26 00:26:14 +0100
No passing TODOs
r15849@t0mlaptop (orig r13539):  t0m | 2010-08-26 00:31:03 +0100
Omit the run method for scripts which new Pod::Coverage finds
r15850@t0mlaptop (orig r13540):  t0m | 2010-08-26 00:39:56 +0100
No idea why but lack of this causes a void context warning when run under the test harness
r15851@t0mlaptop (orig r13541):  t0m | 2010-08-26 01:01:20 +0100
Unify options, get rid of -h which only worked on the CGI script anyway (-h is host in ::Server). This technically breaks back-compat slightly, but for the command line options for help in the script you never run from command line anyway, I don't care
r15852@t0mlaptop (orig r13542):  t0m | 2010-08-26 01:08:24 +0100
Rename test, to merge

19 files changed:
Changes
Makefile.PL
lib/Catalyst.pm
lib/Catalyst/Script/CGI.pm
lib/Catalyst/Script/Server.pm
lib/Catalyst/ScriptRole.pm
lib/Catalyst/Utils.pm
t/aggregate/live__component_controller_action_chained2.t [new file with mode: 0644]
t/aggregate/unit_core_script_help.t
t/aggregate/unit_core_script_test.t
t/author/podcoverage.t
t/custom_exception_class_simple.t
t/lib/ChainedActionsApp.pm [new file with mode: 0644]
t/lib/ChainedActionsApp/Controller/Root.pm [new file with mode: 0644]
t/lib/TestAppClassExceptionSimpleTest.pm
t/lib/TestAppShowInternalActions.pm [new file with mode: 0644]
t/lib/TestAppShowInternalActions/Controller/Root.pm [new file with mode: 0644]
t/live_show_internal_actions_warnings.t [new file with mode: 0644]
t/unit_core_methodattributes_method_metaclass_on_subclasses.t

diff --git a/Changes b/Changes
index f17bba2..ce7606b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,34 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+ Bug fixes:
+  - Fix so that CATALYST_EXCEPTION_CLASS in MyApp is always respected by
+    not loading Catalyst::Exception in Utils.pm BEGIN, because some Scripts::*
+    load Utils before MyApp.pm
+
+  - Fix warnings with new Moose versions about "excludes" during role
+    application
+
+  - Fix warning from MooseX::Getopt regarding duplicate "help" aliases.
+
+  - parse_on_demand fixed when used in conjunction with debug mode.
+    A regression was introduced in 5.80022 which would cause the body
+    to always be parsed for logging at the end of the request when in
+    debug mode. This has been fixed so that if the body has not been parsed
+    by the time the request is logged, then the body is omitted.
+
+  - Fix show_internal_actions config setting producing warnings in debug
+    mode (RT#59738)
+
+ Refactoring:
+   - moved component name sort that happens in setup_components to
+     locate_components to allow methods to wrap around locate_components
+
+ Documentation:
+    - Fix some typos
+
+    - Advertise Catalyst::Plugin::SmartURI
+
+
 5.80025 2010-07-29 01:50:00
 
  New features:
@@ -14,6 +43,8 @@
   - 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.
+  - Fix warning about "excludes" during role application
+  - Fix warning from MooseX::Getopt regarding duplicate "help" aliases
 
  Documentation:
   - Fix missing - in the docs when describing the --mechanize option at one
index 0d021ce..47e26c0 100644 (file)
@@ -47,7 +47,7 @@ requires 'URI' => '1.35';
 requires 'Task::Weaken';
 requires 'Text::Balanced'; # core in 5.8.x but mentioned for completeness
 requires 'MRO::Compat';
-requires 'MooseX::Getopt' => '0.25';
+requires 'MooseX::Getopt' => '0.30';
 requires 'MooseX::Types';
 requires 'MooseX::Types::Common::Numeric';
 requires 'String::RewritePrefix' => '0.004'; # Catalyst::Utils::resolve_namespace
@@ -66,7 +66,7 @@ else {
         grep { $_ ne 't/aggregate.t' }
         map  { glob } qw[t/*.t t/aggregate/*.t];
 }
-author_requires 'CatalystX::LeakChecker', '0.05'; # Skipped if this isn't installed
+author_requires 'CatalystX::LeakChecker', '0.05';
 author_requires 'File::Copy::Recursive'; # For http server test
 
 author_tests 't/author';
index 02c8b71..56ed57f 100644 (file)
@@ -1701,7 +1701,7 @@ sub _stats_start_execute {
         my $parent = $c->stack->[-1];
 
         # forward, locate the caller
-        if ( exists $c->counter->{"$parent"} ) {
+        if ( defined $parent && exists $c->counter->{"$parent"} ) {
             $c->stats->profile(
                 begin  => $action,
                 parent => "$parent" . $c->counter->{"$parent"},
@@ -2150,7 +2150,7 @@ sub log_request {
         $c->log->debug("Query keywords are: $keywords");
     }
 
-    $c->log_request_parameters( query => $request->query_parameters, body => $request->body_parameters );
+    $c->log_request_parameters( query => $request->query_parameters, $request->_has_body ? (body => $request->body_parameters) : () );
 
     $c->log_request_uploads($request);
 }
@@ -2407,8 +2407,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;
@@ -2463,7 +2462,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;
 }
index e80a5f7..60392f5 100644 (file)
@@ -16,7 +16,7 @@ Catalyst::Script::CGI - The CGI Catalyst Script
   myapp_cgi.pl [options]
 
   Options:
-  -h     --help           display this help and exits
+  -?     --help           display this help and exits
 
 =head1 DESCRIPTION
 
index 45156e3..bb4c2a5 100644 (file)
@@ -13,8 +13,6 @@ use namespace::autoclean;
 
 with 'Catalyst::ScriptRole';
 
-__PACKAGE__->meta->get_attribute('help')->cmd_aliases('?');
-
 has debug => (
     traits        => [qw(Getopt)],
     cmd_aliases   => 'd',
index 535ed3d..7ae3d7d 100644 (file)
@@ -6,7 +6,7 @@ use MooseX::Getopt;
 use namespace::autoclean;
 
 with 'MooseX::Getopt' => {
-    excludes => [qw/
+    -excludes => [qw/
         _getopt_spec_warnings
         _getopt_spec_exception
         _getopt_full_usage
@@ -20,14 +20,6 @@ has application_name => (
     required => 1,
 );
 
-has help => (
-    traits        => ['Getopt'],
-    isa           => Bool,
-    is            => 'ro',
-    documentation => 'Display this help and exit',
-    cmd_aliases   => ['?', 'h'],
-);
-
 sub _getopt_spec_exception {}
 
 sub _getopt_spec_warnings {
@@ -41,11 +33,6 @@ sub _getopt_full_usage {
     exit 0;
 }
 
-before run => sub {
-    my $self = shift;
-    $self->_getopt_full_usage if $self->help;
-};
-
 sub run {
     my $self = shift;
     $self->_run_application;
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', "$@"/ );
         }
diff --git a/t/aggregate/live__component_controller_action_chained2.t b/t/aggregate/live__component_controller_action_chained2.t
new file mode 100644 (file)
index 0000000..213294a
--- /dev/null
@@ -0,0 +1,17 @@
+use strict;
+use warnings;
+use FindBin qw/$Bin/;
+use lib "$Bin/../lib";
+use Catalyst::Test 'ChainedActionsApp';
+use Test::More;
+
+content_like('/', qr/Application Home Page/, 'Application home');
+content_like('/15/GoldFinger', qr/List project GoldFinger pages/, 'GoldFinger Project Index');
+content_like('/15/GoldFinger/4/007', qr/This is 007 page of GoldFinger project/, '007 page in GoldFinger Project');
+content_like('/account', qr/New account o login/, 'no account');
+content_like('/account/ferz', qr/This is account ferz/, 'account');
+content_like('/account/123', qr/This is account 123/, 'account');
+action_notfound('/c');
+
+done_testing;
+
index 0287990..d3a6fab 100644 (file)
@@ -15,7 +15,6 @@ use lib "$Bin/../lib";
     sub _getopt_full_usage { $help++ }
 }
 
-test('-h');
 test('--help');
 test('-?');
 
index 71d0e4b..e475651 100644 (file)
@@ -33,8 +33,8 @@ sub run_test {
         } "new_with_options";
         ok $i;
         my $saved;
-        open( $saved, '<&'. STDIN->fileno )
-              or croak("Can't dup stdin: $!");
+        open( $saved, '>&'. STDOUT->fileno )
+            or croak("Can't dup stdout: $!");
         open( STDOUT, '>&='. $fh->fileno )
             or croak("Can't open stdout: $!");
         eval { $i->run };
index e8730de..f8868b6 100644 (file)
@@ -5,9 +5,12 @@ use Test::More;
 use Pod::Coverage 0.19;
 use Test::Pod::Coverage 1.04;
 
-all_pod_coverage_ok(
-  {
-    also_private => ['BUILD']
-  }
-);
+my @modules = all_modules;
+our @private = ( 'BUILD' );
+foreach my $module (@modules) {
+    local @private = (@private, 'run') if $module =~ /^Catalyst::Script::/;
+    pod_coverage_ok($module, { also_private => \@private });
+}
+
+done_testing;
 
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/ChainedActionsApp.pm b/t/lib/ChainedActionsApp.pm
new file mode 100644 (file)
index 0000000..375ce10
--- /dev/null
@@ -0,0 +1,21 @@
+package ChainedActionsApp;
+use Moose;
+use namespace::autoclean;
+
+use Catalyst::Runtime 5.80;
+
+use Catalyst qw//;
+
+extends 'Catalyst';
+
+our $VERSION = "0.01";
+$VERSION = eval $VERSION;
+
+__PACKAGE__->config(
+  name => 'ChainedActionsApp',
+  disable_component_regex_fallback => 1,
+);
+
+__PACKAGE__->setup;
+
+1;
diff --git a/t/lib/ChainedActionsApp/Controller/Root.pm b/t/lib/ChainedActionsApp/Controller/Root.pm
new file mode 100644 (file)
index 0000000..e1f0ae9
--- /dev/null
@@ -0,0 +1,112 @@
+package ChainedActionsApp::Controller::Root;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller' }
+
+#
+# Sets the actions in this controller to be registered with no prefix
+# so they function identically to actions created in MyApp.pm
+#
+__PACKAGE__->config(namespace => '');
+
+=head1 NAME
+
+test_chained::Controller::Root - Root Controller for test_chained
+
+=head1 DESCRIPTION
+
+[enter your description here]
+
+=head1 METHODS
+
+=head2 setup
+
+This is the C<setup> method that initializes the request. Any matching action
+will go through this, so it is an application-wide automatically executed
+action. For more information, see L<Catalyst::DispatchType::Chained>
+
+=cut
+
+sub setup : Chained('/') PathPart('') CaptureArgs(0) {
+    my ( $self, $c ) = @_;
+    # Common things here are to check for ACL and setup global contexts
+}
+
+sub home : Chained('setup') PathPart('') Args(0) {
+    my($self,$c) = @_;
+    $c->response->body( "Application Home Page" );
+}
+
+=head2 home_base
+
+     Args:
+       project_id
+       project_title
+
+=cut
+
+sub home_base : Chained('setup') PathPart('') CaptureArgs(2) {
+    my($self,$c,$proj_id,$title) = @_;
+    $c->stash({project_id=>$proj_id, project_title=>$title});
+}
+
+sub hpages : Chained('home_base') PathPart('') Args(0) {
+    my($self,$c) = @_;
+    $c->response->body( "List project " . $c->stash->{project_title} . " pages");
+}
+
+sub hpage : Chained('home_base') PathPart('') Args(2) {
+    my($self,$c,$page_id, $pagetitle) = @_;
+    $c->response->body( "This is $pagetitle page of " . $c->stash->{project_title} . " project" );
+}
+
+sub no_account : Chained('setup') PathPart('account') Args(0) {
+    my($self,$c) = @_;
+    $c->response->body( "New account o login" );
+}
+
+sub account_base : Chained('setup') PathPart('account') CaptureArgs(1) {
+    my($self,$c,$acc_id) = @_;
+    $c->stash({account_id=>$acc_id});
+}
+
+sub account : Chained('account_base') PathPart('') Args(0) {
+    my($self,$c,$acc) = @_;
+    $c->response->body( "This is account " . $c->stash->{account_id} );
+}
+
+=head2 default
+
+Standard 404 error page
+
+=cut
+
+sub default : Chained('setup') PathPart('') Args() {
+    my ( $self, $c ) = @_;
+    $c->response->body( 'Page not found' );
+    $c->response->status(404);
+}
+
+=head2 end
+
+Attempt to render a view, if needed.
+
+=cut
+
+sub end : ActionClass('RenderView') {}
+
+=head1 AUTHOR
+
+Ferruccio Zamuner
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+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/lib/TestAppShowInternalActions.pm b/t/lib/TestAppShowInternalActions.pm
new file mode 100644 (file)
index 0000000..250730f
--- /dev/null
@@ -0,0 +1,20 @@
+package TestAppShowInternalActions;
+use Moose;
+use namespace::autoclean;
+
+use Catalyst::Runtime 5.80;
+
+use Catalyst qw/ -Debug /; # Debug must remain on for
+                           # t/live_show_internal_actions_warnings.t
+
+extends 'Catalyst';
+
+__PACKAGE__->config(
+    name => 'TestAppShowInternalActions',
+    disable_component_resolution_regex_fallback => 1,
+    show_internal_actions => 1,
+);
+
+__PACKAGE__->setup();
+
+1;
diff --git a/t/lib/TestAppShowInternalActions/Controller/Root.pm b/t/lib/TestAppShowInternalActions/Controller/Root.pm
new file mode 100644 (file)
index 0000000..c36df9c
--- /dev/null
@@ -0,0 +1,19 @@
+package TestAppShowInternalActions::Controller::Root;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller' }
+
+__PACKAGE__->config(namespace => '');
+
+sub index :Path :Args(0) {
+    my ( $self, $c ) = @_;
+
+    $c->response->body( 'hello world' );
+}
+
+sub end : Action {}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/t/live_show_internal_actions_warnings.t b/t/live_show_internal_actions_warnings.t
new file mode 100644 (file)
index 0000000..0fe6ea3
--- /dev/null
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+use FindBin '$Bin';
+use lib "$Bin/lib";
+use Test::More;
+use File::Spec;
+BEGIN { # Shut up debug output, app needs debug on for the issue to
+        # appear, but we don't want the spraff to the screen
+
+    my $devnull = File::Spec->devnull;
+    open my $fh, '>', $devnull or die "Cannot write to $devnull: $!";
+
+    *STDERR = $fh;
+}
+
+use Catalyst::Test 'TestAppShowInternalActions';
+
+my $last_warning;
+{
+    local $SIG{__WARN__} = sub { $last_warning = shift };
+    my $res = get('/');
+}
+is( $last_warning, undef, 'there should be no warnings about uninitialized value' );
+
+done_testing;
index b6f5054..8b8b659 100644 (file)
@@ -15,13 +15,13 @@ use Test::More;
 
     sub test {}
 }
-
+my $c = 0;
 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";
+        local $TODO = "Known MX::MethodAttributes issue" if $c++;
         ok $meth->can('attributes'), 'method metaclass has ->attributes method for ' . $class;;
     }
 }