Perl Advent Calendar 2008-12-01

Episode 208

by Jerrad Pierce

Thanks to recent lay-offs and the switch from toys to weapons of mass destruction—more bang for your labor buck afterall—Santa's workforce is down to a handful of Neptunians. To further demoralize his minions, Santa has taken to designating his organic production units by letters, rather than names. Worse still, a Neptunian's place in the alphabet indicates the fat one's regard for his position. Little surprise then that the IT guy is letter Y, just above the robot reindeer exhaust port scrubber.

Santa's a real ball-buster, and he forces Y to run code on a crufty old VAX, with the environment variable PERL5OPT=-MY:Tools to ensure that Y adheres to his B&D coding standards. Doing so loads a subclass of ToolSet, a manipulative which abstracts the cutting and pasting of frequently used code into a single statement.

Although it may not be clear from the example below, particularly since so many of Santa's favorite modules act globally, ToolSet's export method causes the specified modules to export into the caller's namespace. i.e; things are loaded in your local ToolSet, but the code use -ing ToolSet has access to the loaded libraries' methods and procedures; without fully-qualified names. That's pretty nifty but unfortunately, as of 0.14, ToolSet doesn't support things like no indirect.

mod1.pm

   1 package Y::Tools;
   2 use base 'ToolSet'; 
   3 
   4 #-T
   5 BEGIN{ use Taint::Runtime 'enable'; Taint::Runtime::taint_env }
   6 
   7 #-Mstrict
   8 ToolSet->set_strict(1);
   9 
  10 #-w, there doesn't seem to be a way to invoke -W at run time
  11 ToolSet->set_warnings(1);
  12 
  13 ToolSet->export(
  14 		#But we can still tighten things up…
  15 		'warnings' => [FATAL=>'all'],
  16 		
  17 		#…and reduce him to tears,
  18 		'criticism'=>'brutal',
  19 		
  20 		#with a lovely poem.
  21 		'Coy' => undef,
  22 		
  23 		#Finally, let's go one 'better' than strict
  24 		'Acme::use::strict::with::pride' => undef,
  25 	       );
  26 
  27 "I perform over fifty mega-checks per second!";