From: Guillermo Roditi Date: Mon, 23 Jun 2008 21:19:36 +0000 (+0000) Subject: Remove use of overload X-Git-Tag: 5.8000_03~98 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=f3414019f472b55682ef3af53f761b6db7955887;hp=8c80e4f8ed93daf2d635c0480bdc97adf24e49c1 Remove use of overload Fixup some tests Fixup some areas of code r17834@martha (orig r7765): konobi | 2008-05-20 04:11:55 -0400 --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index c3ff12c..e22ff81 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1234,9 +1234,9 @@ sub execute { $c->state(0); if ( $c->depth >= $RECURSION ) { - my $action = "$code"; + my $action = $code->reverse(); $action = "/$action" unless $action =~ /->/; - my $error = qq/Deep recursion detected calling "$action"/; + my $error = qq/Deep recursion detected calling "${action}"/; $c->log->error($error); $c->error($error); $c->state(0); @@ -1247,7 +1247,7 @@ sub execute { push( @{ $c->stack }, $code ); - eval { $c->state( &$code( $class, $c, @{ $c->req->args } ) || 0 ) }; + eval { $c->state( $code->execute( $class, $c, @{ $c->req->args } ) || 0 ) }; $c->_stats_finish_execute( $stats_info ) if $c->use_stats and $stats_info; @@ -1276,9 +1276,10 @@ sub _stats_start_execute { return if ( ( $code->name =~ /^_.*/ ) && ( !$c->config->{show_internal_actions} ) ); - $c->counter->{"$code"}++; + my $action_name = $code->reverse(); + $c->counter->{$action_name}++; - my $action = "$code"; + my $action = $action_name; $action = "/$action" unless $action =~ /->/; # determine if the call was the result of a forward @@ -1297,7 +1298,7 @@ sub _stats_start_execute { } } - my $uid = "$code" . $c->counter->{"$code"}; + my $uid = $action_name . $c->counter->{$action_name}; # is this a root-level call or a forwarded call? if ( $callsub =~ /forward$/ ) { diff --git a/lib/Catalyst/Action.pm b/lib/Catalyst/Action.pm index 640a209..a74eb29 100644 --- a/lib/Catalyst/Action.pm +++ b/lib/Catalyst/Action.pm @@ -33,19 +33,6 @@ no warnings 'recursion'; #__PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/); -use overload ( - - # Stringify to reverse for debug output etc. - q{""} => sub { shift->reverse() }, - - # Codulate to execute to invoke the encapsulated action coderef - '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; }, - - # Make general $stuff still work - fallback => 1, - -); - sub dispatch { # Execute ourselves against a context my ( $self, $c ) = @_; #Moose todo: grrrrrr. this is no good. i don't know enough about it to diff --git a/lib/Catalyst/ActionChain.pm b/lib/Catalyst/ActionChain.pm index 3c0b49b..450c88e 100644 --- a/lib/Catalyst/ActionChain.pm +++ b/lib/Catalyst/ActionChain.pm @@ -24,20 +24,6 @@ the actions in the chain in order. =cut -use overload ( - - # Stringify to reverse for debug output etc. - q{""} => sub { shift->{reverse} }, - - # Codulate to execute to invoke the encapsulated action coderef - '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; }, - - # Make general $stuff still work - fallback => 1, - -); - - sub dispatch { my ( $self, $c ) = @_; my @captures = @{$c->req->captures||[]}; diff --git a/lib/Catalyst/ActionContainer.pm b/lib/Catalyst/ActionContainer.pm index a51f90a..31e36cd 100644 --- a/lib/Catalyst/ActionContainer.pm +++ b/lib/Catalyst/ActionContainer.pm @@ -18,13 +18,6 @@ to represent the various dispatch points in your application. use Class::C3; use Moose; -use overload ( - - # Stringify to path part for tree search - q{""} => sub { shift->part }, - -); - has part => (is => 'rw', required => 1, lazy => 1, default => sub { {} }); has actions => (is => 'rw', required => 1, lazy => 1, default => sub { {} }); diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index 3b72e15..5bf3853 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -268,13 +268,13 @@ sub register { $part = $path_part[0]; } elsif (@path_part > 1) { Catalyst::Exception->throw( - "Multiple PathPart attributes not supported registering ${action}" + "Multiple PathPart attributes not supported registering " . $action->reverse() ); } if ($part =~ m(^/)) { Catalyst::Exception->throw( - "Absolute parameters to PathPart not allowed registering ${action}" + "Absolute parameters to PathPart not allowed registering " . $action->reverse() ); } diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 99c432a..7c5134b 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -14,10 +14,6 @@ use Tree::Simple; use Tree::Simple::Visitor::FindByPath; use Scalar::Util (); -# Stringify to class -use overload '""' => sub { return ref(shift) }, fallback => 1; - - #do these belong as package vars or should we build these via a builder method? # Preload these action types our @PRELOAD = qw/Index Path Regex/; diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 8b3a701..0389367 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -19,9 +19,6 @@ has read_position => (is => 'rw'); no Moose; -# Stringify to class -use overload '""' => sub { return ref shift }, fallback => 1; - # Amount of data to read from input on each pass our $CHUNKSIZE = 64 * 1024; diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm index f18228c..a46ecb1 100644 --- a/t/lib/TestApp.pm +++ b/t/lib/TestApp.pm @@ -29,7 +29,7 @@ sub global_action : Private { sub execute { my $c = shift; my $class = ref( $c->component( $_[0] ) ) || $_[0]; - my $action = "$_[1]"; + my $action = $_[1]->reverse; my $method; @@ -98,4 +98,4 @@ use strict; use base qw/Catalyst::Base Class::Data::Inheritable/; -1; \ No newline at end of file +1; diff --git a/t/lib/TestAppDoubleAutoBug.pm b/t/lib/TestAppDoubleAutoBug.pm index 5c72461..00855cd 100644 --- a/t/lib/TestAppDoubleAutoBug.pm +++ b/t/lib/TestAppDoubleAutoBug.pm @@ -18,7 +18,7 @@ __PACKAGE__->setup; sub execute { my $c = shift; my $class = ref( $c->component( $_[0] ) ) || $_[0]; - my $action = "$_[1]"; + my $action = $_[1]->reverse(); my $method; diff --git a/t/live_stats.t b/t/live_stats.t index 48bffd1..a8c9c13 100644 --- a/t/live_stats.t +++ b/t/live_stats.t @@ -23,7 +23,7 @@ else { { ok( my $response = request('http://localhost/'), 'Request' ); ok( $response->is_success, 'Response Successful 2xx' ); - ok( $response->content =~ m/\/default.*?[\d.]+s.*- test.*[\d.]+s/s, 'Stats report'); + like( $response->content, qr/\/default.*?[\d.]+s.*- test.*[\d.]+s/s, 'Stats report'); }