- Made Action accessor names more consistent (namespace -> class, prefix -> namespace)
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Path.pm
CommitLineData
6b239949 1package Catalyst::DispatchType::Path;
2
3use strict;
4use base qw/Catalyst::DispatchType/;
a9cbd748 5use Text::ASCIITable;
6b239949 6
2633d7dc 7=head1 NAME
8
9Catalyst::DispatchType::Path - Path DispatchType
10
11=head1 SYNOPSIS
12
13See L<Catalyst>.
14
15=head1 DESCRIPTION
16
17=head1 METHODS
18
19=over 4
20
a9cbd748 21=item $self->list($c)
22
23=cut
24
25sub list {
26 my ( $self, $c ) = @_;
27 my $paths = Text::ASCIITable->new;
2f484ed5 28 $paths->setCols( 'Path', 'Private' );
784ab0e4 29 $paths->setColWidth( 'Path', 36, 1 );
a9cbd748 30 $paths->setColWidth( 'Private', 37, 1 );
31 for my $path ( sort keys %{ $self->{paths} } ) {
32 my $action = $self->{paths}->{$path};
33 $paths->addRow( "/$path", "/$action" );
34 }
35 $c->log->debug( "Loaded Path actions:\n" . $paths->draw )
36 if ( @{ $paths->{tbl_rows} } );
37}
38
2633d7dc 39=item $self->match( $c, $path )
40
41=cut
42
43sub match {
44 my ( $self, $c, $path ) = @_;
6b239949 45
46 if ( my $action = $self->{paths}->{$path} ) {
47 $c->req->action($path);
48 $c->req->match($path);
49 $c->action($action);
11bd4e3e 50 $c->namespace( $action->namespace );
6b239949 51 return 1;
52 }
53
54 return 0;
55}
56
2633d7dc 57=item $self->register( $c, $action )
58
59=cut
60
61sub register {
6b239949 62 my ( $self, $c, $action ) = @_;
22f3a8dd 63
6b239949 64 my $attrs = $action->attributes;
65 my @register;
22f3a8dd 66
2633d7dc 67 foreach my $r ( @{ $attrs->{Path} || [] } ) {
68 unless ( $r =~ m!^/! ) { # It's a relative path
11bd4e3e 69 $r = $action->namespace . "/$r";
6b239949 70 }
2633d7dc 71 push( @register, $r );
6b239949 72 }
73
2633d7dc 74 if ( $attrs->{Global} || $attrs->{Absolute} ) {
75 push( @register, $action->name ); # Register sub name against root
6b239949 76 }
77
2633d7dc 78 if ( $attrs->{Local} || $attrs->{Relative} ) {
11bd4e3e 79 push( @register, join( '/', $action->namespace, $action->name ) );
2633d7dc 80
81 # Register sub name as a relative path
6b239949 82 }
83
84 foreach my $r (@register) {
85 $r =~ s!^/!!;
86 $self->{paths}{$r} = $action;
87 }
88}
89
2633d7dc 90=back
91
92=head1 AUTHOR
93
94Matt S Trout
95Sebastian Riedel, C<sri@cpan.org>
96
97=head1 COPYRIGHT
98
99This program is free software, you can redistribute it and/or modify it under
100the same terms as Perl itself.
101
102=cut
103
6b239949 1041;