Cleaned all new classes
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Regex.pm
CommitLineData
b96f127f 1package Catalyst::DispatchType::Regex;
2
3use strict;
6b239949 4use base qw/Catalyst::DispatchType::Path/;
b96f127f 5
2633d7dc 6=head1 NAME
b96f127f 7
2633d7dc 8Catalyst::DispatchType::Regex - Regex DispatchType
b96f127f 9
2633d7dc 10=head1 SYNOPSIS
11
12See L<Catalyst>.
13
14=head1 DESCRIPTION
15
16=head1 METHODS
17
18=over 4
19
20=item $self->match( $c, $path )
21
22=cut
23
24sub match {
25 my ( $self, $c, $path ) = @_;
26
27 return if $self->SUPER::match( $c, $path );
28
29 # Check path against plain text first
30
31 foreach my $compiled ( @{ $self->{compiled} || [] } ) {
b96f127f 32 if ( my @snippets = ( $path =~ $compiled->{re} ) ) {
2633d7dc 33 $c->req->action( $compiled->{path} );
b96f127f 34 $c->req->match($path);
2633d7dc 35 $c->req->snippets( \@snippets );
36 $c->action( $compiled->{action} );
37 $c->namespace( $compiled->{action}->prefix );
b96f127f 38 return 1;
39 }
40 }
41
42 return 0;
43}
44
2633d7dc 45=item $self->register( $c, $action )
46
47=cut
48
49sub register {
b96f127f 50 my ( $self, $c, $action ) = @_;
51 my $attrs = $action->attributes;
2633d7dc 52 my @register = map { @{ $_ || [] } } @{$attrs}{ 'Regex', 'Regexp' };
b96f127f 53 foreach my $r (@register) {
2633d7dc 54 $self->{paths}{$r} = $action; # Register path for superclass
55 push(
56 @{ $self->{compiled} }, # and compiled regex for us
b96f127f 57 {
2633d7dc 58 re => qr#$r#,
b96f127f 59 action => $action,
2633d7dc 60 path => $r,
61 }
62 );
b96f127f 63 }
64}
65
2633d7dc 66=back
67
68=head1 AUTHOR
69
70Matt S Trout
71Sebastian Riedel, C<sri@cpan.org>
72
73=head1 COPYRIGHT
74
75This program is free software, you can redistribute it and/or modify it under
76the same terms as Perl itself.
77
78=cut
79
b96f127f 801;