File Coverage

blib/lib/AxKit2/Config/Location.pm
Criterion Covered Total %
statement 6 48 12.5
branch 0 20 0.0
condition 0 2 0.0
subroutine 2 14 14.2
pod 0 10 0.0
total 8 94 8.5


line stmt bran cond sub pod time code
1             # Copyright 2001-2006 The Apache Software Foundation
2             #
3             # Licensed under the Apache License, Version 2.0 (the "License");
4             # you may not use this file except in compliance with the License.
5             # You may obtain a copy of the License at
6             #
7             # http://www.apache.org/licenses/LICENSE-2.0
8             #
9             # Unless required by applicable law or agreed to in writing, software
10             # distributed under the License is distributed on an "AS IS" BASIS,
11             # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12             # See the License for the specific language governing permissions and
13             # limitations under the License.
14             #
15              
16             package AxKit2::Config::Location;
17              
18             # Configuration for a location (a URI path within a server)
19              
20 9     9   49 use strict;
  9         19  
  9         295  
21 9     9   45 use warnings;
  9         19  
  9         5493  
22              
23             our $AUTOLOAD;
24              
25             sub new {
26 0     0 0   my $class = shift;
27 0           my $server = shift;
28 0           my $path = shift;
29            
30 0           my %defaults = (
31             Plugins => [],
32             Notes => {},
33             CachedHooks => {},
34             );
35            
36 0           my %args = ( __server => $server, __path => $path, %defaults, @_ );
37            
38 0           return bless \%args, $class;
39             }
40              
41             sub server {
42 0     0 0   my $self = shift;
43 0           $self->{__server};
44             }
45              
46             sub path {
47 0     0 0   my $self = shift;
48 0           $self->{__path};
49             }
50              
51             sub matches {
52 0     0 0   my $self = shift;
53 0           my $tomatch = shift;
54 0           return index($tomatch, $self->path) + 1;
55             }
56              
57             sub docroot {
58 0     0 0   my $self = shift;
59 0 0         @_ and $self->{DocumentRoot} = shift;
60 0 0         $self->{DocumentRoot} || $self->server->docroot;
61             }
62              
63             sub add_plugin {
64 0     0 0   my $self = shift;
65 0           push @{$self->{Plugins}}, shift;
  0            
66             }
67              
68             sub plugins {
69 0     0 0   my $self = shift;
70 0           @{$self->{Plugins}}, $self->server->plugins;
  0            
71             }
72              
73             sub plugin_dir {
74 0     0 0   my $self = shift;
75 0 0         @_ and $self->{PluginDir} = shift;
76 0 0         $self->{PluginDir} || $self->server->plugin_dir;
77             }
78              
79             sub cached_hooks {
80 0     0 0   my $self = shift;
81 0           my $hook = shift;
82 0 0         @_ and $self->{CachedHooks}{$hook} = shift;
83 0           $self->{CachedHooks}{$hook};
84             }
85              
86             sub notes {
87 0     0 0   my $self = shift;
88 0   0       my $key = shift || die "notes() requires a key";
89            
90 0 0         @_ and $self->{Notes}{$key} = [ @_ ];
91 0 0         return $self->server->notes($key) if !exists $self->{Notes}{$key};
92 0 0         return @{ $self->{Notes}{$key} || [] } if wantarray;
  0 0          
93 0 0         ${ $self->{Notes}{$key} || [] }[0];
  0            
94             }
95              
96 0     0     sub DESTROY {}
97              
98             sub AUTOLOAD {
99 0     0     my $self = shift;
100 0           my $method = $AUTOLOAD;
101 0           $method =~ s/.*:://;
102 0           $self->server->$method(@_);
103             }
104              
105             1;