in reply to Is it useful to edit code at execution time?
That said, the facilities for this sort of thing aren't very good in Perl. The first problem is that there isn't a stable Perl parser, other than perl. PPI does as best you can and the author will freely admit there are simple snippets that it will simply fail on. Perl 6 will do this a lot better and, I suspect, you will see a lot more of this sort of thing when Perl 6 comes out, particularly with macros.
For the record, I wrote Sub::Compose as an experiment for the pre-alpha version of Moose. When stvn and I were doing the initial spike that eventually became the pre- and post- processors for methods in Class::MOP, we were playing with restrictions on accessors. The idea was to have a bunch of simple-minded restrictions (cannot be undef, must have a certain length, must be greater than X, must be less than Y, etc). Then, you could chain those restrictions together in neat ways. Except, like everything in Perl that depends on a large number of tiny subroutines, performance was abysmal; the sub-calling overhead was just too high. So, I played around with making them all one subroutine and released that. You'll notice it's been a 0.01 for over 2 years. I honestly don't think anyone's ever used it. I've never received any email about it.
|
|---|