NAME
Dist::Zilla::Role::RequireFromBuild - Role to require() from build files
VERSION
This document describes version 0.001 of Dist::Zilla::Role::RequireFromBuild (from Perl distribution Dist-Zilla-Role-RequireFromBuild), released on 2017-01-08.
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
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:
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;
# write to temporary file, because the file object is not necessarily a
# Dist::Zilla::File::OnDisk object or it is already munged so the file
# no longer has the same content as the on-disk file.
require File::Temp;
my ($fh, $filename) = File::Temp::tempfile();
print $fh $files[0]->encoded_content;
close $fh;
do $filename;
METHODS
$obj->require_from_build($file)
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.
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.
SEE ALSO
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by 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.