goto::file(3pm)
π goto::file π
okay so bestie, welcome to the manual page for goto::file β it's a Perl module, it lives in the User Contributed Perl Documentation corner of your man pages, and it does exactly one weird little thing extremely well. π
β¨ NAME β¨
goto::file β stop parsing the current file and move on to a different one. π¦
πΈ DESCRIPTION πΈ
Okay so like, it's rare, right? But sometimes you genuinely want to swap out the file that's currently being compiled for a whole different file. That's what this module does. From the exact moment you use the module, perl is parsing the new file instead of the original one. No cap. π
π WHY?! π
Okay so this was created specifically for Test2::Harness, which can preload modules and fork to run each test. π
The problem was that using do to execute the test files post-fork was resulting in extra frames in the stack traceβ¦ in other words, there are <em>a lot</em> of tests that assume the test file is the bottom of the stack. This happens all the time, specially if stack traces need to be verified. π
This module allows Test2::Harness to swap out the main script for the new file without adding a stack frame. It's giving surgical precision, honestly. β¨
π SYNOPSIS π
Plain and simple:
#!/usr/bin/perl
use goto::file 'some_file.pl';
die "This will never be seen!";
__DATA__
This data will not be seen by <DATA>
More useful:
#!/usr/bin/perl
BEGIN {
my $file = should_switch_files();
if ($file) {
print "about to switch to file '$file'\n";
require goto::file;
goto::file->import($file);
}
}
print "Did not go to a file\n";
Another thing you can do:
use goto::file [
'print "Hi!\n";',
"exit 0",
];
die "Will not get here";
π NOTES π
__DATA__ and <DATA>
This module does its very best to make sure the data you get from <DATA> comes from the NEW file, and not the old one. π
At the moment there are no known failure cases, but there could be some. π«Ά
π§ IMPLEMENTATION DETAILS π§
This is a source filter. The source filter simply disgards the lines from the original file and instead feeds perl lines from the new file. π¦
There is also a small source injection at the start that sets up "<DATA>" and makes sure line numbers and file name are all correct. β¨
π SOURCE π
The source code repository for goto-file can be found at http://github.com/exodist/goto-file/. Go be nosy, bestie. π₯
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
β AUTHORS β
Chad Granum <exodist@cpan.org>
πΈ COPYRIGHT πΈ
Copyright 2017 Chad Granum <exodist7@gmail.com>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
and that's the whole page, bestie β this doc is from perl v5.36.0, dated 2023-01-24, and it's the goto::file(3pm) page, so go forth and swap files responsibly πβ¨π
π¦ where this page comes from
- debian bookworm: libgoto-file-perl 0.005-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libgoto-file-perl 0.005-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libgoto-file-perl 0.005-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libgoto-file-perl 0.005-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libgoto-file-perl 0.005-2 Β· 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