gaja has asked for the wisdom of the Perl Monks concerning the following question:

Hi please anyone give the solution for this. I have create simple program AddFilterDyn.pm as follows
use strict; use warnings; my $r = shift; $r->content_type('text/plain'); print("Now is: " . scalar(localtime) . "\n");
It working properly when its call direct. But i have added a filters in httpd.conf file like
SetHandler modeperl PerlResponseHandler Apache2::AddFilterDyn
When i have added a filer then shows a error as Can't locate object method "content_type" via package "Apache2::Filter" Please anyone give the solution for it. Thanks in advance..

Replies are listed 'Best First'.
Re: Can't locate object method "content_type"
by Corion (Patriarch) on May 02, 2014 at 07:08 UTC

    Your first script can't work when called as a program:

    > perl -w tmp.pl Can't call method "content_type" on an undefined value at tmp.pl line +5.

    So whatever you're calling "direct" is a different program from what you're calling through mod_perl.

    Maybe your instance of modeperl is something different?

      Hi Corion, Thanks for your quickest reply. Myself its working properly and the output as Now is: Fri May 2 07:25:11 2014 But the problem is when i added a filters in httpd.conf file like
      SetHandler modeperl PerlResponseHandler Apache2::AddFilterDyn
      After i restarting a apache and running the index.pl file then shows a error as Can't locate object method "content_type" via package "Apache2::Filter"
      Hi Finally i found the solution. in .htaccess file need to add this.
      SetHandler perl-script PerlOptions +MergeHandlers PerlResponseHandler Apache2::AddFilterDyn
      Actually I already have one PerlResponseHandler ModPerl::Registry So, my AddFilterDyn filter is not working proper. PerlOptions +MergeHandlers gives the solution for it. Thanks all.