1 package Catalyst::DispatchType::Regex;
4 use base qw/Catalyst::DispatchType::Path/;
9 Catalyst::DispatchType::Regex - Regex DispatchType
19 =head2 $self->list($c)
21 Output a table of all regex actions, and their private equivalent.
26 my ( $self, $c ) = @_;
27 my $re = Text::SimpleTable->new( [ 35, 'Regex' ], [ 36, '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 =head2 $self->match( $c, $path )
38 Check path against compiled regexes, and set action to any matching
39 action. Returns 1 on success and 0 on failure.
44 my ( $self, $c, $path ) = @_;
46 return if $self->SUPER::match( $c, $path );
48 # Check path against plain text first
50 foreach my $compiled ( @{ $self->{compiled} || [] } ) {
51 if ( my @captures = ( $path =~ $compiled->{re} ) ) {
52 next unless $compiled->{action}->match($c);
53 $c->req->action( $compiled->{path} );
54 $c->req->match($path);
55 $c->req->captures( \@captures );
56 $c->action( $compiled->{action} );
57 $c->namespace( $compiled->{action}->namespace );
65 =head2 $self->register( $c, $action )
67 Registers one or more regex actions for an action object.\
68 Also registers them as literal paths.
70 Returns 1 on if any regexps were registered.
75 my ( $self, $c, $action ) = @_;
76 my $attrs = $action->attributes;
77 my @register = @{ $attrs->{'Regex'} || [] };
79 foreach my $r (@register) {
80 $self->register_path( $c, $r, $action );
81 $self->register_regex( $c, $r, $action );
84 return 1 if @register;
88 =head2 $self->register_regex($c, $re, $action)
90 Register an individual regex on the action. Usually called from the
96 my ( $self, $c, $re, $action ) = @_;
98 @{ $self->{compiled} }, # and compiled regex for us
110 Sebastian Riedel, C<sri@cpan.org>
114 This program is free software, you can redistribute it and/or modify it under
115 the same terms as Perl itself.