| 1 | package App::AutoCRUD::Controller::Static; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | use Moose; | ||
| 8 | extends 'App::AutoCRUD::Controller'; | ||
| 9 | |||
| 10 | use List::MoreUtils qw/firstval/; | ||
| 11 | |||
| 12 | use namespace::clean -except => 'meta'; | ||
| 13 | |||
| 14 | sub serve { | ||
| 15 | my ($self) = @_; | ||
| 16 | |||
| 17 | my $context = $self->context; | ||
| 18 | my @dirs = $context->app->share_paths; | ||
| 19 | my $root_dir = $context->config(qw/static root/); | ||
| 20 | unshift @dirs, $root_dir if $root_dir; | ||
| 21 | |||
| 22 | my $path = $context->path; | ||
| 23 | my $file = firstval {-f $_} map {"$_/static$path"} @dirs | ||
| 24 | or die "$path: no such static file"; | ||
| 25 | |||
| 26 | my $view_class = $context->app->find_class("View::Download") | ||
| 27 | or die "no Download view"; | ||
| 28 | $context->set_view($view_class->new); | ||
| 29 | |||
| 30 | return $file; | ||
| 31 | } | ||
| 32 | |||
| 33 | 1; | ||
| 34 | |||
| 35 | |||
| 36 | __END__ |