You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Chris Jacobson <ch...@online-rewards.com> on 2005/05/20 23:31:57 UTC
[mp2] Dynamically pushing output filters -- Questions
Hello,
I am attempting to write a system which allows output filters to be
dynamicaly pushed on the output filter stack at the end of a
PerlResponseHandler. These output filters are generated from a master
factory object.
....
my $FilterType = "Foo";
my $FilterObject = My::FilterFactory->new($FilterType); #
Class::Factory subclassed module
# This will generate a My::Filter::Foo object which inherits methods
from the factory object and overrides them as necessary
$r->add_output_filter($FilterObject->handler); # This call will Seg
Fault the server
.....
I can not seem to get anything to work here except a simple coderef.
This defeats my entire purpose of dynamically pushing filter handlers,
if they can only be a simple subroutine. Is there any possible way to
use an object as a filter handler, or can it only be a monolithic
subroutine code reference?
Thanks,
Chris
--
Chris Jacobson
Online-Rewards.com
2900 Jefferson Ave.
Cincinnati, OH 45219
513-665-9070 x310
http://www.online-rewards.com
Re: [mp2] Dynamically pushing output filters -- Questions
Posted by Chris Jacobson <ch...@online-rewards.com>.
Tom Schindl wrote:
> Chris Jacobson schrieb:
> | Hello,
> |
> | I am attempting to write a system which allows output filters to be
> | dynamicaly pushed on the output filter stack at the end of a
> | PerlResponseHandler. These output filters are generated from a master
> | factory object.
> | ....
> | my $FilterType = "Foo";
> | my $FilterObject = My::FilterFactory->new($FilterType); #
> | Class::Factory subclassed module
> | # This will generate a My::Filter::Foo object which inherits methods
> | from the factory object and overrides them as necessary
> | $r->add_output_filter($FilterObject->handler); # This call will Seg
> | Fault the server
> | .....
> |
>
> This is once more you benefit form the perl-closures many people stumble
> about ;-)
>
> $r->add_output_filter(sub { $FilterObject->handler(@_) });
>
> Tom
>
Brilliant. That works out perfectly! Adding the filter this way plus
making some minor changes to my factory generated filter objects has
solved the problem (and the seg faults!). Thanks Tom and Stas for the
pointers.
--
Chris Jacobson
Online-Rewards.com
2900 Jefferson Ave.
Cincinnati, OH 45219
(513) 665-9070 x310
http://www.online-rewards.com
Re: [mp2] Dynamically pushing output filters -- Questions
Posted by Tom Schindl <to...@gmx.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Chris Jacobson schrieb:
| Hello,
|
| I am attempting to write a system which allows output filters to be
| dynamicaly pushed on the output filter stack at the end of a
| PerlResponseHandler. These output filters are generated from a master
| factory object.
| ....
| my $FilterType = "Foo";
| my $FilterObject = My::FilterFactory->new($FilterType); #
| Class::Factory subclassed module
| # This will generate a My::Filter::Foo object which inherits methods
| from the factory object and overrides them as necessary
| $r->add_output_filter($FilterObject->handler); # This call will Seg
| Fault the server
| .....
|
This is once more you benefit form the perl-closures many people stumble
about ;-)
$r->add_output_filter(sub { $FilterObject->handler(@_) });
Tom
| I can not seem to get anything to work here except a simple coderef.
| This defeats my entire purpose of dynamically pushing filter handlers,
| if they can only be a simple subroutine. Is there any possible way to
| use an object as a filter handler, or can it only be a monolithic
| subroutine code reference?
|
| Thanks,
| Chris
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCkG/0kVPeOFLgZFIRAkUnAKCaeFnvhd3rAf8uMseypOn95uH/IwCcDlYL
S2p7lYLPGiaUEy7w0pHi4ik=
=kaUI
-----END PGP SIGNATURE-----
Re: [mp2] Dynamically pushing output filters -- Questions
Posted by Stas Bekman <st...@stason.org>.
Chris Jacobson wrote:
> Stas Bekman wrote:
>
>> Stas Bekman wrote:
>>
>>>> $r->add_output_filter($FilterObject->handler); # This call will Seg
>>>> Fault the server
>>>
>>>
>>
>>> The fact that you get a segfault is not good, we should take care of
>>> that.
>>
>>
>>
>> Chris, mind to give us a simple case to reproduce that segfault?
>>
> Not at all. I am under some pretty heavy deadlines at the moment. I
> will try to put together the simplest test case which reproduces the
> error over this weekend, however I have a feeling I was just doing
> something incredibly stupid ;>
Even so, no perl app should segfault. instead an error message should be
emitted. So we need to improve that. But take your time, of course :)
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [mp2] Dynamically pushing output filters -- Questions
Posted by Chris Jacobson <ch...@online-rewards.com>.
Stas Bekman wrote:
> Stas Bekman wrote:
>
>>> $r->add_output_filter($FilterObject->handler); # This call will Seg
>>> Fault the server
>>
>
>> The fact that you get a segfault is not good, we should take care of
>> that.
>
>
> Chris, mind to give us a simple case to reproduce that segfault?
>
Not at all. I am under some pretty heavy deadlines at the moment. I
will try to put together the simplest test case which reproduces the
error over this weekend, however I have a feeling I was just doing
something incredibly stupid ;>
--
Chris Jacobson
Online-Rewards.com
2900 Jefferson Ave.
Cincinnati, OH 45219
513-665-9070 x310
http://www.online-rewards.com
Re: [mp2] Dynamically pushing output filters -- Questions
Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
>> $r->add_output_filter($FilterObject->handler); # This call will Seg
>> Fault the server
> The fact that you get a segfault is not good, we should take care of
> that.
Chris, mind to give us a simple case to reproduce that segfault?
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [mp2] Dynamically pushing output filters -- Questions
Posted by Stas Bekman <st...@stason.org>.
Chris Jacobson wrote:
> Stas Bekman wrote:
>
>> Chris Jacobson wrote:
>>
>>> Hello,
>>>
>>> I am attempting to write a system which allows output filters to
>>> be dynamicaly pushed on the output filter stack at the end of a
>>> PerlResponseHandler.
>>
>>
>>
>> That doesn't make any sense, Chris. By the end of the
>> PerlResponseHandler the response is gone and there is nothing to
>> filter. You can only add it *before* you start sending any data.
>>
> Sorry about that. I am attempting to push the output filter handler
> before the end of the PerlResponseHandler. The code snippet from
> before which is generating the filter objects is run before calling
> $r->print().
That's better :)
>> The fact that you get a segfault is not good, we should take care of
>> that. regardless you code is incorrect.
>>
>>> I can not seem to get anything to work here except a simple coderef.
>>> This defeats my entire purpose of dynamically pushing filter
>>> handlers, if they can only be a simple subroutine. Is there any
>>> possible way to use an object as a filter handler, or can it only be
>>> a monolithic subroutine code reference?
>>
>>
>>
>> Filter handlers are very similar to all other mod_perl handlers, so
>> whatever works for mod_perl handlers works should work for filters.
>> I haven't tried using objects as filter handlers. May be in a few days
>> unless someone beats me to it.
>>
> Thanks for the response. I will keep tinkering with it over the weekend
> to see if I can resolve the seg faults.
I suppose we didn't put enough defense in the code accepting the callback
argument, expecting the user to do the right thing.
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [mp2] Dynamically pushing output filters -- Questions
Posted by Chris Jacobson <ch...@online-rewards.com>.
Stas Bekman wrote:
> Chris Jacobson wrote:
>
>> Hello,
>>
>> I am attempting to write a system which allows output filters to
>> be dynamicaly pushed on the output filter stack at the end of a
>> PerlResponseHandler.
>
>
> That doesn't make any sense, Chris. By the end of the
> PerlResponseHandler the response is gone and there is nothing to
> filter. You can only add it *before* you start sending any data.
>
Sorry about that. I am attempting to push the output filter handler
before the end of the PerlResponseHandler. The code snippet from
before which is generating the filter objects is run before calling
$r->print().
>
> The fact that you get a segfault is not good, we should take care of
> that. regardless you code is incorrect.
>
>> I can not seem to get anything to work here except a simple coderef.
>> This defeats my entire purpose of dynamically pushing filter
>> handlers, if they can only be a simple subroutine. Is there any
>> possible way to use an object as a filter handler, or can it only be
>> a monolithic subroutine code reference?
>
>
> Filter handlers are very similar to all other mod_perl handlers, so
> whatever works for mod_perl handlers works should work for filters.
> I haven't tried using objects as filter handlers. May be in a few days
> unless someone beats me to it.
>
Thanks for the response. I will keep tinkering with it over the weekend
to see if I can resolve the seg faults.
--
Chris Jacobson
Online-Rewards.com
2900 Jefferson Ave.
Cincinnati, OH 45219
(513) 665-9070 x310
http://www.online-rewards.com
Re: [mp2] Dynamically pushing output filters -- Questions
Posted by Stas Bekman <st...@stason.org>.
Chris Jacobson wrote:
> Hello,
>
> I am attempting to write a system which allows output filters to be
> dynamicaly pushed on the output filter stack at the end of a
> PerlResponseHandler.
That doesn't make any sense, Chris. By the end of the PerlResponseHandler
the response is gone and there is nothing to filter. You can only add it
*before* you start sending any data.
> These output filters are generated from a master
> factory object.
> ....
> my $FilterType = "Foo";
> my $FilterObject = My::FilterFactory->new($FilterType); #
> Class::Factory subclassed module
> # This will generate a My::Filter::Foo object which inherits methods
> from the factory object and overrides them as necessary
> $r->add_output_filter($FilterObject->handler); # This call will Seg
> Fault the server
You can't call the filter, you need to pass the name of the subroutine or
a reference to it. Please see:
http://perl.apache.org/docs/2.0/api/Apache2/Filter.html#C_add_output_filter_
The fact that you get a segfault is not good, we should take care of that.
regardless you code is incorrect.
> I can not seem to get anything to work here except a simple coderef.
> This defeats my entire purpose of dynamically pushing filter handlers,
> if they can only be a simple subroutine. Is there any possible way to
> use an object as a filter handler, or can it only be a monolithic
> subroutine code reference?
Filter handlers are very similar to all other mod_perl handlers, so
whatever works for mod_perl handlers works should work for filters.
I haven't tried using objects as filter handlers. May be in a few days
unless someone beats me to it.
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com