in reply to Re: Re: Template Method contra passing subroutines to constructor.
in thread Template Method contra passing subroutines to constructor.

I meant two different modules that want to use the same sub ref.
  • Comment on Re: Re: Re: Template Method contra passing subroutines to constructor.

Replies are listed 'Best First'.
Re: Re: Re: Re: Template Method contra passing subroutines to constructor.
by hardburn (Abbot) on Jan 13, 2004 at 19:06 UTC

    Hmm, in that case you might be constrained by your design, but it is still possible like this:

    package Foo; sub filter { . . . } package Bar; my $obj = Baz->new( \&Foo::filter );

    Admittedly, this could get hackish fast.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

      That would work, but by then there's no advantage to sub refs over inheritance. You are basically hard-coding inheritance here.