Dist::...Custom(3pm)

πŸ“¦
version 6.000 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Dist::Zilla::Plugin::ModuleBuild::Custom πŸ’–

okay bestie, gather round, because this is Dist::...Custom(3pm) from the User Contributed Perl Documentation pile and it is lowkey iconic. It's the plugin that lets your dist bring its own Build.PL like the main character it is. ✨


🌸 VERSION 🌸

This doc describes version 4.26 of Dist::Zilla::Plugin::ModuleBuild::Custom, released December 17, 2017, living its truth as part of Dist-Zilla-Plugins-CJM version 6.000. πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

so in your dist.ini you'd say:

[ModuleBuild::Custom]
mb_version = 0.34  ; the default comes from the ModuleBuild plugin

and then in your Build.PL:

use Module::Build;

my %module_build_args = (
  module_name => 'Foo::Bar',
##{ $plugin->get_prereqs(1) ##}
##{ $plugin->get_default('share_dir') ##}
);

unless ( eval { Module::Build->VERSION(0.4004) } ) {
  my $tr = delete $module_build_args{test_requires};
  my $br = $module_build_args{build_requires};
  for my $mod ( keys %$tr ) {
    if ( exists $br->{$mod} ) {
      $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod};
    }
    else {
      $br->{$mod} = $tr->{$mod};
    }
  }
} # end unless Module::Build is 0.4004 or newer

my $builder = Module::Build->new(%module_build_args);
$builder->create_build_script;

now bestie, breathe β€” your Build.PL does not have to look exactly like this, fr fr. If you can require Module::Build 0.4004, you can straight up delete that unless eval section. If you're not using share_dir, that line can go too. πŸ’…

and like… if you're not adding your own code to Build.PL at all? You don't need this plugin. Periodt. πŸ™ˆ


πŸ‘‘ DESCRIPTION πŸ‘‘

This plugin is for the people who need something more complex than the auto-generated Makefile.PL or Build.PL that the MakeMaker or ModuleBuild plugins hand you. It's giving custom order, chef's choice. πŸ”₯

It's a subclass of the ModuleBuild plugin, but plot twist: it does not write a Build.PL for you. Instead, you write your own Build.PL, and it may do anything Module::Build is capable of β€” with one exception: it can't generate a compatibility Makefile.PL. 😭

This plugin will process Build.PL as a template (using Text::Template), which is how you get to sprinkle data from Dist::Zilla into the version you distribute, if that's your vibe. The template delimiters are ##{ and ##}, because that makes them look like comments β€” which means your Build.PL can work both before and after it gets processed as a template. Genius behavior honestly. 🧚

This is particularly useful for XS-based modules, because it lets you build and test the module without the overhead of running dzil build after every single tiny little change. No cap, that's a game changer. πŸ’œ

The template may use these variables:

  • $dist β€” the name of the distribution.
  • $meta β€” the hash of metadata (in META 1.4 format) that will be stored in META.yml.
  • $meta2 β€” the hash of metadata (in META 2 format) that will be stored in META.json.
  • $plugin β€” the ModuleBuild::Custom object that is processing the template.
  • $version β€” the distribution's version number.
  • $zilla β€” the Dist::Zilla object that is creating the distribution.

🌈 Using ModuleBuild::Custom with AutoPrereqs 🌈

If you're using the AutoPrereqs plugin, then you'll probably want to set its configure_finder to a FileFinder that includes Build.PL. You may also want to set this plugin's mb_version parameter to 0 and let AutoPrereqs grab the version straight from your use Module::Build line. Teamwork, bestie. 🫢

Example dist.ini configuration:

[ModuleBuild::Custom]
mb_version = 0 ; AutoPrereqs gets actual version from Build.PL

[FileFinder::ByName / :BuildPL]
file = Build.PL

[AutoPrereqs]
:version = 4.300005 ; need configure_finder
configure_finder = :BuildPL
; Add next line if your Build.PL uses modules you ship in inc/
configure_finder = :IncModules

then in your Build.PL you'd say:

use Module::Build 0.28; # or whatever version you need

πŸ› οΈ METHODS πŸ› οΈ

⭐ get_default

$plugin->get_default(qw(key1 key2 ...))

A template can call this method to pull the specified key(s) out of the default Module::Build arguments that the normal ModuleBuild plugin created, and get them formatted into a comma-separated list that's suitable for a hash constructor or a method's parameter list. Very giving, very formatted. ✨

If any key has no value (or its value is an empty hash or array ref), it gets omitted from the list. If all the keys are omitted, you get the empty string back. Otherwise, the result always ends with a comma. (Yes, always. It's committed to the bit. πŸ’…)

The most common usage would be

##{ $plugin->get_default('share_dir') ##}

⭐ get_meta

$plugin->get_meta(qw(key1 key2 ...))

A template can call this method to extract the specified key(s) from distmeta and have them formatted into a comma-separated list suitable for a hash constructor or a method's parameter list. The keys (and the returned values) are from the META 1.4 spec, because that's what Module::Build uses in its API. πŸŽ€

If any key has no value (or its value is an empty hash or array ref), it gets omitted from the list. If all keys are omitted, the empty string is returned. Otherwise, the result always ends with a comma.

⭐ get_prereqs

$plugin->get_prereqs($api_version)

This returns all the keys that describe the distribution's prerequisites. The $api_version tells the template what keys it can handle. The currently defined values are:

  • 0 (or undef) β€” this is equivalent to
$plugin->get_meta(qw(build_requires configure_requires requires
                     recommends conflicts))
  • 1 β€” this adds test_requires as a separate key (which requires Dist::Zilla 4.300032 or later). It's equivalent to
$plugin->get_default(qw(build_requires configure_requires requires
                        test_requires recommends conflicts))

Your Build.PL should either require Module::Build 0.4004, or fold test_requires into build_requires if an older version is in play (exactly like it's shown in the SYNOPSIS, bestie πŸ‘€).


πŸ” SEE ALSO πŸ”

The MakeMaker::Custom plugin does basically the same thing as this plugin, but for Makefile.PL β€” that's for you if you prefer ExtUtils::MakeMaker. Same energy, different file. πŸ’«


πŸ“¦ DEPENDENCIES πŸ“¦

ModuleBuild::Custom requires Dist::Zilla (6 or later) and Text::Template. I also recommend applying Template_strict.patch to Text::Template β€” that adds support for the STRICT option, which will help catch errors in your templates. Do it for yourself, bestie. 🫢


πŸ’€ INCOMPATIBILITIES πŸ’€

You must not use this in conjunction with the ModuleBuild plugin. Like, at all. They cannot both be at the party. 🚫


πŸ› BUGS AND LIMITATIONS πŸ›

No bugs have been reported. (iconic behavior, truly ✨)


πŸ‘‘ AUTHOR πŸ‘‘

Christopher J. Madsen "<perl AT cjmweb.net>"

Please report any bugs or feature requests to "<bug-Dist-Zilla-Plugins-CJM AT rt.cpan.org>" or through the web interface at <http://rt.cpan.org/Public/Bug/Report.html?Queue=Dist-Zilla-Plugins-CJM>.

You can follow or contribute to Dist-Zilla-Plugins-CJM's development at <https://github.com/madsen/dist-zilla-plugins-cjm>.


This software is copyright (c) 2017 by Christopher J. Madsen.

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


🌸 DISCLAIMER OF WARRANTY 🌸

okay bestie here comes the part where everyone scrolls to the bottom, but it matters, so read it:

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

and that's the whole page, bestie!! πŸ¦‹ this one's from perl v5.34.0, dated 2022-06-13, and it goes out as Dist::...Custom(3pm) β€” mwah, go build something cute. πŸ’…πŸ’–

πŸ“¦ where this page comes from