No, I wouldn't put it in an import module. A BEGIN block would be better. If you put it in import, you have no guarantee that the import method will ever actually be called. It's quite easy to load a module without ever calling the import method. Conversely, it's very easy for the import method to get called multiple times.
I actually do something pretty similar to the technique being discussed in XML::LibXML::Augment.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
| [reply] [d/l] [select] |
What's the advantage of using a BEGIN block for that? Do you really think there's something to gain putting those methods in place, before the other methods are compiled?
| [reply] |
Very little advantage in this case. It just so happens that in the same loop I'm also playing around with @ISA and past experience has taught me to alter @ISA as early as possible. Modern versions of Perl are pretty smart when it comes to invalidating method resolution caches, but force of habit makes me put any @ISA alteration in a BEGIN block unless there's a good reason not to.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
| [reply] [d/l] [select] |
Sounds like a bad idea to me. Why do you think that's a good idea? | [reply] |