I'm using custom PerlTransHandler and while with Embperl it worked OK,
with EmbperlObject it does funny things. When I comment PerlTransHandler
out, it works again, but in my test case the handler just returns
DECLINED. The exact problem is this: after server restart, first time I
load the URL I get the right result and embperl log has the usual stuff.
Then after first reload it just say 'File not found', nothing is written
to the embperl log and apache error log says 'file not found'. Does
anybody have any idea what went wrong? Thanks.

- Robert


url
===
http://nbczsecure/hotel-2/index.html

config
======
<VirtualHost nbczsecure>
        ServerAdmin     germic
        DocumentRoot   
/mnt/web/projekty/netbooking/current/nbczsecure/doc
        ServerName      nbczsecure
        ErrorLog        logs/nbczsecure.error_log
        CustomLog       logs/nbczsecure.access_log combined
#        PerlSetEnv      EMBPERL_DEBUG   10477
        PerlTransHandler        NetBooking::StripHotelName
        <FilesMatch ".*\.html$">
                PerlSetEnv      EMBPERL_OBJECT_BASE base.html
                PerlSetEnv      EMBPERL_OBJECT_FALLBACK index.html
#                PerlSetEnv      EMBPERL_FILESMATCH "\.html$|\.epl$"
                SetHandler      perl-script
                PerlHandler     HTML::EmbperlObject
                Options         ExecCGI
        </FilesMatch>    
</VirtualHost>


error log
=========
[Mon Jan  8 15:01:57 2001] [error] EmbperlObject searched
';/mnt/web/projekty/netbooking/current/nbczsecure/doc/hotel-2;/mnt/web/projekty/netbooking/current/nbczsecure/doc'

/base.html
==========
[-
        sub new {
                my $self = shift;

                $self->{dbh} = $req_rec->pnotes('DBH') || 'no dbh';
                $self->{hotel_id} = $req_rec->pnotes('HOTEL_ID') || 'no
hid';
                $self->{short_name} = $req_rec->pnotes('SHORT_NAME') ||
'no name';
        }
        # ... tvuj stuff
-]

<body>

[- Execute '*' -]

<hr>
dbh = [+ $r->{dbh} +]<br>
hotel_id = [+ $r->{$hotel_id} +]<br>
short_name = [+ $r->{short_name} +]<br>

</body>


/hotel-2/index.html
===================
[-
        $r = shift;
        $r->new;
-]

<h1 style='color: red'>Booking form for hotel *[+ $r->{short_name}
+]*</h1>


handler
=======
package NetBooking::StripHotelName;

use strict;
use Apache::Constants qw/:common BAD_REQUEST/;
use Apache::Log();
use DBI;

sub handler {
        my $r = shift;

        # Don't connect if it's just a picture or styleshit
        return DECLINED if $r->uri =~ /\.gif$/ or $r->uri =~ /\.jpg$/ or
$r->uri =~ /\.css$/;

        my ($junk, $short_name, @rest) = split '/', $r->uri;

        # Fetch the hotel id from the database
        #my $dbh = DBI->connect('DBI:Pg:dbname=nbcz', '', '', {
RaiseError =>
1, AutoCommit => 1 });
        #my ($hotel_id, $short_name, $custom_page) =
$dbh->selectrow_array(
        #       "SELECT id,short_name,custom_page FROM hotel WHERE
short_name = ?",
{}, $short_name);
        my ($dbh, $hotel_id, $short_name, $custom_page) = (undef, 1,
'hotel-1',
1);
        #$r->log->error("DEBUG: hotel_id=$hotel_id,
short_name=$short_name,
custom_page=$custom_page ", $r->the_request);
        $r->pnotes('DBH' => $dbh);
        $r->pnotes('HOTEL_ID' => $hotel_id);
        $r->pnotes('SHORT_NAME' => $short_name);
        # Stay connected! (We pass the db handle around in $r->pnotes)
        #$dbh->disconnect;

        # If nothing found, hotel id is probably invalid
        unless ($hotel_id) {
                $r->log->error("Invalid hotel name!
(short_name=$short_name) ",
$r->the_request);
                # ted fakt nevim, co vratit, jeste se na to kouknu
(treba NOT_FOUND?)
                #return BAD_REQUEST;
                $r->args("error=invalid_hotel_id");
                $r->uri("/error.html");
                return DECLINED;
        }

        # If hotel has a directory with its own design, return something
        # like /hotel-2/index.html otherwise return just /index.html
        unless ($custom_page) {
                my $new_uri = @rest ? "/" . join("/", @rest) :
"/index.html";
                $r->uri($new_uri);
        }
        return DECLINED;
}

1;

__END__

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to