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 $c->req->action( $compiled->{path} );
48 $c->req->match($path);
49 $c->req->snippets( \@snippets );
50 $c->action( $compiled->{action} );
51 $c->namespace( $compiled->{action}->namespace );
59 =head2 $self->register( $c, $action )
64 my ( $self, $c, $action ) = @_;
65 my $attrs = $action->attributes;
66 my @register = map { @{ $_ || [] } } @{$attrs}{ 'Regex', 'Regexp' };
68 my $r ( map { @{ $_ || [] } } @{$attrs}{ 'LocalRegex', 'LocalRegexp' } )
70 unless ( $r =~ s/^\^// ) { $r = "(?:.*?)$r"; }
71 push( @register, '^' . $action->namespace . '/' . $r );
74 foreach my $r (@register) {
75 $self->register_path( $c, $r, $action );
76 $self->register_regex( $c, $r, $action );
78 return 1 if @register;
82 =head2 $self->register_regex($c, $re, $action)
87 my ( $self, $c, $re, $action ) = @_;
89 @{ $self->{compiled} }, # and compiled regex for us
101 Sebastian Riedel, C<sri@cpan.org>
105 This program is free software, you can redistribute it and/or modify it under
106 the same terms as Perl itself.