use strict;
use warnings;
use Cwd qw(abs_path);
use File::Basename qw(dirname);
use File::Spec;

BEGIN {
    return if $ENV{'BCQ_TEXINPUTS_SET'};

    my $repo_root = dirname(abs_path(__FILE__));
    my $examples_dir = File::Spec->catdir($repo_root, 'examples');
    my $existing = $ENV{'TEXINPUTS'};

    if (defined $existing && length $existing) {
        $ENV{'TEXINPUTS'} = join(':', $repo_root, $examples_dir, $existing);
    } else {
        $ENV{'TEXINPUTS'} = join(':', $repo_root, $examples_dir, '');
    }

    $ENV{'BCQ_TEXINPUTS_SET'} = 1;
}
