| 1 | package Dist::Zilla::Plugin::TemplateModule 6.040; | ||||||||||
| 2 | # ABSTRACT: a simple module-from-template plugin | ||||||||||
| 3 | |||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | with 'Dist::Zilla::Role::ModuleMaker', | |||||||||
| 6 | 'Dist::Zilla::Role::TextTemplate'; | ||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Dist::Zilla::Pragmas; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | use Dist::Zilla::Path; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | use Sub::Exporter::ForMethods; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 2 | ▶ | use Data::Section 0.200002 # encoding and bytes | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 2 | { installer => Sub::Exporter::ForMethods::method_installer }, | |||||||||
| 19 | 2 | '-setup'; | |||||||||
| 20 | 2 | ▶ | use Dist::Zilla::File::InMemory; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | #pod =head1 MINTING CONFIGURATION | ||||||||||
| 23 | #pod | ||||||||||
| 24 | #pod This module is part of the standard configuration of the default L<Dist::Zilla> | ||||||||||
| 25 | #pod Minting Profile, and all profiles that don't set a custom ':DefaultModuleMaker' | ||||||||||
| 26 | #pod so you don't need to normally do anything to configure it. | ||||||||||
| 27 | #pod | ||||||||||
| 28 | #pod dzil new Some::Module | ||||||||||
| 29 | #pod # creates ./Some-Module/* | ||||||||||
| 30 | #pod # creates ./Some-Module/lib/Some/Module.pm | ||||||||||
| 31 | #pod | ||||||||||
| 32 | #pod However, for those who wish to configure this ( or any subclasses ) this is | ||||||||||
| 33 | #pod presently required: | ||||||||||
| 34 | #pod | ||||||||||
| 35 | #pod [TemplateModule / :DefaultModuleMaker] | ||||||||||
| 36 | #pod ; template = SomeFile.pm | ||||||||||
| 37 | #pod | ||||||||||
| 38 | #pod =head1 DESCRIPTION | ||||||||||
| 39 | #pod | ||||||||||
| 40 | #pod This is a L<ModuleMaker|Dist::Zilla::Role::ModuleMaker> used for creating new | ||||||||||
| 41 | #pod Perl modules files when minting a new dist with C<dzil new>. It uses | ||||||||||
| 42 | #pod L<Text::Template> (via L<Dist::Zilla::Role::TextTemplate>) to render a template | ||||||||||
| 43 | #pod into a Perl module. The template is given two variables for use in rendering: | ||||||||||
| 44 | #pod C<$name>, the module name; and C<$dist>, the Dist::Zilla object. The module is | ||||||||||
| 45 | #pod always created as a file under F<./lib>. | ||||||||||
| 46 | #pod | ||||||||||
| 47 | #pod By default, the template looks something like this: | ||||||||||
| 48 | #pod | ||||||||||
| 49 | #pod use strict; | ||||||||||
| 50 | #pod use warnings; | ||||||||||
| 51 | #pod package {{ $name }}; | ||||||||||
| 52 | #pod | ||||||||||
| 53 | #pod 1; | ||||||||||
| 54 | #pod | ||||||||||
| 55 | #pod =attr template | ||||||||||
| 56 | #pod | ||||||||||
| 57 | #pod The C<template> parameter may be given to the plugin to provide a different | ||||||||||
| 58 | #pod filename, absolute or relative to the build/profile directory. | ||||||||||
| 59 | #pod | ||||||||||
| 60 | #pod If this parameter is not specified, this module will use the boilerplate module | ||||||||||
| 61 | #pod template included in this module. | ||||||||||
| 62 | #pod | ||||||||||
| 63 | #pod =cut | ||||||||||
| 64 | |||||||||||
| 65 | 2 | has template => ( | |||||||||
| 66 | is => 'ro', | ||||||||||
| 67 | isa => 'Str', | ||||||||||
| 68 | predicate => 'has_template', | ||||||||||
| 69 | ); | ||||||||||
| 70 | |||||||||||
| 71 | 2 | ▶ | sub make_module { | ||||||||
|
Subroutine
make_module: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 72 | 2 | my ($self, $arg) = @_; | |||||||||
| 73 | |||||||||||
| 74 | 2 | my $template; | |||||||||
| 75 | |||||||||||
| 76 | 2 | ▶ | if ($self->has_template) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 0 | $template = path( $self->template )->slurp_utf8; | |||||||||
| 78 | } else { | ||||||||||
| 79 | 2 | $template = ${ $self->section_data('Module.pm') }; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | my $content = $self->fill_in_string( | ||||||||||
| 83 | $template, | ||||||||||
| 84 | { | ||||||||||
| 85 | dist => \($self->zilla), | ||||||||||
| 86 | name => $arg->{name}, | ||||||||||
| 87 | }, | ||||||||||
| 88 | 2 | ); | |||||||||
| 89 | |||||||||||
| 90 | 2 | my $filename = $arg->{name} =~ s{::}{/}gr; | |||||||||
| 91 | |||||||||||
| 92 | 2 | my $file = Dist::Zilla::File::InMemory->new({ | |||||||||
| 93 | name => "lib/$filename.pm", | ||||||||||
| 94 | content => $content, | ||||||||||
| 95 | }); | ||||||||||
| 96 | |||||||||||
| 97 | 2 | $self->add_file($file); | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 101 | 2 | 1; | |||||||||
| 102 | |||||||||||
| 103 | =pod | ||||||||||
| 104 | |||||||||||
| 105 | =encoding UTF-8 | ||||||||||
| 106 | |||||||||||
| 107 | =head1 NAME | ||||||||||
| 108 | |||||||||||
| 109 | Dist::Zilla::Plugin::TemplateModule - a simple module-from-template plugin | ||||||||||
| 110 | |||||||||||
| 111 | =head1 VERSION | ||||||||||
| 112 | |||||||||||
| 113 | version 6.040 | ||||||||||
| 114 | |||||||||||
| 115 | =head1 DESCRIPTION | ||||||||||
| 116 | |||||||||||
| 117 | This is a L<ModuleMaker|Dist::Zilla::Role::ModuleMaker> used for creating new | ||||||||||
| 118 | Perl modules files when minting a new dist with C<dzil new>. It uses | ||||||||||
| 119 | L<Text::Template> (via L<Dist::Zilla::Role::TextTemplate>) to render a template | ||||||||||
| 120 | into a Perl module. The template is given two variables for use in rendering: | ||||||||||
| 121 | C<$name>, the module name; and C<$dist>, the Dist::Zilla object. The module is | ||||||||||
| 122 | always created as a file under F<./lib>. | ||||||||||
| 123 | |||||||||||
| 124 | By default, the template looks something like this: | ||||||||||
| 125 | |||||||||||
| 126 | use strict; | ||||||||||
| 127 | use warnings; | ||||||||||
| 128 | package {{ $name }}; | ||||||||||
| 129 | |||||||||||
| 130 | 1; | ||||||||||
| 131 | |||||||||||
| 132 | =head1 PERL VERSION | ||||||||||
| 133 | |||||||||||
| 134 | This module should work on any version of perl still receiving updates from | ||||||||||
| 135 | the Perl 5 Porters. This means it should work on any version of perl | ||||||||||
| 136 | released in the last two to three years. (That is, if the most recently | ||||||||||
| 137 | released version is v5.40, then this module should work on both v5.40 and | ||||||||||
| 138 | v5.38.) | ||||||||||
| 139 | |||||||||||
| 140 | Although it may work on older versions of perl, no guarantee is made that the | ||||||||||
| 141 | minimum required version will not be increased. The version may be increased | ||||||||||
| 142 | for any reason, and there is no promise that patches will be accepted to | ||||||||||
| 143 | lower the minimum required perl. | ||||||||||
| 144 | |||||||||||
| 145 | =head1 ATTRIBUTES | ||||||||||
| 146 | |||||||||||
| 147 | =head2 template | ||||||||||
| 148 | |||||||||||
| 149 | The C<template> parameter may be given to the plugin to provide a different | ||||||||||
| 150 | filename, absolute or relative to the build/profile directory. | ||||||||||
| 151 | |||||||||||
| 152 | If this parameter is not specified, this module will use the boilerplate module | ||||||||||
| 153 | template included in this module. | ||||||||||
| 154 | |||||||||||
| 155 | =head1 MINTING CONFIGURATION | ||||||||||
| 156 | |||||||||||
| 157 | This module is part of the standard configuration of the default L<Dist::Zilla> | ||||||||||
| 158 | Minting Profile, and all profiles that don't set a custom ':DefaultModuleMaker' | ||||||||||
| 159 | so you don't need to normally do anything to configure it. | ||||||||||
| 160 | |||||||||||
| 161 | dzil new Some::Module | ||||||||||
| 162 | # creates ./Some-Module/* | ||||||||||
| 163 | # creates ./Some-Module/lib/Some/Module.pm | ||||||||||
| 164 | |||||||||||
| 165 | However, for those who wish to configure this ( or any subclasses ) this is | ||||||||||
| 166 | presently required: | ||||||||||
| 167 | |||||||||||
| 168 | [TemplateModule / :DefaultModuleMaker] | ||||||||||
| 169 | ; template = SomeFile.pm | ||||||||||
| 170 | |||||||||||
| 171 | =head1 AUTHOR | ||||||||||
| 172 | |||||||||||
| 173 | Ricardo SIGNES 😏 <cpan@semiotic.systems> | ||||||||||
| 174 | |||||||||||
| 175 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 176 | |||||||||||
| 177 | This software is copyright (c) 2026 by Ricardo SIGNES. | ||||||||||
| 178 | |||||||||||
| 179 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 180 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 181 | |||||||||||
| 182 | =cut | ||||||||||
| 183 | |||||||||||
| 184 | __DATA__ | ||||||||||