Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • The closest I've come up with so far is this:

    #!/usr/bin/perl -l

    use strict;
    use warnings;

    {

        package KillMeNow;
        sub whee { return 'whee!' }
        sub new { bless {}, shift }
    }

    {

        package DontKillMe;
        sub whee { return 'asdfasdf' }
    }

    {

        package KillMeLater;
        @KillMeLater::ISA = 'KillMeNow';
        use overload '%{}' => sub {
            @KillMeLater::ISA =
              rand 1 > .5
              ? 'KillMeNow'
              : 'DontKillMe';
            return shift;
          },
          fallback => 1;

        sub new { bless {} => shift }
        sub whee {
            my $self = shift;
            no warnings 'void';
            %$self;
            $self->SUPER::whee;
        }
    }

    for ( 1 .. 20 ) {
        print KillMeLater->new->whee;
    }

    It works, but it's not what I wanted. I could possibly automate that, but this is harder than it seems.