OC-PM: EasySlice and Source Filters?

Wilson, Douglas dgwilson at sonomasystems.net
Fri Jan 10 11:41:31 CST 2003


I thought of a big improvement to my last source filter, so now I don't
have to buffer any source, and it could now probably even be done with
Filter::Simple, though I haven't yet installed or looked at that module...

Hope somebody enjoys this...

package MethodFilter;
#
# Use methods with a single colon
# (":") character in them
# as bare words.
# Author: Douglas Wilson
#
# E.g. Package->foo:bar;
# creates package variable $MethodFilter::_foo_bar,
# sets it to 'foo:bar', and substitutes the variable name
# into the method call
#
# Known issues:
# 1) $condtion ? $obj->method:function();
#    (just put white space around the ":" to fix it)
# 2) single quoted strings containing, e.g., '->word:word'
#    (break up the string: '->' . 'word:word')
# 3) Line break after method operator '->'
#    (break the line before the '->')
#
use strict;
use warnings;
use Filter::Util::Call;

use vars qw($tmp);

sub import {
  filter_add(
    sub {
      my ($status);
      s/
        (?<=->)((\w+):(\w+))
        (?{
          no strict 'refs';
          $tmp = __PACKAGE__ . "::$_{2}_${3}";
          $$tmp = $1;
        })
      /\$$tmp/gx if ($status = filter_read()) > 0;
      $status;
    }
  );
}

1;



More information about the Oc-pm mailing list