From: Guillermo Roditi Date: Mon, 23 Jun 2008 21:20:34 +0000 (+0000) Subject: bye bye Class::C3. for good. X-Git-Tag: 5.8000_03~94 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=4090e3bb3fea1a73ac369250e31584d61428b808 bye bye Class::C3. for good. r18299@martha (orig r7827): groditi | 2008-05-27 22:42:31 -0400 --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 28b8a27..0d51b1d 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1,7 +1,5 @@ package Catalyst; -use MRO::Compat; -use mro 'c3'; use Moose; extends 'Catalyst::Component'; use bytes; @@ -41,8 +39,6 @@ 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 || [] }; } @@ -376,19 +372,20 @@ Catalyst). =cut -sub stash { +around stash => sub { + my $orig = shift; my $c = shift; + my $stash = $orig->($c); if (@_) { - my $stash = @_ > 1 ? {@_} : $_[0]; - croak('stash takes a hash or hashref') unless ref $stash; - foreach my $key ( keys %$stash ) { - #shouldn't we hold this in a var and save ourselves the subcall? - $c->next::method->{$key} = $stash->{$key}; + my $new_stash = @_ > 1 ? {@_} : $_[0]; + croak('stash takes a hash or hashref') unless ref $new_stash; + foreach my $key ( keys %$new_stash ) { + $stash->{$key} = $new_stash->{$key}; } } - return $c->next::method; -} + return $stash; +}; =head2 $c->error @@ -701,14 +698,15 @@ L. =cut -sub config { +around config => sub { + my $orig = shift; my $c = shift; $c->log->warn("Setting config after setup has been run is not a good idea.") if ( @_ and $c->setup_finished ); - $c->next::method(@_); -} + $c->$orig(@_); +}; =head2 $c->log @@ -814,7 +812,6 @@ Catalyst> line. sub setup { my ( $class, @arguments ) = @_; - Class::C3::initialize; $class->log->warn("Running setup twice is not a good idea.") if ( $class->setup_finished ); @@ -936,7 +933,6 @@ EOF $class->log->_flush() if $class->log->can('_flush'); $class->setup_finished(1); - Class::C3::initialize; } =head2 $c->uri_for( $path, @args?, \%query_values? ) @@ -2451,4 +2447,6 @@ the same terms as Perl itself. =cut +no Moose; + 1; diff --git a/lib/Catalyst/Action.pm b/lib/Catalyst/Action.pm index b426530..6758e86 100644 --- a/lib/Catalyst/Action.pm +++ b/lib/Catalyst/Action.pm @@ -17,8 +17,6 @@ L subclasses. =cut -use MRO::Compat; -use mro 'c3'; use Moose; has class => (is => 'rw'); diff --git a/lib/Catalyst/ActionChain.pm b/lib/Catalyst/ActionChain.pm index 692065a..d9fb623 100644 --- a/lib/Catalyst/ActionChain.pm +++ b/lib/Catalyst/ActionChain.pm @@ -1,7 +1,5 @@ package Catalyst::ActionChain; -use MRO::Compat; -use mro 'c3'; use Moose; extends qw(Catalyst::Action); diff --git a/lib/Catalyst/ActionContainer.pm b/lib/Catalyst/ActionContainer.pm index 61fd0a9..f3cb7e0 100644 --- a/lib/Catalyst/ActionContainer.pm +++ b/lib/Catalyst/ActionContainer.pm @@ -15,21 +15,17 @@ to represent the various dispatch points in your application. =cut -use MRO::Compat; -use mro 'c3'; use Moose; has part => (is => 'rw', required => 1, lazy => 1, default => sub { {} }); has actions => (is => 'rw', required => 1, lazy => 1, default => sub { {} }); -no Moose; - -sub new { - my ($self, $params) = @_; - $params = { part => $params } unless ref $params; - $self->next::method($params); -} +around new => sub { + my ($orig, $self, $params) = @_; + $orig->($self, (ref($params) ? $params : { part => $params } )); +}; +no Moose; sub get_action { my ( $self, $name ) = @_; diff --git a/lib/Catalyst/Base.pm b/lib/Catalyst/Base.pm index 1819eb8..42e70db 100644 --- a/lib/Catalyst/Base.pm +++ b/lib/Catalyst/Base.pm @@ -1,9 +1,7 @@ package Catalyst::Base; -use MRO::Compat; -use mro 'c3'; +use base qw/Catalyst::Controller/; use Moose; -BEGIN{ extends qw/Catalyst::Controller/ }; no Moose; 1; diff --git a/lib/Catalyst/Component.pm b/lib/Catalyst/Component.pm index 7de7e4e..876f682 100644 --- a/lib/Catalyst/Component.pm +++ b/lib/Catalyst/Component.pm @@ -1,16 +1,12 @@ package Catalyst::Component; -use MRO::Compat; -use mro 'c3'; use Moose; use MooseX::Adopt::Class::Accessor::Fast; use Catalyst::Utils; - with 'MooseX::Emulate::Class::Accessor::Fast'; with 'Catalyst::ClassData'; -no Moose; =head1 NAME @@ -57,32 +53,24 @@ component loader with config() support and a process() method placeholder. __PACKAGE__->mk_classdata($_) for qw/_config _plugins/; -sub new { - my ( $self, $c ) = @_; +around new => sub { + my ( $orig, $self) = @_; # 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 ); - $self->next::method( $args ); -} + $self->$orig( $args ); +}; + +no Moose; sub COMPONENT { my ( $self, $c ) = @_; # Temporary fix, some components does not pass context to constructor my $arguments = ( ref( $_[-1] ) eq 'HASH' ) ? $_[-1] : {}; - - - #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); + return $self->new($c, $arguments); } sub config { diff --git a/lib/Catalyst/Controller.pm b/lib/Catalyst/Controller.pm index 703a156..2e0bbba 100644 --- a/lib/Catalyst/Controller.pm +++ b/lib/Catalyst/Controller.pm @@ -1,8 +1,6 @@ package Catalyst::Controller; #switch to BEGIN { extends qw/ ... /; } ? -use MRO::Compat; -use mro 'c3'; use base qw/Catalyst::Component Catalyst::AttrContainer/; use Moose; @@ -124,13 +122,14 @@ sub _END : Private { return !@{ $c->error }; } -sub new { +around new => sub { + my $orig = shift; my $self = shift; my $app = $_[0]; - my $new = $self->next::method(@_); + my $new = $self->$orig(@_); $new->_application( $app ); return $new; -} +}; sub action_for { my ( $self, $name ) = @_; @@ -147,7 +146,7 @@ around action_namespace => sub { if( ref($self) ){ return $self->$orig if $self->has_action_namespace; - } else { + } else { return $self->config->{namespace} if exists $self->config->{namespace}; } diff --git a/lib/Catalyst/DispatchType.pm b/lib/Catalyst/DispatchType.pm index 874963a..d763eb6 100644 --- a/lib/Catalyst/DispatchType.pm +++ b/lib/Catalyst/DispatchType.pm @@ -1,7 +1,5 @@ package Catalyst::DispatchType; -use MRO::Compat; -use mro 'c3'; use Moose; # using it to add Moose::Object to @ISA ... no Moose; diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index a65a198..2e45b29 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -1,7 +1,5 @@ package Catalyst::DispatchType::Chained; -use MRO::Compat; -use mro 'c3'; use Moose; extends 'Catalyst::DispatchType'; diff --git a/lib/Catalyst/DispatchType/Default.pm b/lib/Catalyst/DispatchType/Default.pm index 8984749..ecc6e38 100644 --- a/lib/Catalyst/DispatchType/Default.pm +++ b/lib/Catalyst/DispatchType/Default.pm @@ -1,7 +1,5 @@ package Catalyst::DispatchType::Default; -use MRO::Compat; -use mro 'c3'; use Moose; extends 'Catalyst::DispatchType'; diff --git a/lib/Catalyst/DispatchType/Index.pm b/lib/Catalyst/DispatchType/Index.pm index ea44684..b6b649b 100644 --- a/lib/Catalyst/DispatchType/Index.pm +++ b/lib/Catalyst/DispatchType/Index.pm @@ -1,7 +1,5 @@ package Catalyst::DispatchType::Index; -use MRO::Compat; -use mro 'c3'; use Moose; extends 'Catalyst::DispatchType'; no Moose; diff --git a/lib/Catalyst/DispatchType/Path.pm b/lib/Catalyst/DispatchType/Path.pm index 98e3b97..fd65523 100644 --- a/lib/Catalyst/DispatchType/Path.pm +++ b/lib/Catalyst/DispatchType/Path.pm @@ -1,7 +1,5 @@ package Catalyst::DispatchType::Path; -use MRO::Compat; -use mro 'c3'; use Moose; extends 'Catalyst::DispatchType'; diff --git a/lib/Catalyst/DispatchType/Regex.pm b/lib/Catalyst/DispatchType/Regex.pm index ea46f11..f6d0606 100644 --- a/lib/Catalyst/DispatchType/Regex.pm +++ b/lib/Catalyst/DispatchType/Regex.pm @@ -1,7 +1,5 @@ package Catalyst::DispatchType::Regex; -use MRO::Compat; -use mro 'c3'; use Moose; extends 'Catalyst::DispatchType::Path'; diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index fd9410b..7c5134b 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -1,7 +1,5 @@ package Catalyst::Dispatcher; -use MRO::Compat; -use mro 'c3'; use Moose; use Class::MOP; diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 3514770..814238d 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -1,7 +1,5 @@ package Catalyst::Engine; -use MRO::Compat; -use mro 'c3'; use Moose; with 'MooseX::Emulate::Class::Accessor::Fast'; diff --git a/lib/Catalyst/Engine/CGI.pm b/lib/Catalyst/Engine/CGI.pm index d04fea4..2fcc8f8 100644 --- a/lib/Catalyst/Engine/CGI.pm +++ b/lib/Catalyst/Engine/CGI.pm @@ -1,14 +1,10 @@ package Catalyst::Engine::CGI; -use MRO::Compat; -use mro 'c3'; use Moose; extends 'Catalyst::Engine'; has env => (is => 'rw'); -no Moose; - =head1 NAME Catalyst::Engine::CGI - The CGI Engine @@ -176,14 +172,15 @@ sub prepare_path { =cut -sub prepare_query_parameters { +around prepare_query_parameters => sub { + my $orig = shift; my ( $self, $c ) = @_; local (*ENV) = $self->env || \%ENV; if ( $ENV{QUERY_STRING} ) { - $self->next::method( $c, $ENV{QUERY_STRING} ); + $self->$orig( $c, $ENV{QUERY_STRING} ); } -} +}; =head2 $self->prepare_request($c, (env => \%env)) @@ -203,10 +200,10 @@ Enable autoflush on the output handle for CGI-based engines. =cut -sub prepare_write { +around prepare_write => sub { *STDOUT->autoflush(1); - return shift->next::method(@_); -} + return shift->(@_); +}; =head2 $self->write($c, $buffer) @@ -214,7 +211,8 @@ Writes the buffer to the client. =cut -sub write { +around write => sub { + my $orig = shift; my ( $self, $c, $buffer ) = @_; # Prepend the headers if they have not yet been sent @@ -222,8 +220,8 @@ sub write { $buffer = $headers . $buffer; } - return $self->next::method( $c, $buffer ); -} + return $self->$orig( $c, $buffer ); +}; =head2 $self->read_chunk($c, $buffer, $length) @@ -255,5 +253,6 @@ This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =cut +no Moose; 1; diff --git a/lib/Catalyst/Engine/FastCGI.pm b/lib/Catalyst/Engine/FastCGI.pm index 397bdc0..7a09509 100644 --- a/lib/Catalyst/Engine/FastCGI.pm +++ b/lib/Catalyst/Engine/FastCGI.pm @@ -1,7 +1,5 @@ package Catalyst::Engine::FastCGI; -use MRO::Compat; -use mro 'c3'; use Moose; extends 'Catalyst::Engine::CGI'; diff --git a/lib/Catalyst/Engine/HTTP.pm b/lib/Catalyst/Engine/HTTP.pm index 80645e6..fb40d6f 100644 --- a/lib/Catalyst/Engine/HTTP.pm +++ b/lib/Catalyst/Engine/HTTP.pm @@ -1,10 +1,7 @@ package Catalyst::Engine::HTTP; -use MRO::Compat; -use mro 'c3'; use Moose; extends 'Catalyst::Engine::CGI'; -no Moose; use Data::Dump qw(dump); use Errno 'EWOULDBLOCK'; @@ -87,22 +84,22 @@ sub finalize_headers { =cut -sub finalize_read { +around finalize_read => sub { # 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(@_); -} + shift->(@_); +}; =head2 $self->prepare_read($c) =cut -sub prepare_read { +around prepare_read => sub { # Set the input handle to non-blocking *STDIN->blocking(0); - shift->next::method(@_); -} + shift->(@_); +}; =head2 $self->read_chunk($c, $buffer, $length) @@ -144,7 +141,8 @@ Writes the buffer to the client. =cut -sub write { +around write => sub { + my $orig = shift; my ( $self, $c, $buffer ) = @_; # Avoid 'print() on closed filehandle Remote' warnings when using IE @@ -155,7 +153,7 @@ sub write { $buffer = $headers . $buffer; } - my $ret = $self->next::method($c, $buffer); + my $ret = $self->$orig($c, $buffer); if ( !defined $ret ) { $self->{_write_error} = $!; @@ -166,7 +164,7 @@ sub write { } return $ret; -} +}; =head2 run @@ -527,6 +525,8 @@ sub _socket_data { sub _inet_addr { unpack "N*", inet_aton( $_[0] ) } +no Moose; + =head1 SEE ALSO L, L. diff --git a/lib/Catalyst/Engine/HTTP/Restarter.pm b/lib/Catalyst/Engine/HTTP/Restarter.pm index 3eb7d04..4691cad 100644 --- a/lib/Catalyst/Engine/HTTP/Restarter.pm +++ b/lib/Catalyst/Engine/HTTP/Restarter.pm @@ -1,14 +1,12 @@ package Catalyst::Engine::HTTP::Restarter; -use MRO::Compat; -use mro 'c3'; use Moose; extends 'Catalyst::Engine::HTTP'; -no Moose; use Catalyst::Engine::HTTP::Restarter::Watcher; -sub run { +around run => sub { + my $orig = shift; my ( $self, $class, $port, $host, $options ) = @_; $options ||= {}; @@ -69,7 +67,8 @@ sub run { } } - return $self->next::method( $class, $port, $host, $options ); + return $self->$orig( $class, $port, $host, $options ); + no Moose; }; 1; diff --git a/lib/Catalyst/Log.pm b/lib/Catalyst/Log.pm index a45fb59..e1953b2 100644 --- a/lib/Catalyst/Log.pm +++ b/lib/Catalyst/Log.pm @@ -1,7 +1,5 @@ package Catalyst::Log; -use MRO::Compat; -use mro 'c3'; use Moose; use Data::Dump; @@ -14,6 +12,7 @@ has abort => (is => 'rw'); { my @levels = qw[ debug info warn error fatal ]; + my $meta = __PACKAGE__->meta; for ( my $i = 0 ; $i < @levels ; $i++ ) { my $name = $levels[$i]; @@ -21,29 +20,28 @@ has abort => (is => 'rw'); $LEVELS{$name} = $level; - no strict 'refs'; - - *{$name} = sub { + $meta->add_method($name, sub { my $self = shift; if ( $self->level & $level ) { $self->_log( $name, @_ ); } - }; + }); - *{"is_$name"} = sub { + $meta->add_method("is_$name", sub { my $self = shift; return $self->level & $level; - }; + });; } } -sub new { +around new => sub { + my $orig = shift; my $class = shift; - my $self = $class->next::method; + my $self = $class->$orig; $self->levels( scalar(@_) ? @_ : keys %LEVELS ); return $self; -} +}; sub levels { my ( $self, @levels ) = @_; diff --git a/lib/Catalyst/Model.pm b/lib/Catalyst/Model.pm index 20ae37c..896e3ae 100644 --- a/lib/Catalyst/Model.pm +++ b/lib/Catalyst/Model.pm @@ -1,7 +1,5 @@ package Catalyst::Model; -use MRO::Compat; -use mro 'c3'; use Moose; extends qw/Catalyst::Component/; diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index 33add7b..e6f0a00 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -1,7 +1,5 @@ package Catalyst::Request; -use MRO::Compat; -use mro 'c3'; use IO::Socket qw[AF_INET inet_aton]; use Carp; use utf8; diff --git a/lib/Catalyst/Request/Upload.pm b/lib/Catalyst/Request/Upload.pm index 9080f9a..b1bd4e6 100644 --- a/lib/Catalyst/Request/Upload.pm +++ b/lib/Catalyst/Request/Upload.pm @@ -1,7 +1,5 @@ package Catalyst::Request::Upload; -use MRO::Compat; -use mro 'c3'; use Moose; use Catalyst::Exception; diff --git a/lib/Catalyst/Response.pm b/lib/Catalyst/Response.pm index 387cd27..9c610d4 100644 --- a/lib/Catalyst/Response.pm +++ b/lib/Catalyst/Response.pm @@ -1,7 +1,5 @@ package Catalyst::Response; -use MRO::Compat; -use mro 'c3'; use Moose; use HTTP::Headers; diff --git a/lib/Catalyst/View.pm b/lib/Catalyst/View.pm index ef5a447..1e580c3 100644 --- a/lib/Catalyst/View.pm +++ b/lib/Catalyst/View.pm @@ -1,7 +1,5 @@ package Catalyst::View; -use MRO::Compat; -use mro 'c3'; use Moose; extends qw/Catalyst::Component/;