Changes between Initial Version and Version 1 of Overriding

Dec 17, 2010, 10:57:32 PM (7 years ago)



  • 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?
     3Load some code like this:
     7no warnings 'redefine';
     8sub BarnOwl::Message::Zephyr::zsig {
     9   return "My zsig is " . shift->{zsig};
     13There are a couple of ways to load in code: one is to put it in a file, and run `:perl do '/home/me/'`; 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.
     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`.
     17The two modules referenced can be found in [ /mit/nelhage/Public/BarnOwl].