1 package Catalyst::DispatchType::Regex;
4 use base qw/Catalyst::DispatchType::Path/;
9 Catalyst::DispatchType::Regex - Regex DispatchType
26 my ( $self, $c ) = @_;
27 my $re = Text::SimpleTable->new( [ 36, 'Regex' ], [ 37, 'Private' ] );
28 for my $regex ( @{ $self->{compiled} } ) {
29 my $compiled = $regex->{re};
30 my $action = $regex->{action};
31 $re->row( $compiled, "/$action" );
33 $c->log->debug( "Loaded Regex actions:\n" . $re->draw )
34 if ( @{ $self->{compiled} } );
37 =item $self->match( $c, $path )
42 my ( $self, $c, $path ) = @_;
44 return if $self->SUPER::match( $c, $path );
46 # Check path against plain text first
48 foreach my $compiled ( @{ $self->{compiled} || [] } ) {
49 if ( my @snippets = ( $path =~ $compiled->{re} ) ) {
50 $c->req->action( $compiled->{path} );
51 $c->req->match($path);
52 $c->req->snippets( \@snippets );
53 $c->action( $compiled->{action} );
54 $c->namespace( $compiled->{action}->namespace );
62 =item $self->register( $c, $action )
67 my ( $self, $c, $action ) = @_;
68 my $attrs = $action->attributes;
69 my @register = map { @{ $_ || [] } } @{$attrs}{ 'Regex', 'Regexp' };
70 foreach my $r (@register) {
71 unless ( $r =~ /^\^/ ) { # Relative regex
72 $r = '^' . $action->namespace . '/' . $r;
74 $self->{paths}{$r} = $action; # Register path for superclass
76 @{ $self->{compiled} }, # and compiled regex for us
91 Sebastian Riedel, C<sri@cpan.org>
95 This program is free software, you can redistribute it and/or modify it under
96 the same terms as Perl itself.