Can't call method "is_initial_req" without a package or object reference at .........
All, I'm having some problems with Apache giving me grief, or most probably me getting my knickers in a complete twist. I get the following error:- Can't call method "is_initial_req" without a package or object reference at . It seems to happen when my URL ends like this:- /somepath/16 but not when it ends like this:- /somepath/16/ Below is the code which is where the error occurs. sub handler { my $r = My::Apache::Request->instance(shift); print STDERR Dumper($r); print STDERR "\n\n\nBOOOBS\n\n\n\n\n"; die "$r not defined" unless $r; return OK unless $r->is_initial_req();#ERROR OCCURS HERE my $uri = $r->uri; my $log = $r->log; .. } The handler is simply a multiplexer which based upon a database configuration adds the relevant method handler to the handlers queue. The 'instance' routine for My::Apache::Request is inheritted from the Apache::Request class. the 'new' routine for My::Apache::Request is as follows:- sub new { my ($class, $r) = @_; my $length=32; unless ($r->is_main ) { print STDERR "Apache::Request is not Main, Getting Main\n"; print STDERR Dumper($r); $r=$r->main; print STDERR "Main Apache::Request is:-\n"; print STDERR Dumper($r); print STDERR "DECLINING\n"; return DECLINED; } unless ($r) { print STDERR "making a new Request object\n"; $r = Apache->request; } $r=Apache::Request->new($r); my $self = bless {_r => $r}, $class; my $t=substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, $length); $self->{XX_created_time_XX}=$t; my @params=$self->param(); print STDERR "Here's the Parameters for $class\n"; print STDERR Dumper(@params); my $lang_id=$self->param('lang_id'); if ($lang_id) { $lh=My::Maketext->get_handle($class,$lang_id); } else { $lh=My::Maketext->get_handle($class,My::Conf::DEFAULT_LANGUAGE_ID); } print STDERR "Creating ".ref($self)." $t\n"; #$self->interpret_uri; return $self; }
Re: Can't call method "is_initial_req" without a package or object reference at .........
Ok, that makes sense, thank you:-) But 'What' should I return, is $r->main the right thing to return? > > unless ($r->is_main ) > > { > > print STDERR "Apache::Request is not Main, Getting Main\n"; > > print STDERR Dumper($r); > > $r=$r->main; > > print STDERR "Main Apache::Request is:-\n"; > > print STDERR Dumper($r); > > print STDERR "DECLINING\n"; > > return DECLINED; > > } > > you're not returning an object from your constructor on internal redirects :) > > HTH > > --Geoff > >
Re: Can't call method "is_initial_req" without a package or object reference at .........
Thanks Geoffrey. Marty - Original Message - From: "Geoffrey Young" <[EMAIL PROTECTED]> To: "Martin Moss" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Tuesday, June 17, 2003 4:23 PM Subject: Re: Can't call method "is_initial_req" without a package or object reference at . > > > Martin Moss wrote: > > Ok, that makes sense, thank you:-) > > But 'What' should I return, is $r->main the right thing to return? > > I've found that it's pretty rare that you want to mess with main vs subrequest logic > yourself. instead, I would just make the constructor return an object based on whatever > mod_perl passes it which is, in turn, whatever request record Apache deems to be the > proper one for the current (sub)request. > > so new() should probably just be something like > > sub new { > >my ($class, $r) = @_; > >$r = Apache::Request->new($r); > >my $self = bless {_r => $r}, $class; > >$self->init(); > >return $self; > } > > if it is important to insure that you only populate object attributes once, even in the > case of internal redirects or lookups, you could hang attributes off of pnotes in the main > request > > sub init { > >my $self = shift; > >$t = ubstr(Digest::MD5...); > >if ($r->main) { > $self->{XX_created_time_XX} = $t; > $self->{_r}->pnotes(XX_created_time_XX => $t) >} >else { > $t = $self->{_r}->main->pnotes('XX_created_time_XX'); >} >... > } > > or somesuch. untested, but you get the idea :) > > HTH > > --Geoff > >