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

1  2 
lib/Catalyst.pm
lib/Catalyst/Component.pm

diff --combined lib/Catalyst.pm
@@@ -78,7 -78,7 +78,7 @@@ __PACKAGE__->stats_class('Catalyst::Sta
  
  # Remember to update this in Catalyst::Runtime as well!
  
 -our $VERSION = '5.80018';
 +our $VERSION = '5.80019';
  $VERSION = eval $VERSION;
  
  sub import {
@@@ -243,9 -243,6 +243,9 @@@ environment with CATALYST_DEBUG or <MYA
  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
@@@ -265,14 -262,6 +265,14 @@@ is replaced with the uppercased name o
  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';
@@@ -934,8 -923,6 +934,8 @@@ You can enable debug mode in several wa
  
  =back
  
 +The first three also set the log level to 'debug'.
 +
  Calling C<< $c->debug(1) >> has no effect.
  
  =cut
@@@ -1259,19 -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) }
                           : ()) ];
          $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
@@@ -2239,8 -2224,11 +2239,11 @@@ sub setup_components 
      }
  
      for my $component (@comps) {
-         $class->components->{ $component } = $class->setup_component($component);
-         for my $component ($class->expand_component_module( $component, $config )) {
+         my $instance = $class->components->{ $component } = $class->setup_component($component);
+         my @expanded_components = $instance->can('expand_modules')
+             ? $instance->expand_modules( $component, $config )
+             : $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);
@@@ -5,6 -5,7 +5,7 @@@ use Class::MOP
  use Class::MOP::Object;
  use Catalyst::Utils;
  use Class::C3::Adopt::NEXT;
+ use Devel::InnerPackage ();
  use MRO::Compat;
  use mro 'c3';
  use Scalar::Util 'blessed';
@@@ -84,6 -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 = +{ @_ };
          }
@@@ -147,6 -150,11 +148,11 @@@ sub process 
            . " did not override Catalyst::Component::process" );
  }
  
+ sub expand_modules {
+     my ($class, $component) = @_;
+     return Devel::InnerPackage::list_packages( $component );
+ }
  __PACKAGE__->meta->make_immutable;
  
  1;
@@@ -205,6 -213,13 +211,13 @@@ when you forward to them. The default i
  Merges two hashes together recursively, giving right-hand precedence.
  Alias for the method in L<Catalyst::Utils>.
  
+ =head2 $c->expand_modules( $setup_component_config )
+ Return a list of extra components that this component has created. By default,
+ it just looks for a list of inner packages of this component
+ =cut
  =head1 OPTIONAL METHODS
  
  =head2 ACCEPT_CONTEXT($c, @args)