The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::Yath::Filter - Source filter used to make yath preload+fork work without any extra stack frames.

DESCRIPTION

This is a source filter that allows the yath script to change itself into your test file post-fork in preload mode.

The "obvious" was to preload+fork would be to preload, then fork, then use do or require to execute the test file. The problem with the "obvious" way is that your test file is no longer the bottom of the stack, The code that called your test file is. This has implications for stack traces, warnings, caller, and several other things.

Ideally the test file will be the bottom of the stack, no caller. This is REALLY hard to do. Special form of goto &code cannot do it, and there is no equivilent for files. We also cannot use exec, that defeats the purpose of preload.

What this filter does is it prevents the parser from reading the rest of the originally running script (usually yath itself) and instead returns lines from the test file. It also uses some #line magic to make sure filename and line numbers are all correct.

SYNOPSIS

    #!/usr/bin/perl

    BEGIN {
        my $test_file = do_stuff();
        require App::Yath::Filter;
        App::Yath::Filter->import($test_file);
    }

    die "This statement will never be seen! Lines from the test file will be seen instead.";

Sometimes yath gets codeblocks instead of files, this filter will inject lines that call the sub in such cases.

    #!/usr/bin/perl

    BEGIN {
        require App::Yath::Filter;
        App::Yath::Filter->import(sub { ok(1, "pass") });
    }

    die "This statement will never be seen!";

SOURCE

The source code repository for Test2-Harness can be found at http://github.com/Test-More/Test2-Harness/.

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/