From: Matt S Trout Date: Mon, 27 Feb 2006 01:41:13 +0000 (+0000) Subject: Refactored Regex actions X-Git-Tag: 5.7099_04~690 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=27708fc5f90d4794f082348049ac894f58224fad Refactored Regex actions --- diff --git a/lib/Catalyst/Base.pm b/lib/Catalyst/Base.pm index addc3ae..7536dc6 100644 --- a/lib/Catalyst/Base.pm +++ b/lib/Catalyst/Base.pm @@ -86,6 +86,12 @@ sub action_namespace { || ''; } +=head2 $self->path_prefix($c) + +=cut + +sub path_prefix { shift->action_namespace(@_); } + =head2 $self->register_actions($c) =cut @@ -163,27 +169,44 @@ sub _parse_Global_attr { return $self->_parse_Path_attr( $c, $name, "/$name" ); } -*_parse_Absolute_attr = \&_parse_Global_attr; +sub _parse_Absolute_attr { shift->_parse_Global_attr(@_); } sub _parse_Local_attr { my ( $self, $c, $name, $value ) = @_; return $self->_parse_Path_attr( $c, $name, $name ); } -*_parse_Relative_attr = \&_parse_Local_attr; +sub _parse_Relative_attr { shift->_parse_Local_attr(@_); } sub _parse_Path_attr { my ( $self, $c, $name, $value ) = @_; $value ||= ''; if ( $value =~ m!^/! ) { return ( 'Path', $value ); - } elsif ( length $value ) { - return ( 'Path', join( '/', $self->action_namespace($c), $value ) ); - } else { - return ( 'Path', $self->action_namespace($c) ); } + elsif ( length $value ) { + return ( 'Path', join( '/', $self->path_prefix($c), $value ) ); + } + else { + return ( 'Path', $self->path_prefix($c) ); + } +} + +sub _parse_Regex_attr { + my ( $self, $c, $name, $value ) = @_; + return ( 'Regex', $value ); } +sub _parse_Regexp_attr { shift->_parse_Regex_attr(@_); } + +sub _parse_LocalRegex_attr { + my ( $self, $c, $name, $value ) = @_; + unless ( $value =~ s/^\^// ) { $value = "(?:.*?)$value"; } + return ( 'Regex', '^' . $self->path_prefix($c) . "/${value}" ); +} + +sub _parse_LocalRegexp_attr { shift->_parse_LocalRegex_attr(@_); } + =head1 SEE ALSO L, L. diff --git a/lib/Catalyst/DispatchType/Path.pm b/lib/Catalyst/DispatchType/Path.pm index 9cd1a15..bd74c79 100644 --- a/lib/Catalyst/DispatchType/Path.pm +++ b/lib/Catalyst/DispatchType/Path.pm @@ -60,7 +60,7 @@ sub match { sub register { my ( $self, $c, $action ) = @_; - my @register = @{$action->attributes->{Path}||[]}; + my @register = @{ $action->attributes->{Path} || [] }; $self->register_path( $c, $_, $action ) for @register; @@ -77,6 +77,7 @@ sub register_path { $path =~ s!^/!!; $path = '/' unless length $path; $path = URI->new($path)->canonical; + $self->{paths}{$path} = $action; } diff --git a/lib/Catalyst/DispatchType/Regex.pm b/lib/Catalyst/DispatchType/Regex.pm index 49f7636..520e038 100644 --- a/lib/Catalyst/DispatchType/Regex.pm +++ b/lib/Catalyst/DispatchType/Regex.pm @@ -64,18 +64,13 @@ sub match { sub register { my ( $self, $c, $action ) = @_; my $attrs = $action->attributes; - my @register = map { @{ $_ || [] } } @{$attrs}{ 'Regex', 'Regexp' }; - foreach - my $r ( map { @{ $_ || [] } } @{$attrs}{ 'LocalRegex', 'LocalRegexp' } ) - { - unless ( $r =~ s/^\^// ) { $r = "(?:.*?)$r"; } - push( @register, '^' . $action->namespace . '/' . $r ); - } + my @register = @{ $attrs->{'Regex'} || [] }; foreach my $r (@register) { $self->register_path( $c, $r, $action ); $self->register_regex( $c, $r, $action ); } + return 1 if @register; return 0; }