Filter::EOF(3pm)
β¨ 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
π AUTHOR AND COPYRIGHT π
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
- ubuntu noble: libfilter-eof-perl 0.04-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libfilter-eof-perl 0.04-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfilter-eof-perl 0.04-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms