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

use Perl Log In

Log In

[ Create a new account ]

richardc (1662)

richardc
  (email not shown publicly)
http://unixbeard.net/~richardc/

Journal of richardc (1662)

Tuesday October 29, 2002
07:18 AM

done, done, I'm onto the next one

[ #8656 ]
Lately I seem to be susceptible to suggestion. The Foo Fighters new album is stuck in my head, Mark suggested writing extensions for File::Find::Rule so that it can do things like match on mime type, or image size, so I did that. You can too.

Then yesterday Nick put an idea into my head which rotted and started to become an evilness - Acme::Pie

What's so evil about pie you ask, after all, it's the best thing ever. Well try this:

=head1 NAME

Acme::Pie - when callback bring pie

=head1 SYNOPSIS

use Acme::Pie callback => \&foo;

sub foo {
     for (qw( Foo Bar Baz )) {
       $_->bar;
     }
}

ok( !Foo->can( 'pie' ), "of course Foo can't pie" );

foo();
ok(  Foo->can( 'pie' ), 'what?  when $callback brings pie' );

=head1 DESCRIPTION

Acme::Pie is an exploration of the amazing power of splicing optrees using the L<optimizer> module.  When the callback is invoked, any classes used by the method calls within that callback will suddenly find themselves with a fresh and tasty pie method.

  # before
  $foo->do_something;

  # is secretly morphed into
  $foo->want_pie;
  $foo->do_something;

The module doubles up any method call in a subroutine, to call both the intended method, and UNIVERSAL::want_pie.  UNIVERSAL::want_pie then simply identifies from which class it was called and splices in a pie method.

  sub UNIVERSAL::want_pie {
      my $class = ref $_[0] || $_[0];
      *{"$class\::pie"} = \&mmm_pie;
  }

=cut

Now I just need to write it.

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.