Skip to content

Commit 9d4be69

Browse files
committed
Merge remote-tracking branch 'origin/main' into cookie-semicolon
2 parents 0ac72f4 + 9b5ed02 commit 9d4be69

File tree

7 files changed

+137
-17
lines changed

7 files changed

+137
-17
lines changed

Changes

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
{{$NEXT}}
22

3+
[ BUG FIXES ]
4+
* None
5+
6+
[ ENHANCEMENTS ]
7+
* GH #1723: Enable use of a different Template Toolkit base class
8+
(Andy Beverley)
9+
* PR #1727: Don't create CPAN package files when generating new apps
10+
(Jason A. Crome)
11+
12+
[ DOCUMENTATION ]
13+
* GH #1342: Document skipping private methods in pod coverage tests
14+
(Jason A. Crome)
15+
16+
[ DEPRECATED ]
17+
* None
18+
19+
[ MISC ]
20+
* None
21+
322
1.1.2 2024-11-25 08:34:51-05:00 America/New_York
423

524
[ BUG FIXES ]

lib/Dancer2/CLI/Gen.pm

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ option skel => (
7474
format_doc => 'directory',
7575
required => 0,
7676
default => sub{
77-
my $self = shift;
78-
path( $self->parent_command->_dist_dir, 'skel' );
77+
my $self = shift;
78+
path( $self->parent_command->_dist_dir, 'skel' );
7979
},
8080
);
8181

@@ -95,7 +95,7 @@ option git => (
9595
default => 0,
9696
);
9797

98-
option remote => (
98+
option remote => (
9999
is => 'ro',
100100
short => 'r',
101101
doc => 'URI for git repository (implies -g)',
@@ -104,12 +104,19 @@ option remote => (
104104
required => 0,
105105
);
106106

107+
option no_package_files => (
108+
is => 'ro',
109+
doc => "don't create files needed for CPAN packaging",
110+
required => 0,
111+
default => 0,
112+
);
113+
107114
# Last chance to validate args before we attempt to do something with them
108115
sub BUILD {
109116
my ( $self, $args ) = @_;
110117

111-
$self->osprey_usage( 1, qq{
112-
Invalid application name. Application names must not contain single colons,
118+
$self->osprey_usage( 1, qq{
119+
Invalid application name. Application names must not contain single colons,
113120
dots, hyphens or start with a number.
114121
}) unless is_module_name( $self->application );
115122

@@ -165,8 +172,10 @@ sub run {
165172
};
166173

167174
$self->_copy_templates( $files_to_copy, $vars, $self->overwrite );
168-
$self->_create_manifest( $files_to_copy, $app_path );
169-
$self->_add_to_manifest_skip( $app_path);
175+
unless( $self->no_package_files ) {
176+
$self->_create_manifest( $files_to_copy, $app_path );
177+
$self->_add_to_manifest_skip( $app_path );
178+
}
170179

171180
$self->_check_git( $vars );
172181
$self->_check_yaml;
@@ -183,7 +192,7 @@ sub _check_git {
183192
184193
WARNING: Couldn't initialize a git repo despite being asked to do so.
185194
186-
To resolve this, cd to your application directory and run the following
195+
To resolve this, cd to your application directory and run the following
187196
commands:
188197
189198
git init
@@ -200,13 +209,13 @@ commands:
200209
path( $gitignore )->copy( $app_path );
201210

202211
chdir File::Spec->rel2abs( $app_path ) or die "Can't cd to $app_path: $!";
203-
if( _run_shell_cmd( 'git', 'init') != 0 or
204-
_run_shell_cmd( 'git', 'add', '.') != 0 or
212+
if( _run_shell_cmd( 'git', 'init') != 0 or
213+
_run_shell_cmd( 'git', 'add', '.') != 0 or
205214
_run_shell_cmd( 'git', 'commit', "-m 'Initial commit of $app_name by Dancer2'" ) != 0 ) {
206215
print $git_error;
207216
}
208217
else {
209-
if( $self->remote &&
218+
if( $self->remote &&
210219
_run_shell_cmd( 'git', 'remote', 'add', 'origin', $self->remote ) != 0 ) {
211220
print $git_error;
212221
print " git remote add origin " . $self->remote . "\n";
@@ -290,7 +299,7 @@ sub _build_file_list {
290299
warn "File not found: $file" unless $file->exists; # Paranoia
291300
next if $file->basename =~ m{^\.git(/|$)};
292301
next if $file->is_dir;
293-
302+
294303
my $filename = $file->relative( $from );
295304
push @result, [ $file, path( $to, $filename )];
296305
}
@@ -302,6 +311,9 @@ sub _copy_templates {
302311

303312
foreach my $pair (@$files) {
304313
my ( $from, $to ) = @{$pair};
314+
next if $self->no_package_files && $from =~ /MANIFEST\.SKIP$/;
315+
next if $self->no_package_files && $from =~ /Makefile.PL$/;
316+
305317
if ( -f $to && !$overwrite ) {
306318
print "! $to exists, overwrite? (or rerun this command with -o) [N/y/a]: ";
307319
my $res = <STDIN>; chomp($res);
@@ -315,7 +327,7 @@ sub _copy_templates {
315327
$to_dir->mkpath;
316328
}
317329

318-
# Skeleton files whose names are prefixed with + need to be executable, but we must strip
330+
# Skeleton files whose names are prefixed with + need to be executable, but we must strip
319331
# that from the name when copying them
320332
my $to_file = path( $to )->basename;
321333
my $ex = ( $to_file =~ s/^\+// );
@@ -378,7 +390,7 @@ sub _process_template {
378390
return $engine->render( \$template, $tokens );
379391
}
380392

381-
# These are good candidates to move to Dancer2::CLI if other commands
393+
# These are good candidates to move to Dancer2::CLI if other commands
382394
# need them later.
383395
sub _get_app_path {
384396
my ( $self, $path, $appname ) = @_;
@@ -431,8 +443,8 @@ sub _run_shell_cmd {
431443

432444
my $exit_status = try {
433445
my $pid = IPC::Open3::open3(
434-
my $stdin,
435-
my $stdout,
446+
my $stdin,
447+
my $stdout,
436448
my $stderr = Symbol::gensym,
437449
@cmds,
438450
);

lib/Dancer2/Plugin.pm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,4 +1083,21 @@ to call C<plugin_keywords> after the attribute definition.
10831083
10841084
plugin_keywords 'bar';
10851085
1086+
=head3 Coverage for Dancer2::Plugin::<Name> is 0.0%, with 15 naked subroutines
1087+
1088+
To avoid errors caused by missing pod for private plugin methods, write your
1089+
pod coverage test like so:
1090+
1091+
pod_coverage_ok(
1092+
"Dancer2::Plugin::MyAwesomePlugin", {
1093+
also_private => [
1094+
qw/
1095+
BUILDARGS BUILD ClassHooks PluginKeyword dancer_app
1096+
execute_plugin_hook hook keywords on_plugin_import plugin_args
1097+
plugin_setting realms realm realm_providers register register_hook
1098+
register_plugin request var
1099+
/
1100+
]
1101+
});
1102+
10861103
=cut

lib/Dancer2/Template/TemplateToolkit.pm

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use Dancer2::FileUtils qw<path>;
99
use Scalar::Util ();
1010
use Template;
1111

12+
# Override to use a different Template::Toolkit base class
13+
has 'template_class' => ( is => 'ro', default => 'Template' );
14+
1215
with 'Dancer2::Core::Role::Template';
1316

1417
has '+engine' => ( isa => InstanceOf ['Template'], );
@@ -37,7 +40,7 @@ sub _build_engine {
3740
sub { [ $ttt->views ] },
3841
];
3942

40-
my $tt = Template->new(%tt_config);
43+
my $tt = $self->template_class->new(%tt_config);
4144
$Template::Stash::PRIVATE = undef if $self->config->{show_private_variables};
4245
return $tt;
4346
}
@@ -190,6 +193,22 @@ PARSER (L<Template::Parser>) and GRAMMAR (L<Template::Grammar>). If you intend t
190193
several of these components in your app, it is suggested to create an app-specific subclass
191194
that handles all of them at the same time.
192195
196+
=head2 Custom Template::Toolkit class
197+
198+
When subclassing this module it is possible to use a different
199+
Template::Toolkit class (for example if you have also subclassed that). To do
200+
that simply define a different C<template_class> property:
201+
202+
package Dancer2::Template::TemplateToolkit::FooBar;
203+
204+
use Moo;
205+
206+
extends 'Dancer2::Template::TemplateToolkit';
207+
208+
has '+template_class' => ( default => 'TemplateFooBar' );
209+
210+
1;
211+
193212
=head2 Template Caching
194213
195214
L<Template>::Tookit templates can be cached by adding the C<COMPILE_EXT> property to your
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package Dancer2::Template::TemplateToolkitFoo;
2+
3+
# Custom Template::Toolkit template engine that uses a custom Template class
4+
5+
use strict;
6+
use warnings;
7+
8+
use Moo;
9+
use TemplateFoo;
10+
11+
extends 'Dancer2::Template::TemplateToolkit';
12+
13+
has '+template_class' => ( default => 'TemplateFoo' );
14+
15+
1;

t/lib/TemplateFoo.pm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package TemplateFoo;
2+
3+
# Custom Template::Toolkit class
4+
5+
use base 'Template';
6+
7+
sub process
8+
{ my ($self, $template, $vars, $outstream, @opts) = @_;
9+
$$outstream = "Custom Render Template";
10+
1;
11+
}
12+
13+
1;

t/template.t

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ use HTTP::Request::Common;
88
use File::Spec;
99
use File::Basename 'dirname';
1010

11+
use lib 't/lib';
12+
1113
eval { require Template; Template->import(); 1 }
1214
or plan skip_all => 'Template::Toolkit probably missing.';
1315

1416
use_ok('Dancer2::Template::TemplateToolkit');
17+
use_ok('Dancer2::Template::TemplateToolkitFoo');
1518

1619
my $views =
1720
File::Spec->rel2abs( File::Spec->catfile( dirname(__FILE__), 'views' ) );
@@ -109,6 +112,28 @@ content added in after_layout_render";
109112
is $res->content, $result, '[GET /global] Correct content with template hooks';
110113
};
111114

115+
# Test that a custom class can be used for Template::Toolkit
116+
my $tt_custom = Dancer2::Template::TemplateToolkitFoo->new;
117+
118+
isa_ok $tt_custom, 'Dancer2::Template::TemplateToolkit';
119+
isa_ok $tt_custom, 'Dancer2::Template::TemplateToolkitFoo';
120+
121+
{
122+
package CustomFoo;
123+
use Dancer2;
124+
125+
Dancer2->runner->apps->[1]->set_template_engine($tt_custom);
126+
127+
get '/' => sub { template 'index' };
128+
}
129+
130+
subtest 'custom template render' => sub {
131+
132+
my $test = Plack::Test->create( CustomFoo->to_app );
133+
my $res = $test->request( GET '/' );
134+
is $res->content, 'Custom Render Template', 'Custom Render Template';
135+
};
136+
112137
{
113138

114139
package Foo;

0 commit comments

Comments
 (0)