package Catalyst::DispatchType::Path;
use Moose;
+extends 'Catalyst::DispatchType';
+
use Text::SimpleTable;
use URI;
-extends 'Catalyst::DispatchType';
-
has _paths => (
is => 'rw',
isa => 'HashRef',
required => 1,
- default => sub {{}}
+ default => sub { +{} },
);
+no Moose;
+
=head1 NAME
Catalyst::DispatchType::Path - Path DispatchType
sub list {
my ( $self, $c ) = @_;
- my %paths = %{ $self->_paths };
- my @keys = sort keys %paths;
- return unless @keys;
- my $paths_table = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] );
- foreach my $path ( @keys ) {
+ my $paths = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] );
+ foreach my $path ( sort keys %{ $self->_paths } ) {
my $display_path = $path eq '/' ? $path : "/$path";
- foreach my $action ( @{ $paths{$path} } ) {
- $paths_table->row( $display_path, "/$action" );
+ foreach my $action ( @{ $self->_paths->{$path} } ) {
+ $paths->row( $display_path, "/$action" );
}
}
- $c->log->debug( "Loaded Path actions:\n" . $paths_table->draw . "\n" );
+ $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" )
+ if ( keys %{ $self->_paths } );
}
=head2 $self->match( $c, $path )
sub match {
my ( $self, $c, $path ) = @_;
- $path ||= '/';
+ $path = '/' if !defined $path || !length $path;
foreach my $action ( @{ $self->_paths->{$path} || [] } ) {
next unless $action->match($c);
}
}
-=head1 AUTHOR
+=head1 AUTHORS
-Matt S Trout
-Sebastian Riedel, C<sri@cpan.org>
+Catalyst Contributors, see Catalyst.pm
=head1 COPYRIGHT
=cut
+__PACKAGE__->meta->make_immutable;
+
1;