[Catalyst-commits] r9672 - in Catalyst-Runtime/5.80/trunk: . lib/Catalyst t t/lib t/lib/TestAppMetaCompat t/lib/TestAppMetaCompat/Action t/lib/TestAppMetaCompat/Controller

rafl at dev.catalyst.perl.org rafl at dev.catalyst.perl.org
Sun Apr 12 13:28:23 GMT 2009


Author: rafl
Date: 2009-04-12 14:28:23 +0100 (Sun, 12 Apr 2009)
New Revision: 9672

Added:
   Catalyst-Runtime/5.80/trunk/TODO.register_actions
   Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat.pm
   Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/
   Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Action/
   Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Action/UsesCAF.pm
   Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Controller/
   Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Controller/Base.pm
   Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Controller/Books.pm
   Catalyst-Runtime/5.80/trunk/t/unit_metaclass_compat_non_moose.t
Removed:
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/AttrContainer.pm
Modified:
   Catalyst-Runtime/5.80/trunk/Changes
   Catalyst-Runtime/5.80/trunk/Makefile.PL
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/ClassData.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm
Log:
Merge branch 'register_actions'

* register_actions:
  remove trailing whitespace
  mis-rebase
  split out methods to show rafl what I mean
  Tidy error, remove debug, tidy warn.
  And fix it properly.
  We actually need Moose::Object::meta to avoid metaclass incompat fail, or at least this fixes the test..
  Bump MX::MethodAttributes::Inheritable dep
  Update todo having gone through all the smokes
  Metaclass compatibility fail. This needs to be reduced to a test for Moose..
  List of things from smokes which appear to fail here
  backout, wrong branch fail
  Update TODO
  Use get_all_methods_with_attributes to get all possible actions.
  Update prereqs.
  Don't stringify the meta method. Use its name instead.
  First steps towards throwing out attributes.
  Create branch register_actions.

Conflicts:
	Changes
	Makefile.PL

Modified: Catalyst-Runtime/5.80/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.80/trunk/Changes	2009-04-09 21:38:42 UTC (rev 9671)
+++ Catalyst-Runtime/5.80/trunk/Changes	2009-04-12 13:28:23 UTC (rev 9672)
@@ -23,6 +23,8 @@
           - Test for this (t0m)
         - Kill Class::C3::Adopt::NEXT warnings for the Catalyst:: namespace
           in production versions (t0m)
+        - Tidy up Catalyst::ClassData to ensure that all components get
+          the correct metaclass (t0m)
         - Make MyApp.pm restartable by unsetting setup_finished in
           the restarter process (t0m)
         - Non-naive implementation of making mutable on restart using

Modified: Catalyst-Runtime/5.80/trunk/Makefile.PL
===================================================================
--- Catalyst-Runtime/5.80/trunk/Makefile.PL	2009-04-09 21:38:42 UTC (rev 9671)
+++ Catalyst-Runtime/5.80/trunk/Makefile.PL	2009-04-12 13:28:23 UTC (rev 9672)
@@ -9,6 +9,7 @@
 requires 'Scope::Upper' => '0.06';
 requires 'MooseX::Emulate::Class::Accessor::Fast' => '0.00801';
 requires 'Moose' => '0.73';
+requires 'MooseX::MethodAttributes::Inheritable' => '0.05';
 requires 'Carp';
 requires 'Class::C3::Adopt::NEXT' => '0.07';
 requires 'Class::MOP' => '0.79';

Added: Catalyst-Runtime/5.80/trunk/TODO.register_actions
===================================================================
--- Catalyst-Runtime/5.80/trunk/TODO.register_actions	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/TODO.register_actions	2009-04-12 13:28:23 UTC (rev 9672)
@@ -0,0 +1,14 @@
+Catalyst-Controller-FormBuilder:
+  t/unit_metaclass_compat_non_moose.t
+
+Catalyst-Model-Search:
+CatalystX-CRUD:
+  Could not load class (MyApp) because : Can't locate object method
+  "get_all_methods_with_attributes" via package
+  "Class::MOP::Class" at lib/Catalyst/Controller.pm line 184.
+
+CatalystX-Imports:
+  Could not load class (TestApp) because : Can't locate object method
+  "_action_cache" via package "TestApp::Controller::Vars" at
+  lib/CatalystX/Imports.pm line 192.
+  Compilation failed in require at lib/Catalyst/Utils.pm line 278.

Deleted: Catalyst-Runtime/5.80/trunk/lib/Catalyst/AttrContainer.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/AttrContainer.pm	2009-04-09 21:38:42 UTC (rev 9671)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/AttrContainer.pm	2009-04-12 13:28:23 UTC (rev 9672)
@@ -1,60 +0,0 @@
-package Catalyst::AttrContainer;
-
-use Moose;
-use Catalyst::Exception;
-with 'Catalyst::ClassData';
-
-no Moose;
-
-__PACKAGE__->mk_classdata(_attr_cache => {} );
-__PACKAGE__->mk_classdata( _action_cache => [] );
-
-# note - see attributes(3pm)
-sub MODIFY_CODE_ATTRIBUTES {
-    my ( $class, $code, @attrs ) = @_;
-    $class->_attr_cache( { %{ $class->_attr_cache }, $code => [@attrs] } );
-    $class->_action_cache(
-        [ @{ $class->_action_cache }, [ $code, [@attrs] ] ] );
-    return ();
-}
-
-sub FETCH_CODE_ATTRIBUTES { $_[0]->_attr_cache->{ $_[1] } || () }
-
-=head1 NAME
-
-Catalyst::AttrContainer - Handles code attribute storage and caching
-
-=head1 SYNOPSIS
-
-=head1 DESCRIPTION
-
-This class sets up the code attribute cache.  It's a base class for 
-L<Catalyst::Controller>.
-
-=head1 METHODS
-
-=head2 FETCH_CODE_ATTRIBUTES
-
-Attribute function. See attributes(3pm)
-
-=head2 MODIFY_CODE_ATTRIBUTES
-
-Attribute function. See attributes(3pm)
-
-=head1 SEE ALSO
-
-L<Catalyst::Dispatcher>
-L<Catalyst>.
-
-=head1 AUTHORS
-
-Catalyst Contributors, see Catalyst.pm
-
-=head1 COPYRIGHT
-
-This program is free software, you can redistribute it and/or modify it under
-the same terms as Perl itself.
-
-=cut
-
-1;

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/ClassData.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/ClassData.pm	2009-04-09 21:38:42 UTC (rev 9671)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/ClassData.pm	2009-04-12 13:28:23 UTC (rev 9672)
@@ -2,7 +2,7 @@
 
 use Moose::Role;
 use Class::MOP;
-use Class::MOP::Object;
+use Moose::Util ();
 
 sub mk_classdata {
   my ($class, $attribute) = @_;
@@ -12,8 +12,8 @@
   my $slot = '$'.$attribute;
   my $accessor =  sub {
     my $pkg = ref $_[0] || $_[0];
-    # Hack - delberately create a metaclass instance
-    my $meta = $pkg->Class::MOP::Object::meta();
+    my $meta = Moose::Util::find_meta($pkg) 
+        || Moose->init_meta( for_class => $pkg );
     if (@_ > 1) {
       $meta->namespace->{$attribute} = \$_[1];
       return $_[1];

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm	2009-04-09 21:38:42 UTC (rev 9671)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm	2009-04-12 13:28:23 UTC (rev 9672)
@@ -5,8 +5,7 @@
 
 use namespace::clean -except => 'meta';
 
-# Note - Must be done at compile time due to attributes (::AttrContainer)
-BEGIN { extends qw/Catalyst::Component Catalyst::AttrContainer/; }
+BEGIN { extends qw/Catalyst::Component MooseX::MethodAttributes::Inheritable/; }
 
 use Catalyst::Exception;
 use Catalyst::Utils;
@@ -53,9 +52,9 @@
   package MyApp::Controller::Search
   use base qw/Catalyst::Controller/;
 
-  sub foo : Local { 
+  sub foo : Local {
     my ($self,$c, at args) = @_;
-    ... 
+    ...
   } # Dispatches to /search/foo
 
 =head1 DESCRIPTION
@@ -128,7 +127,7 @@
     return $app->dispatcher->get_action($name, $self->action_namespace);
 }
 
-#my opinion is that this whole sub really should be a builder method, not 
+#my opinion is that this whole sub really should be a builder method, not
 #something that happens on every call. Anyone else disagree?? -- groditi
 ## -- apparently this is all just waiting for app/ctx split
 around action_namespace => sub {
@@ -175,41 +174,43 @@
     return $namespace;
 };
 
+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_all_methods_with_attributes');
+    my @methods = $meta->get_all_methods_with_attributes;
+    return @methods;
+}
 
 sub register_actions {
     my ( $self, $c ) = @_;
+    $self->register_action_methods( $c, $self->get_action_methods );
+}
+
+sub register_action_methods {
+    my ( $self, $c, @methods ) = @_;
     my $class = ref $self || $self;
     #this is still not correct for some reason.
     my $namespace = $self->action_namespace($c);
-    my $meta = find_meta($self);
-    my %methods = map { $_->body => $_->name }
-            $meta->get_all_methods;
 
-    # Advanced inheritance support for plugins and the like
-    #moose todo: migrate to eliminate CDI compat
-    my @action_cache;
-    for my $isa ( $meta->superclasses, $class ) {
-        if(my $coderef = $isa->can('_action_cache')){
-            push(@action_cache, @{ $isa->$coderef });
-        }
-    }
-
-    foreach my $cache (@action_cache) {
-        my $code   = $cache->[0];
-        my $method = delete $methods{$code}; # avoid dupe registers
-        next unless $method;
-        my $attrs = $self->_parse_attrs( $c, $method, @{ $cache->[1] } );
+    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 "'
-                  . join( ' ', @{ $cache->[1] } )
-                  . qq/" for "$class->$method"/ )
+                  . join( ' ', @{ $attributes } )
+                  . qq/" for "$class->$name"/ )
               if $c->debug;
             next;
         }
-        my $reverse = $namespace ? "${namespace}/${method}" : $method;
+        my $reverse = $namespace ? "${namespace}/${name}" : $name;
         my $action = $self->create_action(
-            name       => $method,
-            code       => $code,
+            name       => $name,
+            code       => $method->body,
             reverse    => $reverse,
             namespace  => $namespace,
             class      => $class,
@@ -329,7 +330,7 @@
 
     my $prefix = $self->path_prefix( $c );
     $prefix .= '/' if length( $prefix );
-   
+
     return ( 'Regex', "^${prefix}${value}" );
 }
 
@@ -409,7 +410,7 @@
 will be bound to 'foo/bar'. The default Root controller is an example
 of setting namespace to '' (the null string).
 
-=head2 path 
+=head2 path
 
 Sets 'path_prefix', as described below.
 

Added: Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Action/UsesCAF.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Action/UsesCAF.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Action/UsesCAF.pm	2009-04-12 13:28:23 UTC (rev 9672)
@@ -0,0 +1,8 @@
+package TestAppMetaCompat::Action::UsesCAF;
+
+use strict;
+
+use base qw/Catalyst::Action Class::Accessor::Fast/;
+__PACKAGE__->mk_accessors(qw/ foo /);
+
+1;

Added: Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Controller/Base.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Controller/Base.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Controller/Base.pm	2009-04-12 13:28:23 UTC (rev 9672)
@@ -0,0 +1,6 @@
+package TestAppMetaCompat::Controller::Base;
+
+use strict;
+use base qw/Catalyst::Controller/;
+
+1;

Added: Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Controller/Books.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Controller/Books.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat/Controller/Books.pm	2009-04-12 13:28:23 UTC (rev 9672)
@@ -0,0 +1,9 @@
+package TestAppMetaCompat::Controller::Books;
+
+use strict;
+use base qw/TestAppMetaCompat::Controller::Base/;
+
+sub edit : Local ActionClass('+Catalyst::Controller::FormBuilder::Action') {
+}
+
+1;

Added: Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestAppMetaCompat.pm	2009-04-12 13:28:23 UTC (rev 9672)
@@ -0,0 +1,8 @@
+package TestAppMetaCompat;
+use base qw/Catalyst/;
+
+__PACKAGE__->config(name => __PACKAGE__);
+__PACKAGE__->setup;
+
+1;
+

Added: Catalyst-Runtime/5.80/trunk/t/unit_metaclass_compat_non_moose.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/unit_metaclass_compat_non_moose.t	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/unit_metaclass_compat_non_moose.t	2009-04-12 13:28:23 UTC (rev 9672)
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More tests => 1;
+use_ok('TestAppMetaCompat');
+




More information about the Catalyst-commits mailing list