start using Class::C3, may need to add a reinitalize bit later, not sure
Guillermo Roditi [Mon, 23 Jun 2008 21:19:18 +0000 (21:19 +0000)]
r17830@martha (orig r7761):  groditi | 2008-05-17 17:52:33 -0400

27 files changed:
lib/Catalyst.pm
lib/Catalyst/Action.pm
lib/Catalyst/ActionChain.pm
lib/Catalyst/ActionContainer.pm
lib/Catalyst/AttrContainer.pm
lib/Catalyst/Base.pm
lib/Catalyst/Component.pm
lib/Catalyst/Controller.pm
lib/Catalyst/DispatchType.pm
lib/Catalyst/DispatchType/Chained.pm
lib/Catalyst/DispatchType/Default.pm
lib/Catalyst/DispatchType/Index.pm
lib/Catalyst/DispatchType/Path.pm
lib/Catalyst/DispatchType/Regex.pm
lib/Catalyst/Dispatcher.pm
lib/Catalyst/Engine.pm
lib/Catalyst/Engine/CGI.pm
lib/Catalyst/Engine/FastCGI.pm
lib/Catalyst/Engine/HTTP.pm
lib/Catalyst/Engine/HTTP/Restarter.pm
lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm
lib/Catalyst/Log.pm
lib/Catalyst/Model.pm
lib/Catalyst/Request.pm
lib/Catalyst/Request/Upload.pm
lib/Catalyst/Response.pm
lib/Catalyst/View.pm

index 37425b1..c3ff12c 100644 (file)
@@ -1,5 +1,6 @@
 package Catalyst;
 
+use Class::C3;
 use Moose;
 extends 'Catalyst::Component';
 use bytes;
@@ -39,13 +40,12 @@ has request => (is => 'rw', default => sub { $_[0]->request_class->new({}) }, re
 has response => (is => 'rw', default => sub { $_[0]->response_class->new({}) }, required => 1, lazy => 1);
 has namespace => (is => 'rw');
 
+no Moose;
 
 attributes->import( __PACKAGE__, \&namespace, 'lvalue' );
 
 sub depth { scalar @{ shift->stack || [] }; }
-
-# Laziness++
-*comp = \&component;
+sub comp { shift->component(@_) }
 
 sub req {
     # carp "the use of req() is deprecated in favour of request()";
@@ -57,7 +57,7 @@ sub res {
 }
 
 # For backwards compatibility
-*finalize_output = \&finalize_body;
+sub finalize_output { shift->finalize_body(@_) };
 
 # For statistics
 our $COUNT     = 1;
@@ -379,20 +379,20 @@ Catalyst).
 
 =cut
 
-around stash => sub {
-    my $orig = shift;
+sub stash {
     my $c = shift;
-
-    my $orig_stash = $c->$orig();
     if (@_) {
         my $stash = @_ > 1 ? {@_} : $_[0];
         croak('stash takes a hash or hashref') unless ref $stash;
         foreach my $key ( keys %$stash ) {
-            $orig_stash->{$key} = $stash->{$key};
+            #shouldn't we hold this in a var and save ourselves the subcall?
+            $c->next::method->{$key} = $stash->{$key};
         }
     }
-    return $orig_stash;
-};
+
+    return $c->next::method;
+}
+
 
 =head2 $c->error
 
@@ -704,15 +704,14 @@ L<Catalyst::Plugin::ConfigLoader>.
 
 =cut
 
-around config => sub {
-    my $orig = shift;
+sub config {
     my $c = shift;
 
     $c->log->warn("Setting config after setup has been run is not a good idea.")
       if ( @_ and $c->setup_finished );
 
-    $c->$orig(@_);
-};
+    $c->next::method(@_);
+}
 
 =head2 $c->log
 
index 4469a1d..640a209 100644 (file)
@@ -17,6 +17,7 @@ L<Catalyst::Controller> subclasses.
 
 =cut
 
+use Class::C3;
 use Moose;
 
 has class => (is => 'rw');
index 819b894..3c0b49b 100644 (file)
@@ -1,10 +1,13 @@
 package Catalyst::ActionChain;
 
+use Class::C3;
 use Moose;
 extends qw(Catalyst::Action);
 
 has chain => (is => 'rw');
 
+no Moose;
+
 =head1 NAME
 
 Catalyst::ActionChain - Chain of Catalyst Actions
@@ -57,7 +60,6 @@ sub from_chain {
     return $self->new({ %$final, chain => $actions });
 }
 
-no Moose;
 __PACKAGE__->meta->make_immutable;
 1;
 
index 9d41f4e..a51f90a 100644 (file)
@@ -15,6 +15,7 @@ to represent the various dispatch points in your application.
 
 =cut
 
+use Class::C3;
 use Moose;
 
 use overload (
@@ -27,14 +28,14 @@ use overload (
 has part => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
 has actions => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
 
-around 'new' => sub {
-  my $next = shift;
+no Moose;
+
+sub new {
   my ($self, $params) = @_;
   $params = { part => $params } unless ref $params;
-  $next->($self, $params);
-};
+  $self->next::method($params);
+}
 
-no Moose;
 
 sub get_action {
     my ( $self, $name ) = @_;
index 334d5de..39befd4 100644 (file)
@@ -5,6 +5,8 @@ use Catalyst::Exception;
 
 with 'Catalyst::ClassData';
 
+no Moose;
+
 __PACKAGE__->mk_classdata($_) for qw/_attr_cache _action_cache/;
 __PACKAGE__->_attr_cache( {} );
 __PACKAGE__->_action_cache( [] );
index 24f730e..cf41083 100644 (file)
@@ -1,8 +1,9 @@
 package Catalyst::Base;
 
+use Class::C3;
 use Moose;
 BEGIN{ extends qw/Catalyst::Controller/ };
-
+no Moose;
 
 1;
 
index aac0b64..cf47c27 100644 (file)
@@ -1,5 +1,6 @@
 package Catalyst::Component;
 
+use Class::C3;
 use Moose;
 use MooseX::Adopt::Class::Accessor::Fast;
 use Catalyst::Utils;
@@ -8,6 +9,7 @@ use Catalyst::Utils;
 with 'MooseX::Emulate::Class::Accessor::Fast';
 with 'Catalyst::ClassData';
 
+no Moose;
 
 =head1 NAME
 
@@ -54,38 +56,32 @@ component loader with config() support and a process() method placeholder.
 
 __PACKAGE__->mk_classdata($_) for qw/_config _plugins/;
 
-around new => sub {
-    my $orig = shift;
+sub new {
     my ( $self, $c ) = @_;
 
     # Temporary fix, some components does not pass context to constructor
     my $arguments = ( ref( $_[-1] ) eq 'HASH' ) ? $_[-1] : {};
 
     my $args =  $self->merge_config_hashes( $self->config, $arguments );
-    return $self->$orig( $args );
-};
+    $self->next::method( $args );
+}
 
 sub COMPONENT {
     my ( $self, $c ) = @_;
 
     # Temporary fix, some components does not pass context to constructor
     my $arguments = ( ref( $_[-1] ) eq 'HASH' ) ? $_[-1] : {};
-    $self->new($c, $arguments);
-
-#     if ( my $new = $self->NEXT::COMPONENT( $c, $arguments ) ) {
-#         return $new;
-#     }
-#     else {
-#         if ( my $new = $self->new( $c, $arguments ) ) {
-#             return $new;
-#         }
-#         else {
-#             my $class = ref $self || $self;
-#             my $new   = $self->merge_config_hashes(
-#                 $self->config, $arguments );
-#             return bless $new, $class;
-#         }
-#     }
+
+
+    #this is not the EXACT logic we had before, since  the original tested
+    #for a true value before returning meaning that a subsequent COMPONENT
+    #call could return undef and that would trigger a try to new, which could
+    #again return undef, which would lead to a straight bless of the args and
+    #config. I did not mantain that behavior because it did not seemed sane
+    # please rip me a new one if you have reason to believe i am being stupid
+    # --groditi
+    return $self->next::can ?
+      $self->next::method($c, $arguments) : $self->new($c, $arguments);
 }
 
 sub config {
index 2e58312..29ffc81 100644 (file)
@@ -1,6 +1,7 @@
 package Catalyst::Controller;
 
 #switch to BEGIN { extends qw/ ... /; } ?
+use Class::C3;
 use base qw/Catalyst::Component Catalyst::AttrContainer/;
 use Moose;
 
@@ -34,7 +35,7 @@ has actions =>
 
 # isa => 'ClassName|Catalyst' ?
 has _application => (is => 'rw');
-sub _app{ shift->_application(@_) } # eww
+sub _app{ shift->_application(@_) } 
 
 sub BUILD {
     my ($self, $args) = @_;
@@ -122,14 +123,13 @@ sub _END : Private {
     return !@{ $c->error };
 }
 
-around new => sub {
-    my $orig = shift;
+sub new {
     my $self = shift;
     my $app = $_[0];
-    my $new = $self->$orig(@_);
+    my $new = $self->next::method(@_);
     $new->_application( $app );
     return $new;
-};
+}
 
 sub action_for {
     my ( $self, $name ) = @_;
@@ -137,18 +137,25 @@ sub action_for {
     return $app->dispatcher->get_action($name, $self->action_namespace);
 }
 
+#my opinion is that this whole sub really should be a builder method, not 
+#something that happens on every call. Anyone else disagree?? -- groditi
+
+#we are wrapping the accessor, so just uyse a modifier since a normal sub would
+#just be overridden by the generated moose method 
 around action_namespace => sub {
-    my ( $orig, $self, $c ) = @_;
+    my $orig = shift;
+    my ( $self, $c ) = @_;
 
     if( ref($self) ){
         return $self->$orig if $self->has_action_namespace;
-    } else {
+    } else { 
+        # if the following won't change at runtime it should be lazy_building thing
         return $self->config->{namespace} if exists $self->config->{namespace};
     }
 
     #the following looks like a possible target for a default setting. i am not
     #making the below the builder because i don't know if $c will vary from
-    #call to call, which would affect case sensitivitysettings -- groditi
+    #call to call, which would affect case sensitivity settings -- groditi
     my $case_s;
     if( $c ){
         $case_s = $c->config->{case_sensitive};
@@ -167,7 +174,7 @@ around action_namespace => sub {
     return Catalyst::Utils::class2prefix(ref($self) || $self, $case_s) || '';
 };
 
-
+#Once again, this is probably better written as a builder method
 around path_prefix => sub {
     my $orig = shift;
     my $self = shift;
@@ -362,6 +369,8 @@ sub _parse_MyAction_attr {
     return ( 'ActionClass', $value );
 }
 
+no Moose;
+
 1;
 
 __END__
index 99da4c6..d49febc 100644 (file)
@@ -1,8 +1,8 @@
 package Catalyst::DispatchType;
 
-use Moose;
-#use strict;
-#use base 'Class::Accessor::Fast';
+use Class::C3;
+use Moose; # using it to add Moose::Object to @ISA ...
+no Moose;
 
 =head1 NAME
 
@@ -71,7 +71,6 @@ the same terms as Perl itself.
 
 =cut
 
-no Moose;
 __PACKAGE__->meta->make_immutable;
 
 1;
index 25617da..3b72e15 100644 (file)
@@ -1,5 +1,6 @@
 package Catalyst::DispatchType::Chained;
 
+use Class::C3;
 use Moose;
 extends 'Catalyst::DispatchType';
 
@@ -28,6 +29,8 @@ has _children_of => (
                      default => sub{ {} },
                     );
 
+no Moose;
+
 # please don't perltidy this. hairy code within.
 
 =head1 NAME
@@ -328,7 +331,6 @@ sub uri_for_action {
    
 }
 
-no Moose;
 __PACKAGE__->meta->make_immutable;
 
 =head1 USAGE
index 1216b44..5dcf135 100644 (file)
@@ -1,11 +1,10 @@
 package Catalyst::DispatchType::Default;
 
+use Class::C3;
 use Moose;
 extends 'Catalyst::DispatchType';
 
-
-#use strict;
-#use base qw/Catalyst::DispatchType/;
+no Moose;
 
 =head1 NAME
 
@@ -61,7 +60,6 @@ the same terms as Perl itself.
 
 =cut
 
-no Moose;
 __PACKAGE__->meta->make_immutable;
 
 1;
index bbda89c..1cb5bdb 100644 (file)
@@ -1,10 +1,9 @@
 package Catalyst::DispatchType::Index;
 
+use Class::C3;
 use Moose;
 extends 'Catalyst::DispatchType';
-
-#use strict;
-#use base qw/Catalyst::DispatchType/;
+no Moose;
 
 =head1 NAME
 
@@ -69,7 +68,6 @@ the same terms as Perl itself.
 
 =cut
 
-no Moose;
 __PACKAGE__->meta->make_immutable;
 
 1;
index 46902c4..69e91da 100644 (file)
@@ -1,10 +1,9 @@
 package Catalyst::DispatchType::Path;
 
+use Class::C3;
 use Moose;
 extends 'Catalyst::DispatchType';
 
-#use strict;
-#use base qw/Catalyst::DispatchType/;
 use Text::SimpleTable;
 use URI;
 
@@ -15,6 +14,8 @@ has _paths => (
                default => sub { +{} },
               );
 
+no Moose;
+
 =head1 NAME
 
 Catalyst::DispatchType::Path - Path DispatchType
@@ -140,7 +141,6 @@ the same terms as Perl itself.
 
 =cut
 
-no Moose;
 __PACKAGE__->meta->make_immutable;
 
 1;
index c417a4c..d21eb75 100644 (file)
@@ -1,10 +1,9 @@
 package Catalyst::DispatchType::Regex;
 
+use Class::C3;
 use Moose;
 extends 'Catalyst::DispatchType::Path';
 
-#use strict;
-#use base qw/Catalyst::DispatchType::Path/;
 use Text::SimpleTable;
 use Text::Balanced ();
 
@@ -15,6 +14,8 @@ has _compiled => (
                   default => sub{ [] },
                  );
 
+no Moose;
+
 =head1 NAME
 
 Catalyst::DispatchType::Regex - Regex DispatchType
@@ -161,7 +162,6 @@ the same terms as Perl itself.
 
 =cut
 
-no Moose;
 __PACKAGE__->meta->make_immutable;
 
 1;
index 0818f85..7631c86 100644 (file)
@@ -519,7 +519,7 @@ sub _load_dispatch_types {
     for my $type (@types) {
         my $class =
           ( $type =~ /^\+(.*)$/ ) ? $1 : "Catalyst::DispatchType::${type}";
-        #eval "require $class";
+
         eval { Class::MOP::load_class($class) };
         Catalyst::Exception->throw( message => qq/Couldn't load "$class"/ )
           if $@;
index 71773fe..8b3a701 100644 (file)
@@ -1,5 +1,6 @@
 package Catalyst::Engine;
 
+use Class::C3;
 use Moose;
 with 'MooseX::Emulate::Class::Accessor::Fast';
 
@@ -16,6 +17,8 @@ use Scalar::Util ();
 has read_length => (is => 'rw');
 has read_position => (is => 'rw');
 
+no Moose;
+
 # Stringify to class
 use overload '""' => sub { return ref shift }, fallback => 1;
 
index ae5a652..5a09064 100644 (file)
@@ -1,10 +1,13 @@
 package Catalyst::Engine::CGI;
 
+use Class::C3;
 use Moose;
 extends 'Catalyst::Engine';
 
 has env => (is => 'rw');
 
+no Moose;
+
 =head1 NAME
 
 Catalyst::Engine::CGI - The CGI Engine
@@ -172,15 +175,14 @@ sub prepare_path {
 
 =cut
 
-around prepare_query_parameters => sub {
-    my $orig = shift;
+sub prepare_query_parameters {
     my ( $self, $c ) = @_;
     local (*ENV) = $self->env || \%ENV;
 
     if ( $ENV{QUERY_STRING} ) {
-        $self->$orig( $c, $ENV{QUERY_STRING} );
+        $self->next::method( $c, $ENV{QUERY_STRING} );
     }
-};
+}
 
 =head2 $self->prepare_request($c, (env => \%env))
 
@@ -200,9 +202,10 @@ Enable autoflush on the output handle for CGI-based engines.
 
 =cut
 
-before prepare_write => sub {
+sub prepare_write {
     *STDOUT->autoflush(1);
-};
+    return shift->next::method(@_);
+}
 
 =head2 $self->write($c, $buffer)
 
@@ -210,8 +213,7 @@ Writes the buffer to the client.
 
 =cut
 
-around write => sub {
-    my $orig = shift;
+sub write {
     my ( $self, $c, $buffer ) = @_;
 
     # Prepend the headers if they have not yet been sent
@@ -219,8 +221,8 @@ around write => sub {
         $buffer = $headers . $buffer;
     }
 
-    return $self->$orig( $c, $buffer );
-};
+    return $self->next::method( $c, $buffer );
+}
 
 =head2 $self->read_chunk($c, $buffer, $length)
 
index e009dfa..41da9b9 100644 (file)
@@ -1,8 +1,10 @@
 package Catalyst::Engine::FastCGI;
 
+use Class::C3;
 use Moose;
 extends 'Catalyst::Engine::CGI';
 
+# eval { Class::MOP::load_class("FCGI") };
 eval "use FCGI";
 die "Unable to load the FCGI module, you may need to install it:\n$@\n" if $@;
 
index 090b4f2..fd11fc9 100644 (file)
@@ -1,7 +1,10 @@
 package Catalyst::Engine::HTTP;
 
+use Class::C3;
 use Moose;
 extends 'Catalyst::Engine::CGI';
+no Moose;
+
 use Data::Dump qw(dump);
 use Errno 'EWOULDBLOCK';
 use HTTP::Date ();
@@ -83,20 +86,22 @@ sub finalize_headers {
 
 =cut
 
-before finalize_read => sub {
+sub finalize_read {
     # Never ever remove this, it would result in random length output
     # streams if STDIN eq STDOUT (like in the HTTP engine)
     *STDIN->blocking(1);
-};
+    shift->next::method(@_);
+}
 
 =head2 $self->prepare_read($c)
 
 =cut
 
-befpre prepare_read => sub {
+sub prepare_read {
     # Set the input handle to non-blocking
     *STDIN->blocking(0);
-};
+    shift->next::method(@_);
+}
 
 =head2 $self->read_chunk($c, $buffer, $length)
 
@@ -138,8 +143,7 @@ Writes the buffer to the client.
 
 =cut
 
-around write => sub {
-    my $orig = shift;
+sub write {
     my ( $self, $c, $buffer ) = @_;
 
     # Avoid 'print() on closed filehandle Remote' warnings when using IE
@@ -150,7 +154,7 @@ around write => sub {
         $buffer = $headers . $buffer;
     }
 
-    my $ret = $self->$orig( $c, $buffer );
+    my $ret = $self->next::method($c, $buffer);
 
     if ( !defined $ret ) {
         $self->{_write_error} = $!;
@@ -159,9 +163,9 @@ around write => sub {
     else {
         DEBUG && warn "write: Wrote response ($ret bytes)\n";
     }
-    
+
     return $ret;
-};
+}
 
 =head2 run
 
index a410950..6b1b5f5 100644 (file)
@@ -1,11 +1,13 @@
 package Catalyst::Engine::HTTP::Restarter;
 
+use Class::C3;
 use Moose;
 extends 'Catalyst::Engine::HTTP';
+no Moose;
+
 use Catalyst::Engine::HTTP::Restarter::Watcher;
 
-around run => sub {
-    my $orig = shift;
+sub run {
     my ( $self, $class, $port, $host, $options ) = @_;
 
     $options ||= {};
@@ -66,7 +68,7 @@ around run => sub {
         }
     }
 
-    return $self->$orig( $class, $port, $host, $options );
+    return $self->next::method( $class, $port, $host, $options );
 };
 
 1;
index 847fb0d..9ad126e 100644 (file)
@@ -13,16 +13,10 @@ has directory => (is => 'rw');
 has watch_list => (is => 'rw');
 has follow_simlinks => (is => 'rw');
 
-sub new {
-    my ( $class, %args ) = @_;
+no Moose;
 
-    my $self = {%args};
-
-    bless $self, $class;
-
-    $self->_init;
-
-    return $self;
+sub BUILD {
+  shift->_init;
 }
 
 sub _init {
index 1a33c98..3f67952 100644 (file)
@@ -1,5 +1,6 @@
 package Catalyst::Log;
 
+use Class::C3;
 use Moose;
 use Data::Dump;
 
@@ -36,13 +37,12 @@ has abort => (is => 'rw');
     }
 }
 
-around new => sub {
-    my $orig = shift;
+sub new {
     my $class = shift;
-    my $self = $class->$orig;
+    my $self = $class->next::method;
     $self->levels( scalar(@_) ? @_ : keys %LEVELS );
     return $self;
-};
+}
 
 sub levels {
     my ( $self, @levels ) = @_;
index deb2d24..896e3ae 100644 (file)
@@ -4,7 +4,9 @@ use Moose;
 extends qw/Catalyst::Component/;
 
 no Moose;
-__PACKAGE__->meta->make_immutable();
+
+#We can't immutablize anything that ISA Component just yet
+#__PACKAGE__->meta->make_immutable();
 
 =head1 NAME
 
index ec7a96a..21a26bf 100644 (file)
@@ -1,5 +1,6 @@
 package Catalyst::Request;
 
+use Class::C3;
 use IO::Socket qw[AF_INET inet_aton];
 use Carp;
 use utf8;
@@ -32,9 +33,16 @@ has headers => (
   lazy => 1,
 );
 
+#Moose ToDo:
+#can we lose the before modifiers which just call prepare_body ?
+#they are wasteful, slow us down and feel cluttery.
+# Can we call prepare_body at BUILD time?
+# Can we make _body an attribute and have the rest of these lazy build from there?
+
 has _context => (
   is => 'rw',
   weak_ref => 1,
+  handles => ['read'],
 );
 
 has body_parameters => (
@@ -56,10 +64,11 @@ has uploads => (
   default => sub { {} },
 );
 
-before uploads => sub {
-  my ($self) = @_;
-  #$self->_context->prepare_body;
-};
+# modifier was a noop (groditi)
+# before uploads => sub {
+#   my ($self) = @_;
+#   #$self->_context->prepare_body;
+# };
 
 has parameters => (
   is => 'rw',
@@ -436,10 +445,6 @@ defaults to the size of the request if not specified.
 
 You have to set MyApp->config->{parse_on_demand} to use this directly.
 
-=cut
-
-sub read { shift->_context->read(@_); }
-
 =head2 $req->referer
 
 Shortcut for $req->headers->referer. Returns the referring page.
index b1bd4e6..4d46417 100644 (file)
@@ -1,5 +1,6 @@
 package Catalyst::Request::Upload;
 
+use Class::C3;
 use Moose;
 
 use Catalyst::Exception;
index 2c63ac7..3c71fde 100644 (file)
@@ -1,5 +1,6 @@
 package Catalyst::Response;
 
+use Class::C3;
 use Moose;
 use HTTP::Headers;
 
@@ -18,6 +19,7 @@ has headers   => (
 has _context => (
   is => 'rw',
   weak_ref => 1,
+  handles => ['write'],
 );
 
 sub output { shift->body(@_) }
@@ -153,10 +155,6 @@ Sets or returns the HTTP status.
 
 Writes $data to the output stream.
 
-=cut
-
-sub write { shift->_context->write(@_); }
-
 =head2 meta
 
 Provided by Moose
index a08bbbf..1e580c3 100644 (file)
@@ -65,6 +65,6 @@ the same terms as Perl itself.
 =cut
 
 no Moose;
-__PACKAGE__->meta->make_immutable();
+#__PACKAGE__->meta->make_immutable();
 
 1;