Issues with subroutines and unbless references
am 22.06.2010 12:01:39 von Winfried NeessenHi,
I'm pretty new to mod_perl/Apache2::* and I'm already struggling around with
my first problem.
I am writing a script which later will be kind of proxy server for our self
written application.
I need to alter/manage some of the HTTP headers sent by the application. My
script is currently
not useable at all, though it already provides an error to me which I can't
get rid of.
I have a subroutine "handler" where I import the HTTP object from mod_perl
via: my $r = shift;
This works well and as expected. But if I wanna use that object later on in
a different
subroutine, I get the following error message everytime I try to use the $r
object in the
subroutine: "argument is not a blessed reference (expecting an APR::Table
derived object)"
Here is a code example of what I've written:
====================== begin code snippet =================================
## The main program handler // handler() {{{
sub handler
{
## Get HTTP Apache object
my $r = shift;
## Get a log object
my $log = get_logger( 'handler' );
## Log a start message
$log->info( __PACKAGE__ . ' successfully started.' );
## Get allowed headers as hashref
my $headers = getAllowedHeaders( $r );
## Exit gracefully
$r->content_type( 'text/html' );
return Apache2::Const::OK;
}
# }}}
## Extract sent HTTP headers and extract the allowed ones //
getAllowedHeaders() {{{
sub getAllowedHeaders
{
## Get Logger object
my $log = get_logger( 'getAllowedHeaders' );
## Get HTTP object from caller
my $r = shift;
## Define a temp. header hashref
my $header;
## Go through the list of allowed headers and check if the are
defined {{{
foreach my $head ( sort ALLOWED_HEADER )
{
## Check if the HTTP object has the corresponding header set
next unless defined( $r->headers_in( $head ) );
## Extract value from HTTP object
my $value = $r->headers_in( $head );
## Log a debug message
EXT_DEBUG && $log->debug( 'Found allowed HTTP header "' .
$head . ' with value: ' . $value );
## If the header is defined in the HTTP object, store it for
later usage
$header->{ $head } = $value;
}
# }}}
## Return the hashref
return $header;
}
# }}}
====================== end code snippet =================================
Whenever I call the "$r->headers_in( $head )" in the getAllowedHeaders
subroutine I
receive the error message about the unblessed reference.
Any hint about how to fix this issue would be greatly appreciated.
Thanks
Winni