perlpilot / dist-zilla-plugin-templatefiles Goto Github PK
View Code? Open in Web Editor NEWUtilize files as templates for a distribution built with dzil
Utilize files as templates for a distribution built with dzil
follow patch
Index: libdist-zilla-plugin-templatefiles-perl/lib/Dist/Zilla/Plugin/TemplateFiles.pm
===================================================================
--- libdist-zilla-plugin-templatefiles-perl.orig/lib/Dist/Zilla/Plugin/TemplateFiles.pm 2016-09-19 15:04:54.190958668 -0300
+++ libdist-zilla-plugin-templatefiles-perl/lib/Dist/Zilla/Plugin/TemplateFiles.pm 2016-09-19 15:05:07.918787800 -0300
@@ -78,7 +78,7 @@
This software is copyright (c) 2010 by Jonathan Scott Duff
-This is free sofware; you can redistribute it and/or modify it under the
+This is free software; you can redistribute it and/or modify it under the
same terms as the Perl 5 programming language itself.
=head1 AUTHOR
META.yml provides incorrect links:
resources:
bugtracker: http://github.com/perlpilot/Dist-Zilla-Plugin-TemplateFile/issues
repository: git://github.com/perlpilot/Dist-Zilla-Plugin-TemplateFile.git
This information is used by metacpan to show "Clone repository" and "Issues" links at the left side of the project page. Currently (v0.01) these links are broken.
Patch:
--- dist.ini.ORIG 2015-06-23 13:46:00.000000000 +0300
+++ dist.ini 2015-06-23 13:50:23.956384948 +0300
@@ -5,9 +5,9 @@
copyright_year = 2010
[MetaResources]
- bugtracker.web = http://github.com/perlpilot/Dist-Zilla-Plugin-TemplateFile/issues
- repository.web = http://github.com/perlpilot/Dist-Zilla-Plugin-TemplateFile
- repository.url = git://github.com/perlpilot/Dist-Zilla-Plugin-TemplateFile.git
+ bugtracker.web = http://github.com/perlpilot/Dist-Zilla-Plugin-TemplateFiles/issues
+ repository.web = http://github.com/perlpilot/Dist-Zilla-Plugin-TemplateFiles
+ repository.url = git://github.com/perlpilot/Dist-Zilla-Plugin-TemplateFiles.git
repository.type = git
[ReadmeFromPod]
Hi, that's me again.
Let us see what happen if Perl code in a template not compiles or dies:
{{ die "oops"; }}
$ dzil build
[DZ] beginning to build Assa
oops at template line 2.
Error message is not good because it is not clear what is the source of the error. It looks like sometime wrong with templates, but it is not clear in which file. If proposed patch is applied, error message will looks like:
[TemplateFiles] Error in template starting at lib/Assa.pm line 2:
[TemplateFiles] oops at lib/Assa.pm line 2.
You see "at lib/Assa.pm line 2" is printed twice. It looks redundant, but it is not. The first line shows location of the template, the second line shows location of die. Imagine that template calls a function which dies inside. In such a case error message will be:
[TemplateFiles] Error in template starting at lib/Assa.pm line 2:
[TemplateFiles] oops at Tool.pm line 4.
The patch:
--- TemplateFiles.pm.ORIG 2015-07-10 00:23:39.000000000 +0300
+++ TemplateFiles.pm 2015-07-10 01:01:10.566167791 +0300
@@ -28,7 +28,22 @@
}
}
return unless $files{$file->name};
- my $content = $self->fill_in_string( $file->content, { plugin => \$self, dist => \($self->zilla) } );
+ my $content = $self->fill_in_string(
+ $file->content,
+ { plugin => \$self, dist => \($self->zilla) },
+ {
+ BROKEN => sub {
+ my %args = @_;
+ chomp( $args{ error } );
+ # If error occurs in template, replace "template" with the file name.
+ $args{ error } =~ s{( at )template( line \d+\.)\n?\z}{$1 . $file->name . $2 }e;
+ $self->log_fatal( [
+ "Error in template starting at %s line %d:\n%s",
+ $file->name, $args{ lineno }, $args{ error }
+ ] );
+ },
+ },
+ );
$file->content( $content ) if defined $content;
}
TemplateFiles
is not the only plugin which treats files as templates. There are two plugins, GatherDir::Template
and GenerateFile
, which are bundled into Dist-Zilla
itself. These two plugins provide variables $dist
and $plugin
for template Perl code.
TemplateFiles
provides $dist
variable, but not $plugin
. I think providing $plugin
is a good idea:
$plugin
is set, Dist-Zilla object can be easily reached through $plugin
: $pligin->zilla
. However, if $dist
is set, finding plugin is not so trivial. $dist->plugin_named( "name" )
works, but you have to know plugin name.warn
and die
gives the user error message, but it is not clear what caused it. Reporting problems via $plugin->log
and $plugin->log_fatal
gives a bit better results, because messages are prefixed by plugin name.TemplateFiles
will be aligned with GatherDir::Template
and GenerateFile
.Patch is trivial:
--- TemplateFiles.pm.ORIG 2015-06-23 13:46:00.000000000 +0300
+++ TemplateFiles.pm 2015-06-23 13:48:25.767114532 +0300
@@ -28,7 +28,7 @@
}
}
return unless $files{$file->name};
- my $content = $self->fill_in_string( $file->content, { dist => \($self->zilla) } );
+ my $content = $self->fill_in_string( $file->content, { plugin => $self, dist => \($self->zilla) } );
$file->content( $content ) if defined $content;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.