Filter::EOF(3pm)

πŸ“¦
version 0.04 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

✨ Filter::EOF ✨

Okay bestie, buckle up, because this is Filter::EOF (a 3pm manual page, yes, we're being ✨official✨). It's a Perl module that lets you run a callback after a file has been compiled. That's the whole vibe. πŸ’…


πŸŽ€ VERSION πŸŽ€

0.04 β€” she's a lil vintage but she works. πŸ‘‘


🌸 SYNOPSIS 🌸

This is what using it looks like, in full, no edits, no notes:

 package MyPackage;
 use warnings;
 use strict;

 use Filter::EOF;

 sub import {
     my ($class, @args) = @_;
     my $caller = scalar caller;

     # set the COMPILE_TIME package var to a false value
     # when the file was compiled
     Filter::EOF->on_eof_call(sub {
         no strict 'refs';
         ${ $caller . '::COMPILE_TIME' } = 0;
     });

     # set the COMPILE_TIME package var to a true value when
     # we start compiling it.
     {   no strict 'refs';
         ${ $caller . '::COMPILE_TIME' } = 1;
     }
 }

 1;
 ...

 package MyUsingPackage;
 use warnings;
 use strict;

 our $COMPILE_TIME;
 use MyPackage;

 # prints 'yes'
 BEGIN { print +( $COMPILE_TIME ? 'yes' : 'no' ), "\n" }

 # prints 'no'
 print +( $COMPILE_TIME ? 'yes' : 'no' ), "\n";

 1;

Like… the BEGIN block prints 'yes' because compilation is literally happening, and the runtime line prints 'no' because it's done. Main character timeline behavior. ⏳✨


πŸ¦‹ DESCRIPTION πŸ¦‹

This module utilises Perl's source filters β€” yes, those source filters, we're going under the hood β€” to give you a mechanism to run some code after a file using your module has been processed. That's it, that's the dream. 🫢


πŸ’œ METHODS πŸ’œ

import( @functions )

Right now, the only thing you can get exported is a function equivalent of the on_eof_call method. That's the whole menu, babe, and it's a good menu:

 use Filter::EOF qw( on_eof_call );

 sub import {
     my ($class) = @_;
     ...
     on_eof_call { ... };
 }
 ...

on_eof_call( $code_ref )

Call this method inside your own import method to register a code reference that should be called when the file that's use-ing yours gets compiled. 🎯

Here's the little detail that matters, so pay attention bestie: the code reference gets a scalar reference as its first argument, pointing at an empty string. And if you change that string to something else? It gets appended at the end of the source. The way that works is genuinely iconic. 😭

 # call C<some_function()> after runtime.
 Filter->on_eof_call(sub {
     my $append = shift;
     $$append .= '; some_function(); 1;';
 });

🌈 EXPORTS 🌈

on_eof_call

You can optionally import the on_eof_call function into your namespace. Optional! Consent matters. 🫢


πŸ“ EXAMPLES πŸ“

That example from SYNOPSIS? It lives in the distribution directory examples/synopsis/. Go peek, no cap. πŸ‘€


πŸ‘‘ SEE ALSO πŸ‘‘

  • Filter::Call::Util
  • "Exporting without using Exporter's import method" in Exporter

Robert 'phaylon' Sedlacek β€” <rs@474.at>. Many thanks to Matt S Trout for the idea and inspirations on this module. 🫑 Precious.


🌟 LICENSE 🌟

This program is free software; you can redistribute it and/or modify it under the same terms as perl itself. Periodt.


fr fr, that's the whole page. nothing skipped, nothing invented, every flag, arg, default and path intact. slay. πŸ’…βœ¨

perl v5.36.0 Β· 2022-10-13 Β· and that's the Filter::EOF(3pm) footer, bestie β€” thanks for reading, mwah πŸ’‹πŸŒΈ

πŸ“¦ where this page comes from