done, done, I'm onto the next one

richardc on 2002-10-29T12:18:07

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 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.