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::ASCIITable->new;
28 $re->setCols( 'Regex', 'Private' );
29 $re->setColWidth( 'Regex', 36, 1 );
30 $re->setColWidth( 'Private', 37, 1 );
31 for my $regex ( @{ $self->{compiled} } ) {
32 my $compiled = $regex->{re};
33 my $action = $regex->{action};
34 $re->addRow( $compiled, "/$action" );
36 $c->log->debug( "Loaded Regex actions:\n" . $re->draw )
37 if ( @{ $re->{tbl_rows} } );
40 =item $self->match( $c, $path )
45 my ( $self, $c, $path ) = @_;
47 return if $self->SUPER::match( $c, $path );
49 # Check path against plain text first
51 foreach my $compiled ( @{ $self->{compiled} || [] } ) {
52 if ( my @snippets = ( $path =~ $compiled->{re} ) ) {
53 $c->req->action( $compiled->{path} );
54 $c->req->match($path);
55 $c->req->snippets( \@snippets );
56 $c->action( $compiled->{action} );
57 $c->namespace( $compiled->{action}->namespace );
65 =item $self->register( $c, $action )
70 my ( $self, $c, $action ) = @_;
71 my $attrs = $action->attributes;
72 my @register = map { @{ $_ || [] } } @{$attrs}{ 'Regex', 'Regexp' };
73 foreach my $r (@register) {
74 unless ($r =~ /^\^/) { # Relative regex
75 $r = '^'.$action->namespace.'/'.$r;
77 $self->{paths}{$r} = $action; # Register path for superclass
79 @{ $self->{compiled} }, # and compiled regex for us
94 Sebastian Riedel, C<sri@cpan.org>
98 This program is free software, you can redistribute it and/or modify it under
99 the same terms as Perl itself.