O'Reilly logo

Computer Science & Perl Programming by Jon Orwant

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 33. Source Filters

Paul Marquess

Tip

Looking back at this article a number of years after it was written, it strikes me that source filters were a cool idea waiting for a killer application to come along. Things would probably have stayed that way if Damian Conway hadn’t stumbled across them, because he has certainly put them to good use.

Damian currently has five CPAN modules using source filters. The cornerstone module is undoubtedly Filter::Simple, and anyone wanting to play further with source filters must have copy of this module. The interface it provides is much easier to use than the Filter::Util::Call module described in this article and will be adequate for 95% of applications.

Another module worth checking out for a real-life source filter is Switch, which adds a switch statement to Perl 5. The switch statement destined to be included in Perl 6 bears a striking resemblance to this one.

This article is about a little-known feature of Perl called source filters. Source filters alter the program text of a module before Perl sees it, much as a C preprocessor alters the source text of a C program before the compiler sees it. This article tells you more about what source filters are, how they work, and how to write your own.

The original purpose of source filters was to let you encrypt your program source to prevent casual piracy. This isn’t all they can do, as you’ll soon learn. But first, the basics.

Concepts

Before the Perl interpreter can execute a Perl script, the interpreter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required