The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Dist::Zilla::Role::RequireFromBuild - Role to require() from build files

VERSION

This document describes version 0.007 of Dist::Zilla::Role::RequireFromBuild (from Perl distribution Dist-Zilla-Role-RequireFromBuild), released on 2022-02-19.

SYNOPSIS

In your plugin's preamble, include the role:

 with 'Dist::Zilla::Role::RequireFromBuild';

Then in your plugin subroutine, e.g. munge_files():

 $self->require_from_build("Foo/Bar.pm");
 $self->require_from_build("Baz::Quux");

DESCRIPTION

Since build files are not necessarily on-disk files, but might also be in-memory files or files with munged content, we cannot use require() directly. require_from_build() is like Perl's require() except it looks for files not from @INC but from build files $self->zilla->files. It searches libraries in lib/ and ..

$self->require_from_build("Foo/Bar.pm") or $self->require_from_build("Foo::Bar") is a convenient shortcut for something like:

 return if exists $INC{"Foo/Bar.pm"};

 my @files = grep { $_->name eq "lib/Foo/Bar.pm" } @{ $self->zilla->files };
 @files    = grep { $_->name eq "Foo/Bar.pm" }     @{ $self->zilla->files } unless @files;
 die "Can't find Foo/Bar.pm in lib/ or ./ in build files" unless @files;

 eval $files[0]->encoded_content;
 die if $@;

 $INC{"Foo/Bar.pm"} = "(set by Dist::Zilla::Role::RequireFromBuild, loaded from build file)";

PROVIDED METHODS

$obj->require_from_build( [ \%opts , ] $file)

Known options:

  • reload

    Bool. Optional, default false. If set to true, will reload the module even if it's already loaded.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Dist-Zilla-Role-RequireFromBuild.

SOURCE

Source repository is at https://github.com/perlancar/perl-Dist-Zilla-Role-RequireFromBuild.

SEE ALSO

Require::Hook::DzilBuild

Pod::Weaver::Role::RequireFromBuild

AUTHOR

perlancar <perlancar@cpan.org>

CONTRIBUTING

To contribute, you can send patches by email/via RT, or send pull requests on GitHub.

Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:

 % prove -l

If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla plugin and/or Pod::Weaver::Plugin. Any additional steps required beyond that are considered a bug and can be reported to me.

COPYRIGHT AND LICENSE

This software is copyright (c) 2022, 2017 by perlancar <perlancar@cpan.org>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Role-RequireFromBuild

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.