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 $action = $regex->{action};
30 $re->row( $regex->{path}, "/$action" );
32 $c->log->debug( "Loaded Regex actions:\n" . $re->draw )
33 if ( @{ $self->{compiled} } );
36 =item $self->match( $c, $path )
41 my ( $self, $c, $path ) = @_;
43 return if $self->SUPER::match( $c, $path );
45 # Check path against plain text first
47 foreach my $compiled ( @{ $self->{compiled} || [] } ) {
48 if ( my @snippets = ( $path =~ $compiled->{re} ) ) {
49 $c->req->action( $compiled->{path} );
50 $c->req->match($path);
51 $c->req->snippets( \@snippets );
52 $c->action( $compiled->{action} );
53 $c->namespace( $compiled->{action}->namespace );
61 =item $self->register( $c, $action )
66 my ( $self, $c, $action ) = @_;
67 my $attrs = $action->attributes;
68 my @register = map { @{ $_ || [] } } @{$attrs}{ 'Regex', 'Regexp' };
70 my $r ( map { @{ $_ || [] } } @{$attrs}{ 'LocalRegex', 'LocalRegexp' } )
72 unless ( $r =~ s/^\^// ) { $r = "(?:.*?)$r"; }
73 push( @register, '^' . $action->namespace . '/' . $r );
76 foreach my $r (@register) {
77 $self->register_path( $c, $r, $action );
78 $self->register_regex( $c, $r, $action );
80 return 1 if @register;
84 =item $self->register_regex($c, $re, $action)
89 my ( $self, $c, $re, $action ) = @_;
91 @{ $self->{compiled} }, # and compiled regex for us
105 Sebastian Riedel, C<sri@cpan.org>
109 This program is free software, you can redistribute it and/or modify it under
110 the same terms as Perl itself.