Apache-Wyrd

 view release on metacpan or  search on metacpan

Wyrd/Handler.pm  view on Meta::CPAN

	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::.

=cut

sub init {
	my ($self) = @_;
	return {
		req => $self->{'req'}
	};
}


=pod

=item process

"Hook" method for introducing other handling checks to the request.  It should
return an Apache::Constants value if it wants to override the response of the
C<respond> method.  If it does this override, then it is responsible for setting
it's own headers.

=cut

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

=pod

=item respond

Does the work of setting up the found page as an Apache::Wyrd object and calling
it's C<output> method.  Should probably not be overridden, unless there are
tweaks that cannot be accomplished in C<add_headers> and C<process>.

=cut

sub respond {
	my ($self) = @_;
	my $client = $self->{'client'};
	my $dbl_create = 'Apache::Wyrd::DBL->new($self->{"init"});';
	my $wo_create = 'Apache::Wyrd->new($dbl, {_data => $$data});';
	if ($self->{'client'}) {
		eval ("use " . $client . "::DBL");
		die ("$@:\nA base class $client\::DBL needs to be defined before using Apache::Wyrd") if ($@);
		eval ("use $client\::Wyrd");
		die ("$@\:\nA base class $client\::Wyrd needs to be defined before using Apache::Wyrd") if ($@);
		$dbl_create =~ s/^Apache::Wyrd/$self->{client}/;
		$wo_create =~ s/^Apache/$self->{client}/;
	}
	my ($dbl, $object) = ();
	eval("\$dbl=$dbl_create");
	die ($@) if ($@);
	my $data = slurp_file($self->{'file'});



( run in 1.104 second using v1.01-cache-2.11-cpan-39bf76dae61 )