NAME

Router::PathInfo::Static - static routing

DESCRIPTION

Class to describe the routing of statics. Allows us to describe the statics as follows:

- Specify the starting segment of the URI

- Specify a directory on disk, which will host the search for static

Statics is divided into two parts:

- allready - already exists (the "classic") static

- on_demand - created on demand

Если случай allready - это различные css, js, картинки, то on_demand - это архивы и прочее. Если файл для on_demand не найден, match вернёт undef - сигнал к тому, что поиск имеет смысл продолжить среди роутинга по правилам.

Case allready it's different css, js, images. on_demand it's archives and another. If the file to on_demand not found, match return undef - a signal that makes sense to continue search of Router::PathInfo::Controller routing.

If successful, returns hashref:

{
    type => 'static',
    mime_type => $mime_type,
    file_name => '/path/to/found.static',
};

This ensures that the file exists, has size, and is readable.

If static is not found (for allready) an error is returned:

{
    type  => 'error',
    code => 404,
    desc  => sprintf('not found static for PATH_INFO = %s', $env->{PATH_INFO})
}

If PATH_INFO contains illegal characters (such as /../ or /.file)an error is returned:

{
    type  => 'error',
    code => 403,
    desc  => sprintf('forbidden for PATH_INFO = %s', $env->{PATH_INFO})   
}

Return undef means that it makes sense to continue search of Router::PathInfo::Controller routing.

SYNOPSIS

my $s = Router::PathInfo::Static->new(
        # describe simple static 
        allready => {
            path => $allready_path,
            first_uri_segment => 'static'
        },
        # describe on demand created static
        on_demand => {
            path => $on_demand_path,
            first_uri_segment => 'archives',
        }
);

my $env = {PATH_INFO => '/static/some.jpg'};
my @segment = split '/', $env->{PATH_INFO}, -1; 
shift @segment;
$env->{'psgix.tmp.RouterPathInfo'} = {
    segments => [@segment],
    depth => scalar @segment 
};

my $res = $s->match($env);

# $res = {
#     type  => 'static',
#     file  => $path_to_some_jpg,
#     mime  => 'image/jpeg'
# }

METHODS

new(allready => {path => $dir, first_uri_segment => $uri_segment}, on_demand => {...})

The constructor accepts the description of the statics (allready) and/or static generated on demand (on_demand). Each description is a hashref with the keys 'path' (directory path) and 'first_uri_segment' (the first segment of a PATH_INFO, which defines namespace for designated purposes).

All arguments are optional. If no arguments are given, the object is not created.

match({'psgix.tmp.RouterPathInfo' => {...}})

Objects method. Receives a uri and return:

For on_demand created static, return undef if file not found.

DEPENDENCIES

Plack::MIME, File::MimeInfo::Magic

SEE ALSO

Router::PathInfo, Router::PathInfo::Controller

AUTHOR

mr.Rico <catamoose at yandex.ru>

1 POD Error

The following errors were encountered while parsing the POD:

Around line 24:

Non-ASCII character seen before =encoding in 'Если'. Assuming UTF-8