Changes between Initial Version and Version 1 of Overriding


Ignore:
Timestamp:
Dec 17, 2010, 10:57:32 PM (14 years ago)
Author:
geofft@mit.edu
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Overriding

    v1 v1  
     1Imagine you've identified some function in the [browser:perl Perl source] that you'd like to override for some reason. Given the liberal use of Perl OO throughout the code, this is fairly likely. Assuming your problem is not better solved by CreatingAModule or using some other more public customization interface like writing a new style, how do you do this?
     2
     3Load some code like this:
     4
     5{{{
     6#!perl
     7no warnings 'redefine';
     8sub BarnOwl::Message::Zephyr::zsig {
     9   return "My zsig is " . shift->{zsig};
     10}
     11}}}
     12
     13There are a couple of ways to load in code: one is to put it in a file, and run `:perl do '/home/me/file.pl'`; another is to use Nelson's !DevUtils module to get an :eperl command that lets you compose Perl to be evaluated the same way you would compose a new message.
     14
     15For a practical example of this technique, see Nelson's Alias module, which overrides the "context" property getter on zephyrs (which displays the class name) to allow you to display abbreviated or redacted class names. This makes the replacement compatible with any style, since they all just call `->context`.
     16
     17The two modules referenced can be found in [http://web.mit.edu/nelhage/Public/BarnOwl/ /mit/nelhage/Public/BarnOwl].