| 1 | package Dancer2::CLI::Gen; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Create new Dancer2 application | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | $Dancer2::CLI::Gen::VERSION = '2.3.0'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Dancer2::Template::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Module::Runtime qw( use_module is_module_name ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | use CLI::Osprey | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | desc => 'Helper script to create new Dancer2 applications'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | # For git integration | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | use Symbol; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use IPC::Open3 qw(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | ▶ | use File::Which; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | 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 | 8 | 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 | 8 | 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 | 8 | option overwrite => ( | |||||||||||||||||||||||||||||||||||||||||
| 53 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 54 | short => 'o', | ||||||||||||||||||||||||||||||||||||||||||
| 55 | doc => 'overwrite existing files', | ||||||||||||||||||||||||||||||||||||||||||
| 56 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 8 | 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 | 0 | ▶ | default => sub{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | path( $self->parent_command->_dist_dir, 'skel' ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 8 | 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 | 8 | option docker => ( | |||||||||||||||||||||||||||||||||||||||||
| 92 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 93 | short => 'c', | ||||||||||||||||||||||||||||||||||||||||||
| 94 | doc => 'create a dockerfile (container definition)', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 8 | option git => ( | |||||||||||||||||||||||||||||||||||||||||
| 100 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 101 | short => 'g', | ||||||||||||||||||||||||||||||||||||||||||
| 102 | doc => 'init git repository', | ||||||||||||||||||||||||||||||||||||||||||
| 103 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 8 | 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 | 8 | 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 | 5 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 5 | return Dancer2::Template::Tiny->new( config => { start_tag => '[d2%', end_tag => '%2d]' } ); | |||||||||||||||||||||||||||||||||||||||||
| 127 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | # Last chance to validate args before we attempt to do something with them | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 5 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=9 SCAR=28.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | ▶ | $self->osprey_usage( 1, qq{ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 5 | ▶ | if ( my $remote = $self->remote ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | my $scheme = URI->new( $remote )->scheme // $self->remote; # This feels dirty | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
"URI"->new($remote)->scheme // $self->remote
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
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | $self->osprey_usage( 1, "'$remote' must be a valid URI to git repository") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | unless $scheme =~ / ^ git \@ .+ : .+ \.git $ | ^ http /x; | ||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 5 | my $path = $self->app_path; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | ▶ | -d $path or $self->osprey_usage( 1, "path: directory '$path' does not exist" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | ▶ | -w $path or $self->osprey_usage( 1, "path: directory '$path' is not writeable" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 5 | ▶ | if ( my $skel = $self->skel ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 5 | ▶ | -d $skel or $self->osprey_usage( 1, "skel: directory '$skel' not found" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 5 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 5 | ▶ | $self->_version_check unless $self->no_check; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 5 | my $app_name = $self->application; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 5 | my $app_file = $self->parent_command->_get_app_file( $app_name ); | |||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | my $app_path = $self->parent_command->_get_app_path( $self->app_path, $app_name ); | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | ▶ | if( my $dir = $self->directory ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 4 | $app_path = path( $self->app_path, $dir ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 5 | my $files_to_copy = $self->_build_file_list( $self->skel . '/' . $self->skel_name, $app_path ); | |||||||||||||||||||||||||||||||||||||||||
| 167 | 5 | foreach my $pair( @$files_to_copy ) { | |||||||||||||||||||||||||||||||||||||||||
| 168 | 45 | ▶ | if( $pair->[0] =~ m/lib\/AppFile.pm$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 5 | $pair->[1] = path( $app_path, $app_file ); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 5 | last; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 5 | ▶ | if( $self->docker ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | push @$files_to_copy, [ path( $self->parent_command->_dist_dir, 'docker/Dockerfile' ), "$app_name/Dockerfile" ]; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 5 | 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 | 5 | $self->_copy_templates( $files_to_copy, $vars, $self->overwrite ); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 5 | ▶ | unless( $self->no_package_files ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 5 | $self->_create_manifest( $files_to_copy, $app_path ); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 5 | $self->_add_to_manifest_skip( $app_path, $vars->{cleanfiles} ); | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 5 | $self->_check_git( $vars ); | |||||||||||||||||||||||||||||||||||||||||
| 196 | 5 | $self->_check_yaml; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 5 | $self->_how_to_run( $vars ); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 5 | ▶ | sub _check_git { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_git: called CC=10 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 5 | my( $self, $vars ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 5 | ▶ | if( my $remote = $self->remote or $self->git ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
my $remote = $self->remote or $self->git
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | ▶ | if( _run_shell_cmd( 'git', 'init') != 0 or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
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
_run_shell_cmd("git", "init") != 0 or _run_shell_cmd("git", "add", ".") != 0
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->remote and _run_shell_cmd("git", "remote", "add", "origin", $self->remote) != 0
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 5 | ▶ | sub _check_yaml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_yaml: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 5 | ▶ | if ( ! eval { use_module( 'YAML' ); 1; } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 5 | ▶ | sub _how_to_run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_how_to_run: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 5 | my( $self, $vars ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 5 | my $app_path = $vars->{ apppath }; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 5 | my $app_name = $vars->{ appname }; | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 5 | print "\nYour new application is ready! To run it:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 5 | ▶ | if( $vars->{ docker } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 5 | my $install_deps = ''; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 5 | ▶ | $install_deps = "\n cpanm --installdeps ." | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | if $self->skel_name ne 'default'; | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 5 | 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 | 5 | ▶ | sub _build_file_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_file_list: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 5 | my ( $self, $from, $to ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 5 | $from =~ s{/+$}{}; | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 5 | my @result; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 5 | my $iter = path( $from )->iterator({ recurse => 1 }); | |||||||||||||||||||||||||||||||||||||||||
| 332 | 5 | ▶ | while( my $file = $iter->() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 155 | ▶ | warn "File not found: $file" unless $file->exists; # Paranoia | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 155 | ▶ | next if $file->basename =~ m{^\.git(/|$)}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 155 | ▶ | next if $file->is_dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 110 | my $filename = $file->relative( $from ); | |||||||||||||||||||||||||||||||||||||||||
| 338 | 110 | push @result, [ $file, path( $to, $filename )]; | |||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 5 | return \@result; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 5 | ▶ | sub _copy_templates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_copy_templates: called CC=17 SCAR=33.6
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 5 | my ( $self, $files, $vars, $overwrite ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 5 | my $app_name = $vars->{ appname }; | |||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 5 | foreach my $pair (@$files) { | |||||||||||||||||||||||||||||||||||||||||
| 348 | 110 | my ( $from, $to ) = @{$pair}; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 110 | ▶ | next if $self->no_package_files && $from =~ /MANIFEST\.SKIP$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->no_package_files and $from =~ /MANIFEST\.SKIP$/
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$/
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 110 | ▶ | next if $self->no_package_files && $from =~ /Makefile.PL$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->no_package_files and $from =~ /Makefile.PL$/
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$/
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 110 | ▶ | if ( -f $to && !$overwrite ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f $to and not $overwrite
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | next unless ( $res eq 'y' ) or ( $res eq 'a' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$res eq "y" or $res eq "a"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 110 | $to =~ s/AppFile/$app_name/; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 110 | my $to_dir = path( $to )->parent; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 110 | ▶ | if ( ! $to_dir->is_dir ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 50 | print "+ $to_dir\n"; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 50 | $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 | 110 | my $to_file = path( $to )->basename; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 110 | my $ex = ( $to_file =~ s/^\+// ); | |||||||||||||||||||||||||||||||||||||||||
| 370 | 110 | ▶ | $to = path( $to_dir, $to_file ) if $ex; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 110 | print "+ $to\n"; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 110 | my $content; | |||||||||||||||||||||||||||||||||||||||||
| 374 | { | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 110 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 110 | ▶ | open( my $fh, '<:raw', $from ) or die "unable to open file `$from' for reading: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 110 | $content = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 110 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 110 | ▶ | if( $from !~ m/\.(db|ico|jpg|png|css|eot|map|swp|ttf|svg|woff|woff2|js)$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 85 | $content = $self->_process_template($content, $vars); | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 110 | path( $to )->spew_raw( $content ); | |||||||||||||||||||||||||||||||||||||||||
| 386 | 110 | ▶ | if( $ex ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 15 | ▶ | $to->chmod( 0755 ) or warn "unable to change permissions for $to: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 5 | ▶ | sub _create_manifest { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_manifest: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 5 | my ( $self, $files, $dir ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | # MANIFEST is a list of paths, not prose, so it is written raw: without an | ||||||||||||||||||||||||||||||||||||||||||
| 396 | # explicit layer the handle is in text mode on Windows and every \n becomes | ||||||||||||||||||||||||||||||||||||||||||
| 397 | # \r\n, leaving the generated file with different line endings to every | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # other file _copy_templates writes. | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 5 | my $manifest_name = path( $dir, 'MANIFEST' ); | |||||||||||||||||||||||||||||||||||||||||
| 400 | 5 | ▶ | open( my $manifest, '>:raw', $manifest_name ) or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 5 | print $manifest "MANIFEST\n"; | |||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 5 | foreach my $file( @{ $files } ) { | |||||||||||||||||||||||||||||||||||||||||
| 405 | 110 | my $filename = path( $file->[1] )->relative( $dir ); | |||||||||||||||||||||||||||||||||||||||||
| 406 | 110 | my $basename = $filename->basename; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 110 | my $clean_basename = $basename; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 110 | $clean_basename =~ s/^\+//; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 110 | $filename =~ s/\Q$basename\E/$clean_basename/; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 110 | print {$manifest} "$filename\n"; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 5 | close $manifest; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 5 | ▶ | sub _add_to_manifest_skip { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_to_manifest_skip: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 5 | my ( $self, $dir, $dist_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | # As in _create_manifest: this is a line of patterns, not prose, so it is | ||||||||||||||||||||||||||||||||||||||||||
| 420 | # appended raw, or on Windows the \n would become \r\n and leave a | ||||||||||||||||||||||||||||||||||||||||||
| 421 | # carriage return on the end of the pattern. | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 5 | my $filename = path( $dir, 'MANIFEST.SKIP' ); | |||||||||||||||||||||||||||||||||||||||||
| 423 | 5 | ▶ | open my $fh, '>>:raw', $filename or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 5 | print {$fh} "^$dist_name-\n"; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 5 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 85 | ▶ | sub _process_template { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_template: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 85 | my ( $self, $template, $tokens ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 85 | return $self->_engine->render( \$template, $tokens ); | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | sub _version_check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_version_check: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my $version = $self->parent_command->_dancer2_version; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | return if $version =~ m/_/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my $latest_version = 0; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $resp = HTTP::Tiny->new( timeout => 5 )->get( 'https://fastapi.metacpan.org/release/Dancer2' ); | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | if( $resp->{ success } && decode_json( $resp->{ content } )->{ version } =~ /(\d\.\d+)/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$resp->{"success"} and &decode_json($resp->{"content"})->{"version"} =~ /(\d\.\d+)/
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+)/
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | $latest_version = $1; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ($latest_version gt $version) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | print qq{ | |||||||||||||||||||||||||||||||||||||||||
| 446 | The latest stable Dancer2 release is $latest_version. You are currently using $version. | ||||||||||||||||||||||||||||||||||||||||||
| 447 | Please check https://metacpan.org/pod/Dancer2/ for updates. | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | warn "\nCouldn't determine latest version of Dancer2. Please check your internet | |||||||||||||||||||||||||||||||||||||||||
| 453 | connection, or pass -x to gen to bypass this check in the future.\n\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | # Shell out to run git | ||||||||||||||||||||||||||||||||||||||||||
| 459 | 3 | ▶ | sub _run_shell_cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_shell_cmd: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | 3 | my @cmds = @_; | |||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 3 | ▶ | my $exit_status = try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 3 | my $pid = IPC::Open3::open3( | |||||||||||||||||||||||||||||||||||||||||
| 464 | my $stdin, | ||||||||||||||||||||||||||||||||||||||||||
| 465 | my $stdout, | ||||||||||||||||||||||||||||||||||||||||||
| 466 | my $stderr = Symbol::gensym, | ||||||||||||||||||||||||||||||||||||||||||
| 467 | @cmds, | ||||||||||||||||||||||||||||||||||||||||||
| 468 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 3 | waitpid( $pid, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 471 | 3 | return $? >> 8; | |||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | print STDERR "$_\n"; | |||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 475 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 3 | return $exit_status; | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | __END__ | ||||||||||||||||||||||||||||||||||||||||||