Apache2-Controller
view release on metacpan or search on metacpan
lib/Apache2/Controller/Directives.pm view on Meta::CPAN
See L<Apache2::Controller::Dispatch>
=head2 A2C_Dispatch_Map
This is the path to a file compatible with L<YAML::Syck>.
If you do not provide a C<< dispatch_map() >> subroutine,
the hash will be loaded with this file.
Different subclasses of L<Apache2::Controller::Dispatch>
have different data structures. YMMV.
Or, if you just specify a package name, it will generate
a dispatch map with one 'default' entry with that package.
=cut
sub A2C_Dispatch_Map {
my ($self, $parms, $value) = @_;
($value) = $value =~ m{ \A (.*) \z }mxs;
if ($value =~ m{ :: }mxs) {
$self->{A2C_Dispatch_Map} = { default => $value };
return;
}
my $file = $value;
# DEBUG("using file '$file' as A2C_Dispatch_Map");
croak "A2C_Dispatch_Map $file does not exist or is not readable."
if !(-e $file && -f _ && -r _);
# why not go ahead and load the file!
# slurp it in so it can be detainted.
my $file_contents;
{ local $/;
open my $loadfile_fh, '<', $file
|| croak "Cannot read A2C_Dispatch_Map $file: $OS_ERROR";
$file_contents = <$loadfile_fh>;
close $loadfile_fh;
}
eval { $self->{A2C_Dispatch_Map} = Load($file_contents) };
croak "Could not load A2C_Dispatch_Map $file: $EVAL_ERROR" if $EVAL_ERROR;
# DEBUG("success!");
return;
}
=head1 Apache2::Controller::Render::Template
See L<Apache2::Controller::Render::Template>.
=head2 A2C_Render_Template_Path
This is the base path for templates used by
Apache2::Controller::Render::Template. The directive takes only
one parameter and verifies that the directory exists and is readable.
(At startup time Apache2 is root... this should verify readability by
www user? Hrmm how is it going to figure out what user that is?
It will have to access the server config via $parms. Except that
this does not appear to work? It returns an empty hash.)
=cut
sub A2C_Render_Template_Path {
my ($self, $parms, @directories_untainted) = @_;
my @directories = map {
my ($val) = $_ =~ m{ \A (.*) \z }mxs;
$val;
} @directories_untainted;
# uhh... this doesn't work?
# my $srv_cfg = Apache2::Module::get_config($self, $parms->server);
# DEBUG(sub{"SERVER CONFIG:\n".Dump({
# map {("$_" => $srv_cfg->{$_})} keys %{$srv_cfg}
# }) });
# DEBUG("server is ".$parms->server);
# I need to figure out how to merge these or something
croak("A2C_Render_Template_Path '$_' does not exist or is not readable.")
for grep !( -d $_ && -r _ ), @directories;
my $current = $self->{A2C_Render_Template_Path} ||= [ ];
DEBUG sub { "pushing (@directories) to (@{$current})" };
push @{ $self->{A2C_Render_Template_Path} }, @directories;
}
=head2 A2C_Render_Template_Opts
<location "/where/template/is/used">
A2C_Render_Template_Opts INTERPOLATE 1
A2C_Render_Template_Opts PRE_PROCESS header meta style scripts
A2C_Render_Template_Opts POST_CHOMP 1
</location>
Options for Template Toolkit. See L<Template>.
You can also implement C<<get_template_opts>> in your controller subclass,
which simply returns the hash reference of template options.
See L<Apache2::Controller::Render::Template>.
Note the behavior is to merge values specified at multiple levels
into array references. i.e. a subdirectory could specify an
additional C<<PRE_PROCESS>> template or whatever. YMMV.
It should be this way, at any rate!
=cut
sub A2C_Render_Template_Opts {
my ($self, $parms, $key, $val) = @_;
$self->hash_assign('A2C_Render_Template_Opts', $key, $val);
return;
}
=head1 Apache2::Controller::Session
See L<Apache2::Controller::Session>.
=head2 A2C_Session_Class
A2C_Session_Class Apache::Session::File
Single argument, the class for the tied session hash. L<Apache::Session>.
=cut
sub A2C_Session_Class {
my ($self, $parms, $class) = @_;
($class) = $class =~ m{ \A (.*) \z }mxs;
$self->{A2C_Session_Class} = $class;
}
=head2 A2C_Session_Opts
Multiple arguments
A2C_Session_Opts Directory /tmp/sessions
A2C_Session_Opts LockDirectory /var/lock/sessions
=cut
sub A2C_Session_Opts {
my ($self, $parms, $key, $val) = @_;
$self->hash_assign('A2C_Session_Opts', $key, $val);
return;
}
=head2 A2C_Session_Secret
# generate a random 30-character string:
A2C_Session_Secret
# specify your own string:
A2C_Session_Secret jsd9e9j#*@JMf39kc3
This server-wide constant string will used to verify the session id.
See L<Apache2::Controller::Session>.
If you don't specify the value, it will generate a default 30-character
random string, but this will regenerate on server restarts, and would not
work for a cluster of servers serving the same application.
=cut
sub A2C_Session_Secret {
my ($self, $parms, $val) = @_;
if (!defined $val || $val =~ m{ \A \s* \z }mxs) {
srand;
$val = join('', map $RANDCHARS[int(rand(@RANDCHARS))], 1..30);
}
($val) = $val =~ m{ \A (.*) \z }mxs;
$self->{A2C_Session_Secret} = $val;
}
=head2 A2C_Session_Always_Save
A2C_Session_Always_Save
Takes no arguments. If directed, L<Apache2::Controller::Session>
will update a top-level timestamp in
C<< $r->pnotes->{a2c}{session}{a2c_timestamp} >> so that
L<Apache::Session> will always save.
=cut
sub A2C_Session_Always_Save {
my ($self, $parms) = @_;
$self->{A2C_Session_Always_Save} = 1;
}
=head2 A2C_Session_Cookie_Opts
A2C_Session_Cookie_Opts name myapp_sessionid
A2C_Session_Cookie_Opts expires +3M
Multiple arguments.
L<Apache2::Controller::Session::Cookie>,
L<Apache2::Cookie>
=cut
sub A2C_Session_Cookie_Opts {
my ($self, $parms, $key, $val) = @_;
$self->hash_assign('A2C_Session_Cookie_Opts', $key, $val);
return;
}
=head1 Apache2::Controller::Methods
Misc. directives that apply to most A2C objects that inherit
L<Apache2::Controller::Methods>.
=head2 A2C_Skip_Bogus_Cookies
A2C_Skip_Bogus_Cookies
( run in 0.572 second using v1.01-cache-2.11-cpan-437f7b0c052 )