[Catalyst-dev] Static Alias

chunzi chunzi at perlchina.org
Sat Jul 16 12:49:24 CEST 2005

when using Apache, sometimes we configed as:

Alias /archieve /home/paht/to/some/archieve

so, we could access the files under the long real path by

and in Catalyst, running with script/myapp_server.pl, almot use the
Catalyst::Plugin::Static to serve
the files under root directory. no alisa support. so I just wrote an
extend as follow:

package Catalyst::Plugin::StaticAlias;
use base 'Catalyst::Plugin::Static';
sub serve_static {
my $c = shift;
my @params = @_;

my @static_alias = @{$c->config->{'static_alias'}};
my @pairs;
while ( @static_alias ){
my $alias_name = shift @static_alias;
my $alias_path = shift @static_alias;
next unless -d $alias_path;
push @pairs, [ $alias_name, $alias_path ];

my $req_path = $c->req->path;
$req_path =~ s/^\///;

foreach ( @pairs ){
my ( $alias_name, $alias_path ) = @{$_};
next unless $req_path =~ /^$alias_name/;
$req_path =~ s/^$alias_name//;
my $path = $alias_path. '/' . $req_path;
return $c->serve_static_file( $path, @params );

# default, as baseclass
my $path = $c->config->{root} . '/' . $c->req->path;
return $c->serve_static_file( $path, @params );

and in myapp's config like:

use Catalyat 'StaticAlias';
static_alias => [
'archieve' => '/home/chunzi/CaberMessages',

that's a scrach, but works fine. and I think there more works to do to
have a greate Static module.
and I hope you could make it more better.

More information about the Catalyst-dev mailing list