The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


sealed - Subroutine attribute for compile-time method lookups on its typed lexicals.


    use Apache2::RequestRec;
    use base 'sealed';

    sub handler :Sealed {
      my Apache2::RequestRec $r = shift;
      $r->content_type("text/html"); # compile-time method lookup.

import() Options

    use sealed 'debug';   # warns about 'method_named' op tweaks
    use sealed 'deparse'; # additionally warns with the B::Deparse output
    use sealed 'dump';    # warns with the $op->dump during the tree walk
    use sealed 'disabled';# disables all CV tweaks
    use sealed;           # disables all warnings


You may need to simplify your named method call argument stack, because this op-tree walker isn't as robust as it needs to be. For example, any "branching" done in the target method's argument stack, eg by using the '?:' ternary operator, will break this logic (pushmark ops are processed linearly, by $op->next walking, in tweak()).

Compiling perl v5.30+ for functional mod_perl2 w/ithreads and httpd 2.4.x w/event mpm

    % ./Configure -Uusemymalloc -Duseshrplib -Dusedtrace -Duseithreads -des && make -j$(nproc) && sudo make -j$(nproc) install

In an ithread setting, running w/ :sealed subs v4.1+ involves a tuning commitment to each ithread it is active on, to avoid garbage collecting the ithread until the process is at its global exit point. For mod_perl, ensure you never reap new ithreads from the mod_perl portion of the tune, only from the mpm_event worker process tune or during httpd server (graceful) restart.



Don't use typed lexicals under a :sealed sub for API method argument processing, if you are writing a reusable OO module (on CPAN, say). This module primarily targets end-applications: virtual method lookups and duck typing are core elements of any dynamic language's OO feature design, and Perl is no different.

Look into XS if you want peak performance in reusable OO methods you wish to provide. The only rational targets for :sealed subs with typed lexicals are methods implemented in XS, where the overhead of traditional OO virtual-method lookup is on the same order as the actual duration of the invoked method call. For nontrivial methods implemented entirely in Perl itself, the op-tree processing overhead involved during execution of those methods will drown out any performance gains this module would otherwise provide.



Apache License 2.0