blib/lib/Dancer2/CLI/Gen.pm

filter: Statementstmt 85.9% 171 / 199 Branchbran 53.7% 43 / 80 Conditioncond 26.6% 8 / 30 MC/DCmcdc 5.2% 1 / 19 Subroutinesub 89.2% 25 / 28 Podpod 0.0% 0 / 2 totaltotal 69.2% 248 / 358 CC 54 SCAR 25.8
CC
54
Cov
72%
_version_check
30.0
_copy_templates
28.7
BUILD
18.0
CRAP 13.2
↑ Summary blib/lib/Dancer2/Handler/AutoPage.pm »
1 package Dancer2::CLI::Gen;
2 # ABSTRACT: Create new Dancer2 application
3 6 $Dancer2::CLI::Gen::VERSION = '2.2.1';
4 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Dancer2::Template::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Module::Runtime qw( use_module is_module_name );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 use CLI::Osprey
12 6 ▶ desc => 'Helper script to create new Dancer2 applications';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # For git integration
15 6 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use IPC::Open3 qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶use File::Which;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 6 option application => (
21 is => 'ro',
22 short => 'a',
23 doc => 'application name',
24 format => 's',
25 format_doc => 'appname',
26 required => 1,
27 spacer_before => 1,
28 );
29  
30 6 option directory => (
31 is => 'ro',
32 short => 'd',
33 doc => 'application directory (default: dashed application name)',
34 format => 's',
35 format_doc => 'directory',
36 required => 0,
37 );
38  
39 # This was causing conflict with Path::Tiny's path(), so renaming to avoid
40 # the overhead of making Path::Tiny an object.
41 6 option app_path => (
42 is => 'ro',
43 short => 'p',
44 option => 'path',
45 doc => 'application path (default: current directory)',
46 format => 's',
47 format_doc => 'directory',
48 required => 0,
49 default => '.',
50 );
51  
52 6 option overwrite => (
53 is => 'ro',
54 short => 'o',
55 doc => 'overwrite existing files',
56 required => 0,
57 default => 0,
58 );
59  
60 6 option no_check => (
61 is => 'ro',
62 short => 'x',
63 doc => "don't check latest Dancer2 version (default: check - requires internet)",
64 required => 0,
65 default => 0,
66 );
67  
68 option skel => (
69 is => 'ro',
70 short => 's',
71 doc => 'skeleton directory',
72 format => 's',
73 format_doc => 'directory',
74 required => 0,
75 default => sub{
76 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 0 path( $self->parent_command->_dist_dir, 'skel' );
78 },
79 6 );
80  
81 6 option skel_name => (
82 is => 'ro',
83 short => 'n',
84 doc => 'skeleton name',
85 format => 's',
86 format_doc => 'skelname',
87 required => 0,
88 default => 'default',
89 );
90  
91 6 option docker => (
92 is => 'ro',
93 short => 'c',
94 doc => 'create a dockerfile (container definition)',
95 required => 0,
96 default => 0,
97 );
98  
99 6 option git => (
100 is => 'ro',
101 short => 'g',
102 doc => 'init git repository',
103 required => 0,
104 default => 0,
105 );
106  
107 6 option remote => (
108 is => 'ro',
109 short => 'r',
110 doc => 'URI for git repository (implies -g)',
111 format => 's',
112 format_doc => 'URI',
113 required => 0,
114 );
115  
116 6 option no_package_files => (
117 is => 'ro',
118 doc => "don't create files needed for CPAN packaging",
119 required => 0,
120 default => 0,
121 );
122  
123 has _engine => (
124 is => 'ro',
125 default => sub {
126 4 ▶ return Dancer2::Template::Tiny->new( config => { start_tag => '[d2%', end_tag => '%2d]' } );
Subroutine __ANON__: called CC=1 SCAR=0.0
127 },
128 6 );
129  
130 # Last chance to validate args before we attempt to do something with them
131 sub BUILD {
132 4 ▶ my ( $self, $args ) = @_;
Subroutine BUILD: called CC=9 SCAR=28.9
Pod undocumented
133  
134 4 ▶ $self->osprey_usage( 1, qq{
Branch: 1 branch
BranchTrueFalseTotal
unless &is_module_name(scalar $self->application) 0 4 4
135 Invalid application name. Application names must not contain single colons,
136 dots, hyphens or start with a number.
137 }) unless is_module_name( $self->application );
138  
139 4 ▶ if ( my $remote = $self->remote ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $remote = $self->remote) 0 4 4
140 0 ▶ my $scheme = URI->new( $remote )->scheme // $self->remote; # This feels dirty
Condition0%0/3
"URI"->new($remote)->scheme // $self->remote
l!l&&r!l&&!r
000
MC/DC0%0/2
"URI"->new($remote)->scheme // $self->remote
"URI"->new($remote)->scheme $self->remote
Truth table0%0/3
A // B
A= "URI"->new($remote)->schemeB= $self->remote
ABresult
1X1
011
000
141 0 ▶ $self->osprey_usage( 1, "'$remote' must be a valid URI to git repository")
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme =~ / ^ git \@ .+ : .+ \.git $ | ^ http /x 0 0 0
142 unless $scheme =~ / ^ git \@ .+ : .+ \.git $ | ^ http /x;
143 }
144  
145 4 my $path = $self->app_path;
146 4 ▶ -d $path or $self->osprey_usage( 1, "path: directory '$path' does not exist" );
Branch: 1 branch
BranchTrueFalseTotal
-d $path or $self->osprey_usage(1, "path: directory '${path}' does not exist") 0 4 4
147 4 ▶ -w $path or $self->osprey_usage( 1, "path: directory '$path' is not writeable" );
Branch: 1 branch
BranchTrueFalseTotal
-w $path or $self->osprey_usage(1, "path: directory '${path}' is not writeable") 0 4 4
148  
149 4 ▶ if ( my $skel = $self->skel ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $skel = $self->skel) 4 0 4
150 4 ▶ -d $skel or $self->osprey_usage( 1, "skel: directory '$skel' not found" );
Branch: 1 branch
BranchTrueFalseTotal
-d $skel or $self->osprey_usage(1, "skel: directory '${skel}' not found") 0 4 4
151 }
152 }
153  
154 sub run {
155 4 ▶ my $self = shift;
Subroutine run: called CC=7 SCAR=19.6
Pod undocumented
156 4 ▶ $self->_version_check unless $self->no_check;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->no_check 0 4 4
157  
158 4 my $app_name = $self->application;
159 4 my $app_file = $self->parent_command->_get_app_file( $app_name );
160 4 my $app_path = $self->parent_command->_get_app_path( $self->app_path, $app_name );
161  
162 4 ▶ if( my $dir = $self->directory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dir = $self->directory) 3 1 4
163 3 $app_path = path( $self->app_path, $dir );
164 }
165  
166 4 my $files_to_copy = $self->_build_file_list( $self->skel . '/' . $self->skel_name, $app_path );
167 4 foreach my $pair( @$files_to_copy ) {
168 36 ▶ if( $pair->[0] =~ m/lib\/AppFile.pm$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pair->[0] =~ m[lib/AppFile.pm$]) 4 32 36
169 4 $pair->[1] = path( $app_path, $app_file );
170 4 last;
171 }
172 }
173  
174 4 ▶ if( $self->docker ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->docker) 0 4 4
175 0 push @$files_to_copy, [ path( $self->parent_command->_dist_dir, 'docker/Dockerfile' ), "$app_name/Dockerfile" ];
176 }
177  
178 4 my $vars = {
179 appname => $app_name,
180 appfile => $app_file->stringify,
181 apppath => $app_path->stringify,
182 appdir => $app_path->absolute->stringify,
183 perl_interpreter => $self->parent_command->_get_perl_interpreter,
184 cleanfiles => $self->parent_command->_get_dashed_name( $app_name ),
185 dancer_version => $self->parent_command->_dancer2_version,
186 docker => $self->docker,
187 };
188  
189 4 $self->_copy_templates( $files_to_copy, $vars, $self->overwrite );
190 4 ▶ unless( $self->no_package_files ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->no_package_files) 4 0 4
191 4 $self->_create_manifest( $files_to_copy, $app_path );
192 4 $self->_add_to_manifest_skip( $app_path, $vars->{cleanfiles} );
193 }
194  
195 4 $self->_check_git( $vars );
196 4 $self->_check_yaml;
197 4 $self->_how_to_run( $vars );
198 }
199  
200 sub _check_git {
201 4 ▶ my( $self, $vars ) = @_;
Subroutine _check_git: called CC=10 SCAR=27.1
202  
203 4 ▶ if( my $remote = $self->remote or $self->git ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $remote = $self->remote or $self->git) 1 3 4
Condition66%2/3
my $remote = $self->remote or $self->git
l!l&&r!l&&!r
013
MC/DC50%1/2
my $remote = $self->remote or $self->git
my $remote = $self->remote $self->git
Truth table66%2/3
A or B
A= my $remote = $self->remoteB= $self->git
ABresult
1X1
011
000
204 1 my $app_name = $vars->{ appname };
205 1 my $git_error = qq{
206 *****
207  
208 WARNING: Couldn't initialize a git repo despite being asked to do so.
209  
210 To resolve this, cd to your application directory and run the following
211 commands:
212  
213 git init
214 git add .
215 git commit -m"Initial commit of $app_name by Dancer2"
216 };
217  
218 1 my $git = which 'git';
219 1 ▶ -x $git or die "Can't execute git: $!";
Branch: 1 branch
BranchTrueFalseTotal
-x $git or die "Can't execute git: $!" 0 1 1
220  
221 #my $dist_dir = $self->parent_command->_dist_dir;
222 1 my $app_path = $vars->{ apppath };
223  
224 # The shipped template lives at share/gitignore, not share/.gitignore --
225 # a leading dot there would make git itself honour it against this
226 # distribution's own share/ tree, which kept the skeleton's environment
227 # configs out of the shipped dist entirely. The generated application
228 # still needs a file literally named .gitignore, so the destination
229 # name is given explicitly rather than left to whatever copy() does
230 # with a directory target.
231 1 my $gitignore = path( $self->parent_command->_dist_dir, 'gitignore' );
232 1 path( $gitignore )->copy( path( $app_path, '.gitignore' ) );
233  
234 # $vars->{apppath} is a plain string (see the die message below, which
235 # wants it as one); the absolute path was already computed once into
236 # $vars->{appdir} at the point of $app_path->absolute->stringify in
237 # run(), so re-derive it from there instead of calling ->absolute on
238 # a string -- which is what used to make 'dancer2 gen -g' die with
239 # "Can't locate object method \"absolute\" via package ...".
240 chdir $vars->{ appdir }
241 1 ▶ or die "Can't cd to $app_path: $!";
Branch: 1 branch
BranchTrueFalseTotal
chdir $vars->{"appdir"} or die "Can't cd to ${app_path}: $!" 0 1 1
242 1 ▶ if( _run_shell_cmd( 'git', 'init') != 0 or
Branch: 1 branch
BranchTrueFalseTotal
if (_run_shell_cmd('git', 'init') != 0 or _run_shell_cmd('git', 'add', '.') != 0 or _run_shell_cmd('git', 'commit', "-m 'Initial commit of $app_name by Dancer2'") != 0) { } 0 1 1
Condition33%2/6
_run_shell_cmd("git", "init") != 0 or _run_shell_cmd("git", "add", ".") != 0 or _run_shell_cmd("git", "commit", "-m 'Initial commit of $app_name by Dancer2'") != 0
l!l&&r!l&&!r
001
_run_shell_cmd("git", "init") != 0 or _run_shell_cmd("git", "add", ".") != 0
l!l&&r!l&&!r
001
MC/DC0%0/3
_run_shell_cmd("git", "init") != 0 or _run_shell_cmd("git", "add", ".") != 0 or _run_shell_cmd("git", "commit", "-m 'Initial commit of $app_name by Dancer2'") != 0
_run_shell_cmd("git", "init") != 0 _run_shell_cmd("git", "add", ".") != 0 _run_shell_cmd("git", "commit", "-m 'Initial commit of $app_name by Dancer2'") != 0
Truth table25%1/4
A or B or C
A= _run_shell_cmd("git", "init") != 0B= _run_shell_cmd("git", "add", ".") != 0C= _run_shell_cmd("git", "commit", "-m 'Initial commit of $app_name by Dancer2'") != 0
ABCresult
1XX1
01X1
0011
0000
243 _run_shell_cmd( 'git', 'add', '.') != 0 or
244 _run_shell_cmd( 'git', 'commit', "-m 'Initial commit of $app_name by Dancer2'" ) != 0 ) {
245 0 print $git_error;
246 }
247 else {
248 1 ▶ if( $self->remote &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->remote and _run_shell_cmd("git", "remote", "add", "origin", $self->remote) != 0) 0 1 1
Condition33%1/3
$self->remote and _run_shell_cmd("git", "remote", "add", "origin", $self->remote) != 0
!ll&&!rl&&r
100
MC/DC0%0/2
$self->remote and _run_shell_cmd("git", "remote", "add", "origin", $self->remote) != 0
$self->remote _run_shell_cmd("git", "remote", "add", "origin", $self->remote) != 0
Truth table33%1/3
A and B
A= $self->remoteB= _run_shell_cmd("git", "remote", "add", "origin", $self->remote) != 0
ABresult
0X0
100
111
249 _run_shell_cmd( 'git', 'remote', 'add', 'origin', $self->remote ) != 0 ) {
250 0 print $git_error;
251 0 print " git remote add origin " . $self->remote . "\n";
252 }
253 }
254 1 print "\n*****\n";
255 }
256 }
257  
258 sub _check_yaml {
259 4 ▶ if ( ! eval { use_module( 'YAML' ); 1; } ) {
Subroutine _check_yaml: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
if (not eval { do { &use_module("YAML"); 1 } }) 0 4 4
260 0 print qq{
261 *****
262  
263 WARNING: YAML.pm is not installed. This is not a full dependency, but is highly
264 recommended; in particular, the scaffolded Dancer app being created will not be
265 able to read settings from the config file without YAML.pm being installed.
266  
267 To resolve this, simply install YAML from CPAN, for instance using one of the
268 following commands:
269  
270 cpan YAML
271 perl -MCPAN -e 'install YAML'
272 curl -L https://cpanmin.us | perl - --sudo YAML
273  
274 *****
275 };
276 }
277 }
278  
279 sub _how_to_run {
280 4 ▶ my( $self, $vars ) = @_;
Subroutine _how_to_run: called CC=3 SCAR=11.7
281  
282 4 my $app_path = $vars->{ apppath };
283 4 my $app_name = $vars->{ appname };
284  
285 4 print "\nYour new application is ready! To run it:\n";
286  
287 4 ▶ if( $vars->{ docker } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{"docker"}) 0 4 4
288 0 my $image = lc $app_name;
289 0 print qq{
290  
291 cd $app_path
292 docker build -t ${image} .
293 docker run -d -p 5000:4000 --name $app_name ${image}
294  
295 where 5000 is the external port, and 4000 is the port your application
296 runs on inside of the container.
297  
298 (note: you may need to run the docker commands with sudo)
299  
300 You may also run your app without Docker:
301 };
302 }
303  
304 4 my $install_deps = '';
305 4 ▶ $install_deps = "\n cpanm --installdeps ."
Branch: 1 branch
BranchTrueFalseTotal
if $self->skel_name ne "default" 0 4 4
306 if $self->skel_name ne 'default';
307  
308 4 print qq{
309 cd $app_path$install_deps
310 plackup bin/app.psgi
311  
312 To access your application, point your browser to http://localhost:5000/
313  
314 If you need community assistance, the following resources are available:
315 - Dancer website: https://perldancer.org
316 - GitHub: https://github.com/PerlDancer/Dancer2/
317 - Mailing list: https://lists.perldancer.org/mailman/listinfo/dancer-users
318 - IRC: irc.perl.org#dancer
319  
320 Happy Dancing!
321  
322 };
323 }
324  
325 # skel creation routines
326 sub _build_file_list {
327 4 ▶ my ( $self, $from, $to ) = @_;
Subroutine _build_file_list: called CC=5 SCAR=16.2
328 4 $from =~ s{/+$}{};
329  
330 4 my @result;
331 4 my $iter = path( $from )->iterator({ recurse => 1 });
332 4 ▶ while( my $file = $iter->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = &$iter()) 124 4 128
333 124 ▶ warn "File not found: $file" unless $file->exists; # Paranoia
Branch: 1 branch
BranchTrueFalseTotal
unless $file->exists 0 124 124
334 124 ▶ next if $file->basename =~ m{^\.git(/|$)};
Branch: 1 branch
BranchTrueFalseTotal
if $file->basename =~ m[^\.git(/|$)] 0 124 124
335 124 ▶ next if $file->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
if $file->is_dir 36 88 124
336  
337 88 my $filename = $file->relative( $from );
338 88 push @result, [ $file, path( $to, $filename )];
339 }
340 4 return \@result;
341 }
342  
343 sub _copy_templates {
344 4 ▶ my ( $self, $files, $vars, $overwrite ) = @_;
Subroutine _copy_templates: called CC=17 SCAR=33.6
345 4 my $app_name = $vars->{ appname };
346  
347 4 foreach my $pair (@$files) {
348 88 my ( $from, $to ) = @{$pair};
349 88 ▶ next if $self->no_package_files && $from =~ /MANIFEST\.SKIP$/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->no_package_files and $from =~ /MANIFEST\.SKIP$/ 0 88 88
Condition33%1/3
$self->no_package_files and $from =~ /MANIFEST\.SKIP$/
!ll&&!rl&&r
8800
MC/DC0%0/2
$self->no_package_files and $from =~ /MANIFEST\.SKIP$/
$self->no_package_files $from =~ /MANIFEST\.SKIP$/
Truth table33%1/3
A and B
A= $self->no_package_filesB= $from =~ /MANIFEST\.SKIP$/
ABresult
0X0
100
111
350 88 ▶ next if $self->no_package_files && $from =~ /Makefile.PL$/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->no_package_files and $from =~ /Makefile.PL$/ 0 88 88
Condition33%1/3
$self->no_package_files and $from =~ /Makefile.PL$/
!ll&&!rl&&r
8800
MC/DC0%0/2
$self->no_package_files and $from =~ /Makefile.PL$/
$self->no_package_files $from =~ /Makefile.PL$/
Truth table33%1/3
A and B
A= $self->no_package_filesB= $from =~ /Makefile.PL$/
ABresult
0X0
100
111
351  
352 88 ▶ if ( -f $to && !$overwrite ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $to and not $overwrite) 0 88 88
Condition33%1/3
-f $to and not $overwrite
!ll&&!rl&&r
8800
MC/DC0%0/2
-f $to and not $overwrite
-f $to not $overwrite
Truth table33%1/3
A and not(B)
A= -f $toB= not $overwrite
ABresult
0X0
100
111
353 0 print "! $to exists, overwrite? (or rerun this command with -o) [N/y/a]: ";
354 0 my $res = <STDIN>; chomp($res);
355 0 ▶ $overwrite = 1 if $res eq 'a';
Branch: 1 branch
BranchTrueFalseTotal
if $res eq "a" 0 0 0
356 0 ▶ next unless ( $res eq 'y' ) or ( $res eq 'a' );
Branch: 1 branch
BranchTrueFalseTotal
unless $res eq "y" or $res eq "a" 0 0 0
Condition0%0/3
$res eq "y" or $res eq "a"
l!l&&r!l&&!r
000
MC/DC0%0/2
$res eq "y" or $res eq "a"
$res eq "y" $res eq "a"
Truth table0%0/3
A or B
A= $res eq "y"B= $res eq "a"
ABresult
1X1
011
000
357 }
358  
359 88 $to =~ s/AppFile/$app_name/;
360 88 my $to_dir = path( $to )->parent;
361 88 ▶ if ( ! $to_dir->is_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($to_dir->is_dir) 40 48 88
362 40 print "+ $to_dir\n";
363 40 $to_dir->mkpath;
364 }
365  
366 # Skeleton files whose names are prefixed with + need to be executable, but we must strip
367 # that from the name when copying them
368 88 my $to_file = path( $to )->basename;
369 88 my $ex = ( $to_file =~ s/^\+// );
370 88 ▶ $to = path( $to_dir, $to_file ) if $ex;
Branch: 1 branch
BranchTrueFalseTotal
if $ex 12 76 88
371  
372 88 print "+ $to\n";
373 88 my $content;
374 {
375 88 local $/;
376 88 ▶ open( my $fh, '<:raw', $from ) or die "unable to open file `$from' for reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $from or die "unable to open file `${from}' for reading: $!" 0 88 88
377 88 $content = <$fh>;
378 88 close $fh;
379 }
380  
381 88 ▶ if( $from !~ m/\.(db|ico|jpg|png|css|eot|map|swp|ttf|svg|woff|woff2|js)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from =~ /\.(db|ico|jpg|png|css|eot|map|swp|ttf|svg|woff|woff2|js)$/) 68 20 88
382 68 $content = $self->_process_template($content, $vars);
383 }
384  
385 88 path( $to )->spew_raw( $content );
386 88 ▶ if( $ex ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ex) 12 76 88
387 12 ▶ $to->chmod( 0755 ) or warn "unable to change permissions for $to: $!";
Branch: 1 branch
BranchTrueFalseTotal
$to->chmod(493) or warn "unable to change permissions for ${to}: $!" 0 12 12
388 }
389 }
390 }
391  
392 sub _create_manifest {
393 4 ▶ my ( $self, $files, $dir ) = @_;
Subroutine _create_manifest: called CC=3 SCAR=11.0
394  
395 4 my $manifest_name = path( $dir, 'MANIFEST' );
396 4 ▶ open( my $manifest, '>', $manifest_name ) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $manifest, ">", $manifest_name or die $! 0 4 4
397 4 print $manifest "MANIFEST\n";
398  
399 4 foreach my $file( @{ $files } ) {
400 88 my $filename = path( $file->[1] )->relative( $dir );
401 88 my $basename = $filename->basename;
402 88 my $clean_basename = $basename;
403 88 $clean_basename =~ s/^\+//;
404 88 $filename =~ s/\Q$basename\E/$clean_basename/;
405 88 print {$manifest} "$filename\n";
406 }
407  
408 4 close $manifest;
409 }
410  
411 sub _add_to_manifest_skip {
412 4 ▶ my ( $self, $dir, $dist_name ) = @_;
Subroutine _add_to_manifest_skip: called CC=2 SCAR=7.0
413  
414 4 my $filename = path( $dir, 'MANIFEST.SKIP' );
415 4 ▶ open my $fh, '>>', $filename or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">>", $filename or die $! 0 4 4
416 4 print {$fh} "^$dist_name-\n";
417 4 close $fh;
418 }
419  
420 sub _process_template {
421 68 ▶ my ( $self, $template, $tokens ) = @_;
Subroutine _process_template: called CC=1 SCAR=0.0
422  
423 68 return $self->_engine->render( \$template, $tokens );
424 }
425  
426 sub _version_check {
427 0 ▶ my $self = shift;
Subroutine _version_check: not called CC=5 SCAR=34.0
428 0 my $version = $self->parent_command->_dancer2_version;
429 0 ▶ return if $version =~ m/_/;
Branch: 1 branch
BranchTrueFalseTotal
if $version =~ /_/ 0 0 0
430  
431 0 my $latest_version = 0;
432 0 my $resp = HTTP::Tiny->new( timeout => 5 )->get( 'https://fastapi.metacpan.org/release/Dancer2' );
433 0 ▶ if( $resp->{ success } && decode_json( $resp->{ content } )->{ version } =~ /(\d\.\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->{'success'} and &decode_json($resp->{'content'})->{'version'} =~ /(\d\.\d+)/) { } 0 0 0
Condition0%0/3
$resp->{"success"} and &decode_json($resp->{"content"})->{"version"} =~ /(\d\.\d+)/
!ll&&!rl&&r
000
MC/DC0%0/2
$resp->{"success"} and &decode_json($resp->{"content"})->{"version"} =~ /(\d\.\d+)/
$resp->{"success"} &decode_json($resp->{"content"})->{"version"} =~ /(\d\.\d+)/
Truth table0%0/3
A and B
A= $resp->{"success"}B= &decode_json($resp->{"content"})->{"version"} =~ /(\d\.\d+)/
ABresult
0X0
100
111
434 0 $latest_version = $1;
435 0 ▶ if ($latest_version gt $version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($latest_version gt $version) 0 0 0
436 0 print qq{
437 The latest stable Dancer2 release is $latest_version. You are currently using $version.
438 Please check https://metacpan.org/pod/Dancer2/ for updates.
439  
440 };
441 }
442 } else {
443 0 warn "\nCouldn't determine latest version of Dancer2. Please check your internet
444 connection, or pass -x to gen to bypass this check in the future.\n\n";
445  
446 }
447 }
448  
449 # Shell out to run git
450 sub _run_shell_cmd {
451 3 ▶ my @cmds = @_;
Subroutine _run_shell_cmd: called CC=1 SCAR=0.2
452  
453 my $exit_status = try {
454 3 ▶ my $pid = IPC::Open3::open3(
Subroutine __ANON__: called CC=1 SCAR=0.0
455 my $stdin,
456 my $stdout,
457 my $stderr = Symbol::gensym,
458 @cmds,
459 );
460  
461 3 waitpid( $pid, 0 );
462 3 return $? >> 8;
463 } catch {
464 0 ▶ print STDERR "$_\n";
Subroutine __ANON__: not called CC=1 SCAR=6.9
465 0 return 1;
466 3 };
467  
468 3 return $exit_status;
469 }
470  
471 6 1;
472  
473 __END__
↑ Summary blib/lib/Dancer2/Handler/AutoPage.pm »