1goto::file(3)         User Contributed Perl Documentation        goto::file(3)
2
3
4

NAME

6       goto::file - Stop parsing the current file and move on to a different
7       one.
8

DESCRIPTION

10       It is rare, but there are times where you want to swap out the
11       currently compiling file for a different one. This module does that.
12       From the point you "use" the module perl will be parsing the new file
13       instead of the original.
14

WHY?!

16       This was created specifically for Test2::Harness which can preload
17       modules and fork to run each test. The problem was that using "do" to
18       execute the test files post-fork was resuling in extra frames in the
19       stack trace... in other words there are a lot of tests that assume the
20       test file is the bottom of the stack. This happens all the time,
21       specially if stack traces need to be verified.
22
23       This module allows Test2::Harness to swap out the main script for the
24       new file without adding a stack frame.
25

SYNOPSIS

27       Plain and simple:
28
29           #!/usr/bin/perl
30
31           use goto::file 'some_file.pl';
32
33           die "This will never be seen!";
34
35           __DATA__
36
37           This data will not be seen by <DATA>
38
39       More useful:
40
41           #!/usr/bin/perl
42
43           BEGIN {
44               my $file = should_switch_files();
45
46               if ($file) {
47                   print "about to switch to file '$file'\n";
48                   require goto::file;
49                   goto::file->import($file);
50               }
51           }
52
53           print "Did not go to a file\n";
54
55       Another thing you can do:
56
57           use goto::file [
58               'print "Hi!\n";',
59               "exit 0",
60           ];
61
62           die "Will not get here";
63

NOTES

65       __DATA__ and <DATA>
66           This module does its very best to make sure the data you get from
67           <DATA> comes from the NEW file, and not the old. At the moment
68           there are no known failure cases, but there could be some.
69

IMPLEMENTATION DETAILS

71       This is a source filter. The source filter simply disgards the lines
72       from the original file and instead feeds perl lines from the new file.
73       There is also a small source injection at the start that sets up
74       "<DATA>" and makes sure line numbers and file name are all correct.
75

SOURCE

77       The source code repository for goto-file can be found at
78       http://github.com/exodist/goto-file/.
79

MAINTAINERS

81       Chad Granum <exodist@cpan.org>
82

AUTHORS

84       Chad Granum <exodist@cpan.org>
85
87       Copyright 2017 Chad Granum <exodist7@gmail.com>.
88
89       This program is free software; you can redistribute it and/or modify it
90       under the same terms as Perl itself.
91
92       See http://dev.perl.org/licenses/
93
94
95
96perl v5.32.0                      2020-07-28                     goto::file(3)
Impressum