Apache-Wyrd

 view release on metacpan or  search on metacpan

Wyrd/Handler.pm  view on Meta::CPAN


=item post_process

Called by handler on a successful responses from C<process> and
C<respond>.  A hook for post-processing the final output.  At the point
this method is called, all the output is ready to be sent and is waiting
in the C<output> attribute, so this method traditionally manipulates
C<$self-E<gt>{'output'}> directly.

=cut

sub post_process {
	my ($self) = @_;
	return;
}
=pod

=item add_headers

Called by handler on a successful responses from C<process> and C<respond>. Adds
some standard headers to the response or can be overridden.  By default, it adds
headers to help with compatibility with AOL's famously broken proxies and other
similar problems.

=cut

sub add_headers {
	my ($self) = @_;
	my $req = $self->{'req'};
	$req->no_cache(1);
	$req->headers_out->set('Vary', '*');
	return;
}

=pod

=item get_file

Based on the request, locates the file to be used and sets the file
attribute to that path.  It declines non-text/html files (via mime type)
and, on accepting a file, passes the mtime and size of the file to the
init hashref for use by the Apache::Wyrd object.

=cut

sub get_file {
	my ($self, $file) = @_;
	$file ||= $self->{'req'}->filename;
	return DECLINED if (-d $file and $self->{'req'}->next);
	return DECLINED unless (-r _);
	return DECLINED unless ($self->{'req'}->content_type eq 'text/html');
	$self->{'file'} = $file;
	my @stats = stat _;
	foreach my $datum (
		qw(
			dev
			ino
			mode
			nlink
			uid
			gid
			rdev
			size
			atime
			mtime
			ctime
			blksize
			blocks
		)
					) {
		$self->{'init'}->{$datum} = shift @stats;
	}
	my $root = $self->{'req'}->document_root;
	$self->{'init'}->{'file_path'} = $file;
	$file =~ s#$root/*#/#;
	$self->{'init'}->{'self_path'} = $file;
	return;
}


=pod

=item globals

defines the hashref which will be kept by the DBL object.  Empty by default.

=cut

sub globals {
	return {};
}

=pod

=item init

defines the hashref which will be used to initialize the Apache::Wyrd objects. 
It B<must> return the request object under the key 'req', which is stored under
the C<Apache::Wyrd::Handler> attribute 'req' by the C<handler> method.  Any
other keys are optional.

By default, if the hash key 'error_page' is set (non-null), the installation
will use an error page with a debugging log.  See the C<errorpage> method.

Note also if you wish to pass data containing Wyrd constructions via CGI
variables, you need to list the variables by array reference here under the
taint_exceptions key.  For example, a site under the namespace "TESTSITE" has
a form with a text area called "widget_text" in which Wyrds may be composed.
This text area's name is included in the hashref values returned by init:

  sub init {
    my ($self) = @_;
    return {
      req => $self->{'req'},
      taint_exceptions => ['widget_text'],
      .... other init keys and values ...
    }
  }

Otherwise, any data submitted by the textarea will be ignored if it contains
any string beginning with E<lt>TESTSITE::.



( run in 2.218 seconds using v1.01-cache-2.11-cpan-5735350b133 )