Apache2-Layer

 view release on metacpan or  search on metacpan

lib/Apache2/Layer.pm  view on Meta::CPAN

}

sub _DocumentRootLayersParam {
    my ($self, $params, $path) = @_;

    _check_cmd_context($params);

    push @{ $self->{DocumentRootLayers} }, $path;
    $self->_set_location_path( $params->path );
}

sub _EnableDocumentRootLayersParam {
    my ($self, $params, $flag) = @_;

    _check_cmd_context($params);

    $self->{DocumentRootLayersEnabled} = $flag;
    $self->_set_location_path( $params->path );
}

sub _DocumentRootLayersStripLocationParam {
    my ($self, $params, $flag) = @_;

    _check_cmd_context($params);

    $self->{DocumentRootLayersStripLocation} = $flag;
    $self->_set_location_path( $params->path );
}

sub handler {
    my $r = shift;

    my $dir_cfg = Apache2::Module::get_config(
        __PACKAGE__, $r->server, $r->per_dir_config
    );

    return Apache2::Const::DECLINED
        unless $dir_cfg->{DocumentRootLayersEnabled};

    if ( my $paths = $dir_cfg->{DocumentRootLayers} ) {
        for my $dir ( @$paths ) {
            my $uri = $r->uri;
            # not defined means On
            if ( ! defined $dir_cfg->{DocumentRootLayersStripLocation}
                    ||
                 $dir_cfg->{DocumentRootLayersStripLocation}
            ) {
                if ( my $path = $dir_cfg->{LocationPath} ) {
                    $uri =~ s/^$path//;
                }
            }
            my $file = File::Spec->canonpath(
                File::Spec->catfile(
                    File::Spec->file_name_is_absolute($dir) ?
                        $dir : File::Spec->catdir( $r->document_root, $dir ),
                    $uri
                )
            );

            if ( my $finfo = eval {
                APR::Finfo::stat($file, APR::Const::FINFO_NORM, $r->pool)
            } ) {
                $r->push_handlers(PerlMapToStorageHandler => sub {
                    my $r = shift;
                    $r->filename($file);
                    $r->finfo($finfo);
                    return Apache2::Const::DECLINED;
                });

                return Apache2::Const::DECLINED;
            }
        }
    }

    return Apache2::Const::DECLINED;
}


1;


__END__
=pod

=encoding utf-8

=head1 NAME

Apache2::Layer - Layers for DocumentRoot

=head1 VERSION

version 1.103360

=head1 SYNOPSIS

    # in httpd.conf
    DocumentRoot "/usr/local/htdocs"

    # load module
    PerlLoadModule Apache2::Layer

    # enable layers for whole server
    EnableDocumentRootLayers On

    # disable location strip
    DocumentRootLayersStripLocation Off

    # paths are relative to DocumentRoot
    DocumentRootLayers layered/christmas layered/promotions

    <VirtualHost *:80>
        ...
        # layers enabled for this vhost
    </VirtualHost>

    <VirtualHost *:80>
        ...
        DocumentRoot "/usr/local/vhost2"

        # disabled by default



( run in 1.179 second using v1.01-cache-2.11-cpan-d8267643d1d )