NAME

Catalyst::Controller::DirectoryDispatch - A controller for browsing system directories

SYNOPSIS

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

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

DESCRIPTION

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

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.

__PACKAGE__->config(
    'default'   => 'text/html',
    'map'       => {
    	'text/html' => [ 'View', 'TT' ],
    }
);

Then in your template...

[% FOREACH node IN response.data %]
[% 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 ($c, $files) = @_;
	
	foreach my $file ( @$files ) {
		# Do stuff...
	}
}

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.

CONFIGURATION

root

is: ro, isa: Str

The folder that will be listed when accessing the controller.

filter

is: ro, isa: RegexpRef

A regular expression that will remove matching files or folders from the directory listing.

data_root

is: ro, isa: Str

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

full_paths

is: ro, isa: Bool

Returns full paths for the directory listing rather than just the names.

TODO

Write tests

AUTHOR

Andy Gorman, agorman@cpan.org

THANKS

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

COPYRIGHT AND LICENSE

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