Andy Gorman


Catalyst::Controller::DirectoryDispatch - Simple directory listing with built in url dispatching


version 1.02


    package MyApp::Controller::Browser::Example;
    use Moose;
    BEGIN { extends 'Catalyst::Controller::DirectoryDispatch' }

        action => { setup => { Chained => '/browser/base', PathPart => 'mydir' } },
        root     => '/home/andy',
        filter     => qr{^\.|.conf$},
        data_root  => 'data',
        full_paths => 1,


Provides a simple configuration based controller for listing local system directories and dispatching them as URLs.

Example Usage

If you created the controller at http://localhost/mydir and set root to '/home/user1' then browsing to the controller might give the following output:


You could then point your browser to http://localhost/mydir/dir1 to get a directory listing of the folder '/home/user1/dir1' and so on...

Changing Views

The default view for DirectoryDispatch serializes the file list as JSON but it's easy to change it to whatever view you'd like.

        'default'   => 'text/html',
        'map'       => {
            'text/html' => [ 'View', 'TT' ],

Then in your template...

    [% FOREACH node IN %]
    [% node %]
    [% END %]

Post Processing

If you need to process the files in anyway before they're passed to the view you can override process_files in your controller.

    sub process_files {
        my ($self, $c, $files) = @_;

        foreach my $file ( @$files ) {
            # Modify $file

        return $files;

This is the last thing that happens before the list of files are passed on to the view. $files is sent in as an ArrayRef[Str] but you are free to return any thing you want as long as the serializer you're using can handle it.



    is: ro, isa: Str

The folder that will be listed when accessing the controller (default '/').


    is: ro, isa: RegexpRef

A regular expression that will remove matching files or folders from the directory listing (default: undef).


    is: ro, isa: Str

The name of the key inside $c->stash->{response} where the directory listing will be stored (default: data).


    is: ro, isa: Bool

Returns full paths for the directory listing rather than just the names (default: 0).


The design for this module was heavly influenced by the fantastic Catalyst::Controller::DBIC::API.


Andy Gorman <>


This software is copyright (c) 2010 by Andy Gorman.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.