Apache-HTMLView
view release on metacpan or search on metacpan
HTMLView.pm view on Meta::CPAN
sub new {
my $this = shift;
my $class = ref($this) || $this;
my $self= bless {}, $class;
}
sub execute
{shift->{'first'}=1}
sub fetchrow_arrayref {
my ($self)=@_;
if ($self->{'first'}) {
$self->{'first'}=0;
$a[0]='';
return \@a;
}
return [];
}
}
#############################################################
# The handler, this parses the request and returns the page #
#############################################################
sub handler {
my $r = shift;
## Determine which fmt_dir to use
%actions = %{$actionlist{$r->dir_config('Name')}};
%fmts = %{$fmtlist{$r->dir_config('Name')}};
## Reading request params
my $uri = $r->uri;
$uri =~ /\/([^\/]*)$/;
$file = $1;
my $q = new CGI();
## Make buttonspecifik param overrides overide the defaults
if (defined $q->param('_but') && defined $q->param('_but_'.$q->param('_but'))){
my $oq=new CGI($q->param('_but_'.$q->param('_but')));
foreach ($oq->param) {
$q->param($_, $oq->param($_));
}
}
## Execute requst action
if (defined $q && defined $q->param('_pre_action')) {
$actions{$q->param('_pre_action')}->($q, $r)
}
## Update database if requested
if (defined $actions{$file}) {
$actions{$file}->($q,$r);
## Decide what to show next
$file=$q->param('_done');
if (!defined $file || lc($file) eq 'ref') {$file=$r->headers_in->{'Referer'};}
## Send client to that fmt
$r->header_out(Location=>$file);
return REDIRECT;
} else {
## Bring up requested fmt
my @sel;
# if (defined $q) {@sel=split(/,\s*/,$q->param('sel'));}
if (defined $q) {@sel=$q->param('sel');}
if (defined $fmts{$file}) {
$r->content_type('text/html');
$r->send_http_header;
$r->print($fmts{$file}->(\@sel, $q, $r));
return OK;
} else {
# Let someone else handle the request
return DECLINED;
}
}
}
########################
# Reading all fmt-dirs #
########################
BEGIN {
# Finding all dirs
my @fmt_dirs = grep {
$_ =~ /_fmtpath$/
} keys %{ Apache->server->dir_config() };
my $fsth=fake_sth->new();
foreach my $fmt_dir ( @fmt_dirs ) {
my $fmtdir = Apache->server->dir_config( $fmt_dir );
my $fmtname = $fmt_dir;
$fmtname =~ s/_fmtpath$//;
my $dbistr = Apache->server->dir_config($fmtname . "_DBIstr");
my $dbiuser = Apache->server->dir_config($fmtname . "_DBI_User");
my $dbipasswd = Apache->server->dir_config($fmtname . "_DBI_Password");
# Making sure the DB exsists and caching a handle to it
DBI->connect($dbistr, $dbiuser, $dbipasswd)->disconnect();
# Load the compiled fmts and the htmlfile
# Maby use Apache::File ??????
foreach (`ls $fmtdir/*`)
{
# Reading the file
chop;
my $name= $_ ;
( run in 0.844 second using v1.01-cache-2.11-cpan-e1769b4cff6 )