Friday, July 28, 2006

OSCON: Day three part 2

Next up was Chromatic's talk on Perl Hacks. I was looking forward to this one, especially after that disappointing "extreme Perl makeover" talk.

The presentation got off to a good start. Chromatic started with some perldoc command-line args, such as the -i (case-insentivie), -m (show source) and -l (display the path to the file). Here's a quick way to edit an installed module: vim $( perldoc -l Some::Module )

Whoa! You can put subroutine references in @INC! Dude. Apparently he picked this tip up from Nick Clark. You can return a filehandle, which Perl will use as the module contents. He then demonstrated a hack that uses this trick and Perl::Critic to review every module before it gets loaded. Impressive.

Next was an explanation of attributes. He showed us the Attribute::Handlers module. One useful application was Attribute::Method that allows you to access the invocant ("self") without declaring or shifting it.

Next up was the subject of calling C from Perl. He showed us a module called P5NCI that allows you to call functions in shared libraries without writing any XS glue code. Mark was sitting right up front and actually clapped for this one. But it got better! He also demonstrated some absurdly nice syntactic sugar to go along with it.

He went on to discuss a way to create private methods. The implementation involves using symbolic method calls to use names that the parser doesn't allow. Of course, it's exposed through extremely nice-looking attribute syntax.

The next hack was a great way to test well-encapsulated modules. The coolest part was that you could create a proxy that can test an object using live data while performing its usual tasks.

Yay! Perl 5.10 allows you to create your own pragmas. It's a simple matter of adding a key to the %^H (hints hash) during your import, and this allows you determine whether your pragma is active in a given scope. Many useful applications for this.


Post a Comment

Links to this post:

Create a Link

<< Home