1 package Catalyst::DispatchType::Regex;
4 use base qw/Catalyst::DispatchType::Path/;
9 Catalyst::DispatchType::Regex - Regex DispatchType
19 =head2 $self->list($c)
24 my ( $self, $c ) = @_;
25 my $re = Text::SimpleTable->new( [ 36, 'Regex' ], [ 37, 'Private' ] );
26 for my $regex ( @{ $self->{compiled} } ) {
27 my $action = $regex->{action};
28 $re->row( $regex->{path}, "/$action" );
30 $c->log->debug( "Loaded Regex actions:\n" . $re->draw )
31 if ( @{ $self->{compiled} } );
34 =head2 $self->match( $c, $path )
39 my ( $self, $c, $path ) = @_;
41 return if $self->SUPER::match( $c, $path );
43 # Check path against plain text first
45 foreach my $compiled ( @{ $self->{compiled} || [] } ) {
46 if ( my @snippets = ( $path =~ $compiled->{re} ) ) {
47 next unless $compiled->{action}->match($c);
48 $c->req->action( $compiled->{path} );
49 $c->req->match($path);
50 $c->req->snippets( \@snippets );
51 $c->action( $compiled->{action} );
52 $c->namespace( $compiled->{action}->namespace );
60 =head2 $self->register( $c, $action )
65 my ( $self, $c, $action ) = @_;
66 my $attrs = $action->attributes;
67 my @register = @{ $attrs->{'Regex'} || [] };
69 foreach my $r (@register) {
70 $self->register_path( $c, $r, $action );
71 $self->register_regex( $c, $r, $action );
74 return 1 if @register;
78 =head2 $self->register_regex($c, $re, $action)
83 my ( $self, $c, $re, $action ) = @_;
85 @{ $self->{compiled} }, # and compiled regex for us
97 Sebastian Riedel, C<sri@cpan.org>
101 This program is free software, you can redistribute it and/or modify it under
102 the same terms as Perl itself.