Giter Club home page Giter Club logo

dist-zilla-plugin-templatefiles's People

Contributors

perlpilot avatar

Stargazers

 avatar

Watchers

 avatar  avatar

dist-zilla-plugin-templatefiles's Issues

spelling error on POD documentation

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 bugtracker and repository links

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]

Better error messages

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;
 }

Please provide $plugin variable.

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:

  1. If $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.
  2. Reporting problems through plain 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.
  3. 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;
 }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.