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

Hi, I am newbie in source filters.
All manuals I read before tells how to filter your own package. This will filter Foo's code.
package Foo; use Filter::cpp; ...
But is it possible to filter some other module before including it in my code? Smth like
package Foo; use strict; use_filtered Bar; # instead of "use Bar"

Replies are listed 'Best First'.
Re: Source filters: filter some module before including in my package
by Corion (Patriarch) on Sep 15, 2011 at 14:49 UTC

    Maybe you want to see require on how to replace code before it is loaded?

      Yeah, really forgot about require hooks. This totally solves my problem. Thanks.
      Can you tell me why nothing works?
      push @INC, \&my_sub; sub my_sub { my ($self, $filename) = @_; warn $filename; } require IO::Socket;
      Expected at least output smth like: "/usr/lib/perl5/IO/Socket.pm", but get nothing. Whats wrong?
        Ok, I understand. I should unshift for my purposes instead of push.
Re: Source filters: filter some module before including in my package
by afoken (Chancellor) on Sep 15, 2011 at 14:51 UTC
    But is it possible to filter some other module before including it in my code?

    Why? Sounds like an XY Problem.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      Maybe, maybe. I want to prevent exceptions catching in some package. One of the possible solution was in my previous topic. This is another possible solution.