- Made Catalyst::Action and ActionContainer default rather than hardcoded
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Path.pm
CommitLineData
6b239949 1package Catalyst::DispatchType::Path;
2
3use strict;
4use base qw/Catalyst::DispatchType/;
8c113188 5use Text::SimpleTable;
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 ) = @_;
8c113188 27 my $paths = Text::SimpleTable->new( [ 36, 'Path' ], [ 37, 'Private' ] );
a9cbd748 28 for my $path ( sort keys %{ $self->{paths} } ) {
29 my $action = $self->{paths}->{$path};
8c113188 30 $paths->row( "/$path", "/$action" );
a9cbd748 31 }
32 $c->log->debug( "Loaded Path actions:\n" . $paths->draw )
8c113188 33 if ( keys %{ $self->{paths} } );
a9cbd748 34}
35
2633d7dc 36=item $self->match( $c, $path )
37
38=cut
39
40sub match {
41 my ( $self, $c, $path ) = @_;
6b239949 42
43 if ( my $action = $self->{paths}->{$path} ) {
44 $c->req->action($path);
45 $c->req->match($path);
46 $c->action($action);
11bd4e3e 47 $c->namespace( $action->namespace );
6b239949 48 return 1;
49 }
50
51 return 0;
52}
53
2633d7dc 54=item $self->register( $c, $action )
55
56=cut
57
58sub register {
6b239949 59 my ( $self, $c, $action ) = @_;
22f3a8dd 60
6b239949 61 my $attrs = $action->attributes;
62 my @register;
22f3a8dd 63
2633d7dc 64 foreach my $r ( @{ $attrs->{Path} || [] } ) {
621a5d5e 65 unless ( $r ) {
66 $r = $action->namespace;
67 }
68 elsif ( $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;