Apache-ConfigParser
view release on metacpan or search on metacpan
lib/Apache/ConfigParser/Directive.pm view on Meta::CPAN
}
=item Note on $d->value_is_path, $d->value_is_abs_path,
$d->value_is_rel_path, $d->orig_value_is_path,
$d->orig_value_is_abs_path and $d->orig_value_is_rel_path
These six methods are very similar. They all check if the directive
can take a file or directory path value argument in the appropriate
index in the value array and then check the value. For example, the
C<LoadModule> directive, i.e.
=over 4
LoadModule cgi_module libexec/mod_cgi.so
=back
does not take a path element in its first (index 0) value array
element.
If there is no argument supplied to the method call, then the
directive checks the first element of the value array that can legally
contain path. For C<LoadModule>, it would check element 1. You could
pass 0 to the method to check the first indexed value of
C<LoadModule>, but it would always return false, because index 0 does
not contain a path.
These are the differences between the methods:
=over 4
1) The methods beginning with the string 'value_is' apply to the
current value in the directive while the methods beginning with the
string 'orig_value_is' apply to the original value of the directive.
2) The methods '*value_is_path' test if the directive value is a path,
either absolute or relative. The methods '*value_is_abs_path' test if
the path if an absolute path, and the methods '*value_is_rel_path'
test if the path is not an absolute path.
=back
=item $d->value_is_path
=item $d->value_is_path($index_into_value_array)
Returns true if C<$d>'s directive can take a file or directory path in
the specified value array element (indexed by $index_into_value_array
or the first path element for the particular directive if
$index_into_value_array is not provided) and if the value is either an
absolute or relative file or directory path. Both the directive name
and the value is checked, because some directives such as ErrorLog,
can take values that are not paths (i.e. a piped command or
syslog:facility). The /dev/null equivalent for the operating system
is not treated as a path, since on some operating systems the
/dev/null equivalent is not a file, such as nul on Windows.
The method actually does not check if its value is a path, rather it
checks if the value does not match all of the other possible non-path
values for the specific directive because different operating systems
have different path formats, such as Unix, Windows and Macintosh.
=cut
# Define these constant subroutines as the different types of paths to
# check for in _value_is_path_or_abs_path_or_rel_path.
sub CHECK_TYPE_ABS () { 'abs' }
sub CHECK_TYPE_REL () { 'rel' }
sub CHECK_TYPE_ABS_OR_REL () { 'abs_or_rel' }
# This is a function that does the work for value_is_path,
# orig_value_is_path, value_is_abs_path, orig_value_is_abs_path,
# value_is_rel_path and orig_value_is_rel_path.
sub _value_is_path_or_abs_path_or_rel_path {
unless (@_ == 4) {
confess "$0: Apache::ConfigParser::Directive::",
"_value_is_path_or_abs_path_or_rel_path ",
$INCORRECT_NUMBER_OF_ARGS;
}
my ($self,
$check_type,
$array_var_name,
$value_path_index) = @_;
unless ($check_type eq CHECK_TYPE_ABS or
$check_type eq CHECK_TYPE_REL or
$check_type eq CHECK_TYPE_ABS_OR_REL) {
confess "$0: Apache::ConfigParser::Directive::",
"_value_is_path_or_abs_path_or_rel_path ",
"passed invalid check_type value '$check_type'.\n";
}
if (defined $value_path_index and $value_path_index !~ /^\d+$/) {
confess "$0: Apache::ConfigParser::Directive::",
"_value_is_path_or_abs_path_or_rel_path ",
"passed invalid value_path_index value '$value_path_index'.\n";
}
my $array_ref = $self->{$array_var_name};
unless ($array_ref) {
return 0;
}
my $directive_name = $self->name;
unless (defined $directive_name and length $directive_name) {
return 0;
}
# Check if there is an index into the value array that can take a
# path.
my $first_value_path_index =
$directive_value_path_element_pos{$directive_name};
unless (defined $first_value_path_index and length $first_value_path_index) {
return 0;
}
# If the index into the value array was specified, then check if the
# value in the index can take a path. If the index was not
lib/Apache/ConfigParser/Directive.pm view on Meta::CPAN
} else {
confess "$0: internal error: check_type case ",
"'$check_type' not handled.\n";
}
} else {
return 0;
}
}
sub value_is_path {
unless (@_ < 3) {
confess "$0: Apache::ConfigParser::Directive::value_is_path ",
$INCORRECT_NUMBER_OF_ARGS;
}
_value_is_path_or_abs_path_or_rel_path($_[0],
CHECK_TYPE_ABS_OR_REL,
'value_array',
$_[1]);
}
=item $d->orig_value_is_path
=item $d->orig_value_is_path($index_into_value_array)
This has the same behavior as C<< $d->value_is_path >> except the results
are applicable to C<$d>'s 'original' value array.
=cut
sub orig_value_is_path {
unless (@_ < 3) {
confess "$0: Apache::ConfigParser::Directive::orig_value_is_path ",
$INCORRECT_NUMBER_OF_ARGS;
}
_value_is_path_or_abs_path_or_rel_path($_[0],
CHECK_TYPE_ABS_OR_REL,
'orig_value_array',
$_[1]);
}
=item $d->value_is_abs_path
=item $d->value_is_abs_path($index_into_value_array)
Returns true if C<$d>'s directive can take a file or directory path in
the specified value array element (indexed by $index_into_value_array
or the first path element for the particular directive if
$index_into_value_array is not provided) and if the value is an
absolute file or directory path. Both the directive name and the
value is checked, because some directives such as ErrorLog, can take
values that are not paths (i.e. a piped command or syslog:facility).
The /dev/null equivalent for the operating system is not treated as a
path, since on some operating systems the /dev/null equivalent is not
a file, such as nul on Windows.
The method actually does not check if its value is a path, rather it
checks if the value does not match all of the other possible non-path
values for the specific directive because different operating systems
have different path formats, such as Unix, Windows and Macintosh.
=cut
sub value_is_abs_path {
unless (@_ < 3) {
confess "$0: Apache::ConfigParser::Directive::value_is_abs_path ",
$INCORRECT_NUMBER_OF_ARGS;
}
_value_is_path_or_abs_path_or_rel_path($_[0],
CHECK_TYPE_ABS,
'value_array',
$_[1]);
}
=item $d->orig_value_is_abs_path
=item $d->orig_value_is_abs_path($index_into_value_array)
This has the same behavior as C<< $d->value_is_abs_path >> except the
results are applicable to C<$d>'s 'original' value array.
=cut
sub orig_value_is_abs_path {
unless (@_ < 3) {
confess "$0: Apache::ConfigParser::Directive::orig_value_is_abs_path ",
$INCORRECT_NUMBER_OF_ARGS;
}
_value_is_path_or_abs_path_or_rel_path($_[0],
CHECK_TYPE_ABS,
'orig_value_array',
$_[1]);
}
=item $d->value_is_rel_path
=item $d->value_is_rel_path($index_into_value_array)
Returns true if C<$d>'s directive can take a file or directory path in
the specified value array element (indexed by $index_into_value_array
or the first path element for the particular directive if
$index_into_value_array is not provided) and if the value is a
relative file or directory path. Both the directive name and the
value is checked, because some directives such as ErrorLog, can take
values that are not paths (i.e. a piped command or syslog:facility).
The /dev/null equivalent for the operating system is not treated as a
path, since on some operating systems the /dev/null equivalent is not
a file, such as nul on Windows.
The method actually does not check if its value is a path, rather it
checks if the value does not match all of the other possible non-path
values for the specific directive because different operating systems
have different path formats, such as Unix, Windows and Macintosh.
=cut
sub value_is_rel_path {
unless (@_ < 3) {
confess "$0: Apache::ConfigParser::Directive::value_is_rel_path ",
$INCORRECT_NUMBER_OF_ARGS;
}
_value_is_path_or_abs_path_or_rel_path($_[0],
CHECK_TYPE_REL,
'value_array',
$_[1]);
}
=item $d->orig_value_is_rel_path
=item $d->orig_value_is_rel_path($index_into_value_array)
This has the same behavior as C<< $d->value_is_rel_path >> except the
results are applicable to C<$d>'s 'original' value array.
=cut
sub orig_value_is_rel_path {
unless (@_ < 3) {
confess "$0: Apache::ConfigParser::Directive::orig_value_is_rel_path ",
$INCORRECT_NUMBER_OF_ARGS;
}
_value_is_path_or_abs_path_or_rel_path($_[0],
CHECK_TYPE_REL,
'orig_value_array',
$_[1]);
}
=item $d->filename
=item $d->filename($filename)
In the first form get the filename where this particular directive or
context appears. In the second form set the new filename of the
directive or context and return the original filename.
=cut
sub filename {
unless (@_ < 3) {
confess "$0: Apache::ConfigParser::Directive::filename ",
$INCORRECT_NUMBER_OF_ARGS;
}
my $self = shift;
if (@_) {
my $old = $self->{filename};
$self->{filename} = $_[0];
return $old;
} else {
return $self->{filename};
}
lib/Apache/ConfigParser/Directive.pm view on Meta::CPAN
sub line_number {
unless (@_ < 3) {
confess "$0: Apache::ConfigParser::Directive::line_number ",
$INCORRECT_NUMBER_OF_ARGS;
}
my $self = shift;
if (@_) {
my $old = $self->{line_number};
$self->{line_number} = $_[0];
return $old;
} else {
return $self->{line_number};
}
}
=back
=head1 EXPORTED VARIABLES
The following variables are exported via C<@EXPORT_OK>.
=over 4
=item DEV_NULL
The string representation of the null device on this operating system.
=item DEV_NULL_LC
The lowercase version of DEV_NULL.
=item is_dev_null($path)
On a case sensitive system, compares $path to DEV_NULL and on a case
insensitive system, compares lc($path) to DEV_NULL_LC.
=item %directive_value_takes_abs_path
This hash is keyed by the lowercase version of a directive name. This
hash is keyed by all directives that accept a file or directory path
value as its first value array element. The hash value is a subroutine
reference to pass the value array element containing the file,
directory, pipe or syslog entry to. If a hash entry exists for a
particular entry, then the directive name can take either a relative
or absolute path to either a file or directory. The hash does not
distinguish between directives that take only filenames, only
directories or both, and it does not distinguish if the directive
takes only absolute, only relative or both types of paths.
The hash value for the lowercase directive name is a subroutine
reference. The subroutine returns 1 if its only argument is a path
and 0 otherwise. The /dev/null equivalent (C<< File::Spec->devnull >>)
for the operating system being used is not counted as a path, since on
some operating systems the /dev/null equivalent is not a filename,
such as nul on Windows.
The subroutine actually does not check if its argument is a path,
rather it checks if the argument does not match one of the other
possible non-path values for the specific directive because different
operating systems have different path formats, such as Unix, Windows
and Macintosh. For example, ErrorLog can take a filename, such as
ErrorLog /var/log/httpd/error_log
or a piped command, such as
ErrorLog "| cronolog /var/log/httpd/%Y/%m/%d/error.log"
or a syslog entry of the two forms:
ErrorLog syslog
ErrorLog syslog:local7
The particular subroutine for ErrorLog checks if the value is not
equal to C<< File::Spec->devnull >>, does not begin with a | or does not
match syslog(:[a-zA-Z0-9]+)?.
These subroutines do not remove any "'s before checking on the type of
value.
This hash is used by C<value_is_path> and C<orig_value_is_path>.
This is a list of directives and any special values to check for as of
Apache 1.3.20 with the addition of IncludeOptional from 2.4.x.
AccessConfig
AgentLog check for "| prog"
AuthDBGroupFile
AuthDBMGroupFile
AuthDBMUserFile
AuthDBUserFile
AuthDigestFile
AuthGroupFile
AuthUserFile
CacheRoot
CookieLog
CoreDumpDirectory
CustomLog check for "| prog"
Directory
DocumentRoot
ErrorLog check for "| prog", or syslog or syslog:facility
Include
IncludeOptional
LoadFile
LoadModule
LockFile
MimeMagicFile
MMapFile
PidFile
RefererLog check for "| prog"
ResourceConfig
RewriteLock
ScoreBoardFile
ScriptLog
ServerRoot
TransferLog check for "| prog"
TypesConfig
=item %directive_value_takes_rel_path
This hash is keyed by the lowercase version of a directive name. This
hash contains only those directive names that can accept both relative
and absolute file or directory names. The hash value is a subroutine
reference to pass the value array element containing the file,
directory, pipe or syslog entry to. The hash does not distinguish
between directives that take only filenames, only directories or both.
The hash value for the lowercase directive name is a subroutine
reference. The subroutine returns 1 if its only argument is a path
and 0 otherwise. The /dev/null equivalent (C<< File::Spec->devnull >>)
for the operating system being used is not counted as a path, since on
some operating systems the /dev/null equivalent is not a filename,
such as nul on Windows.
The subroutine actually does not check if its argument is a path,
rather it checks if the argument does not match one of the other
possible non-path values for the specific directive because different
operating systems have different path formats, such as Unix, Windows
and Macintosh. For example, ErrorLog can take a filename, such as
ErrorLog /var/log/httpd/error_log
or a piped command, such as
ErrorLog "| cronolog /var/log/httpd/%Y/%m/%d/error.log"
or a syslog entry of the two forms:
ErrorLog syslog
ErrorLog syslog:local7
The particular subroutine for ErrorLog checks if the value is not
equal to C<< File::Spec->devnull >>, does not begin with a | or does not
match syslog(:[a-zA-Z0-9]+)?.
These subroutines do not remove any "'s before checking on the type of
value.
This hash is used by C<value_is_rel_path> and
C<orig_value_is_rel_path>.
This is a list of directives and any special values to check for as of
Apache 1.3.20 with the addition of IncludeOptional from 2.4.x.
AccessFileName is not a key in the hash because, while its value is
one or more relative paths, the ServerRoot is never prepended to it as
the AccessFileName values are looked up in every directory of the path
to the document being requested.
AccessConfig
AuthGroupFile
AuthUserFile
CookieLog
CustomLog check for "| prog"
ErrorLog check for "| prog", or syslog or syslog:facility
Include
IncludeOptional
LoadFile
LoadModule
LockFile
MimeMagicFile
PidFile
RefererLog check for "| prog"
ResourceConfig
ScoreBoardFile
ScriptLog
TransferLog check for "| prog"
TypesConfig
=item %directive_value_path_element_pos
This hash holds the indexes into the directive value array for the
value or values that can contain either absolute or relative file or
directory paths. This hash is keyed by the lowercase version of a
directive name. The hash value is a string representing an integer.
The string can take two forms:
/^\d+$/ The directive has only one value element indexed by \d+
( run in 1.486 second using v1.01-cache-2.11-cpan-39bf76dae61 )