[Israel.pm] bless and AUTOLOAD

Gaal Yahas gaal at forum2.org
Tue Sep 25 16:20:16 PDT 2007


Or:

no AutoloadedDestroy;

...

package AutoloadedDestroy;

no strict 'refs'; # somebody should write an Acme::Damian that does this for you

sub import {
    # We can't delete the sub, but we can fake it.
    # (I think. I never tested this code.)
    # (I didn't even compile it.)
    # (Really. Use at your own risk.)
    my $caller = caller;
    *{"$caller\::DESTROY} = sub {
        *{"$caller\::AUTOLOAD"} = "$caller\::DESTROY";
        goto &{"$caller\::AUTOLOAD"};
    };
}

sub unimport {
    my $caller = caller;
    *{$caller\::AUTOLOAD} = sub {};
}

__END__

On 9/25/07, Yuval Kogman <nothingmuch at woobling.org> wrote:
> Slightly less ugly but more kookie is Module::Compile::TT
>
> On Tue, Sep 25, 2007 at 21:38:10 +0200, Yuval Yaari wrote:
> > Yona Shlomo wrote:
> > > Is well in place, but alas, I'm too lazy to implement
> > > several dozens of functions/methods that are the same except
> > > for their name... and then change (all of them with no
> > > mistakes) then when needed...
> > >
> > How about...
> >
> > <UGLY>
> > BEGIN {
> >     no strict 'refs';
> >     *{__PACKAGE__ . '::' . $_} = sub {}
> >             for qw/foo bar baz DESTROY/;
> > }
> > </UGLY>
> >
> > HTH :-)
> >
> >   ~Y
> > _______________________________________________
> > Perl mailing list
> > Perl at perl.org.il
> > http://perl.org.il/mailman/listinfo/perl
>
> --
>   Yuval Kogman <nothingmuch at woobling.org>
> http://nothingmuch.woobling.org  0xEBD27418
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>


-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/



More information about the Perl mailing list