| 1 | package Venus::Task::Venus::New; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use 5.018; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Venus::Class 'base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | # IMPORTS | ||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use Venus::Path; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | # INHERITS | ||||||||||
| 15 | |||||||||||
| 16 | 2 | base 'Venus::Task::Venus'; | |||||||||
| 17 | |||||||||||
| 18 | # REQUIRES | ||||||||||
| 19 | |||||||||||
| 20 | 2 | require Venus; | |||||||||
| 21 | |||||||||||
| 22 | # METHODS | ||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub name { | ||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 25 | 0 | 'vns new' | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 29 | 1 | my ($self) = @_; | |||||||||
| 30 | |||||||||||
| 31 | 1 | return $self->Venus::Task::execute; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub footer { | ||||||||
|
Subroutine
footer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 35 | |||||||||||
| 36 | 0 | return <<"EOF"; | |||||||||
| 37 | Copyright 2022-2023, Vesion $Venus::VERSION, The Venus "AUTHOR" and "CONTRIBUTORS" | ||||||||||
| 38 | |||||||||||
| 39 | More information on "vns" and/or the "Venus" standard library, visit | ||||||||||
| 40 | https://p3rl.org/vns. | ||||||||||
| 41 | EOF | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 8 | ▶ | sub perform { | ||||||||
|
Subroutine
perform: called CC=4 SCAR=14.0
| |||||||||||
| 45 | 8 | my ($self) = @_; | |||||||||
| 46 | |||||||||||
| 47 | 8 | my $type = $self->argument_value('type'); | |||||||||
| 48 | |||||||||||
| 49 | 8 | ▶ | my $file = $type ? ".vns.$type" : $self->file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | |||||||||||
| 51 | 8 | my $path = Venus::Path->new($file)->absolute; | |||||||||
| 52 | |||||||||||
| 53 | 8 | $type = $path->extension; | |||||||||
| 54 | |||||||||||
| 55 | 8 | my $supported = grep {$type eq $_} qw(yaml yml json js perl pl); | |||||||||
| 56 | |||||||||||
| 57 | 8 | ▶ | if (!$supported) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 1 | $self->log_error("$path invalid"); | |||||||||
| 59 | |||||||||||
| 60 | 1 | return $self; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 7 | ▶ | if ($path->exists) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | $self->log_error("$path exists"); | |||||||||
| 65 | |||||||||||
| 66 | 0 | return $self; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 7 | require Venus::Config; | |||||||||
| 70 | |||||||||||
| 71 | 7 | Venus::Config->new($self->init)->write_file($path); | |||||||||
| 72 | |||||||||||
| 73 | 7 | $self->log_info("$path created"); | |||||||||
| 74 | |||||||||||
| 75 | 7 | return $self; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 9 | ▶ | sub prepare { | ||||||||
|
Subroutine
prepare: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 79 | 9 | my ($self) = @_; | |||||||||
| 80 | |||||||||||
| 81 | 9 | $self->summary('initialize a new Venus configuration file'); | |||||||||
| 82 | |||||||||||
| 83 | # type | ||||||||||
| 84 | 9 | $self->argument('type', { | |||||||||
| 85 | name => 'type', | ||||||||||
| 86 | help => 'Configuration file type. See "types" below.', | ||||||||||
| 87 | multiples => 0, | ||||||||||
| 88 | required => 0, | ||||||||||
| 89 | type => 'string', | ||||||||||
| 90 | wants => 'string', | ||||||||||
| 91 | }); | ||||||||||
| 92 | |||||||||||
| 93 | # json | ||||||||||
| 94 | 9 | $self->choice('json', { | |||||||||
| 95 | name => 'json', | ||||||||||
| 96 | help => 'A JSON configuration file. E.g. .vns.json.', | ||||||||||
| 97 | argument => 'type', | ||||||||||
| 98 | }); | ||||||||||
| 99 | |||||||||||
| 100 | # js | ||||||||||
| 101 | 9 | $self->choice('js', { | |||||||||
| 102 | name => 'js', | ||||||||||
| 103 | help => 'A JSON configuration file. E.g. .vns.js.', | ||||||||||
| 104 | argument => 'type', | ||||||||||
| 105 | }); | ||||||||||
| 106 | |||||||||||
| 107 | # perl | ||||||||||
| 108 | 9 | $self->choice('perl', { | |||||||||
| 109 | name => 'perl', | ||||||||||
| 110 | help => 'A Perl configuration file. E.g. .vns.perl.', | ||||||||||
| 111 | argument => 'type', | ||||||||||
| 112 | }); | ||||||||||
| 113 | |||||||||||
| 114 | # pl | ||||||||||
| 115 | 9 | $self->choice('pl', { | |||||||||
| 116 | name => 'pl', | ||||||||||
| 117 | help => 'A Perl configuration file. E.g. .vns.pl.', | ||||||||||
| 118 | argument => 'type', | ||||||||||
| 119 | }); | ||||||||||
| 120 | |||||||||||
| 121 | # yaml | ||||||||||
| 122 | 9 | $self->choice('yaml', { | |||||||||
| 123 | name => 'yaml', | ||||||||||
| 124 | help => 'A YAML configuration file. E.g. .vns.yaml.', | ||||||||||
| 125 | argument => 'type', | ||||||||||
| 126 | }); | ||||||||||
| 127 | |||||||||||
| 128 | # yml | ||||||||||
| 129 | 9 | $self->choice('yml', { | |||||||||
| 130 | name => 'yml', | ||||||||||
| 131 | help => 'A YAML configuration file. E.g. .vns.yml.', | ||||||||||
| 132 | argument => 'type', | ||||||||||
| 133 | }); | ||||||||||
| 134 | |||||||||||
| 135 | # help | ||||||||||
| 136 | 9 | $self->option('help', { | |||||||||
| 137 | name => 'help', | ||||||||||
| 138 | help => 'Display the help text.', | ||||||||||
| 139 | multiples => 0, | ||||||||||
| 140 | required => 0, | ||||||||||
| 141 | type => 'boolean', | ||||||||||
| 142 | wants => 'boolean', | ||||||||||
| 143 | }); | ||||||||||
| 144 | |||||||||||
| 145 | 9 | return $self; | |||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | 2 | 1; | |||||||||
| 149 | |||||||||||
| 150 | |||||||||||
| 151 | =head1 NAME | ||||||||||
| 152 | |||||||||||
| 153 | Venus::Task::Venus::New - vns new | ||||||||||
| 154 | |||||||||||
| 155 | =cut | ||||||||||
| 156 | |||||||||||
| 157 | =head1 ABSTRACT | ||||||||||
| 158 | |||||||||||
| 159 | Task Class for Venus CLI | ||||||||||
| 160 | |||||||||||
| 161 | =cut | ||||||||||
| 162 | |||||||||||
| 163 | =head1 SYNOPSIS | ||||||||||
| 164 | |||||||||||
| 165 | use Venus::Task::Venus::New; | ||||||||||
| 166 | |||||||||||
| 167 | my $task = Venus::Task::Venus::New->new; | ||||||||||
| 168 | |||||||||||
| 169 | # bless(.., 'Venus::Task::Venus::New') | ||||||||||
| 170 | |||||||||||
| 171 | =cut | ||||||||||
| 172 | |||||||||||
| 173 | =head1 DESCRIPTION | ||||||||||
| 174 | |||||||||||
| 175 | This package is a task class for the C<vns-new> CLI, and C<vns new> | ||||||||||
| 176 | sub-command. | ||||||||||
| 177 | |||||||||||
| 178 | =cut | ||||||||||
| 179 | |||||||||||
| 180 | =head1 INHERITS | ||||||||||
| 181 | |||||||||||
| 182 | This package inherits behaviors from: | ||||||||||
| 183 | |||||||||||
| 184 | L<Venus::Task::Venus> | ||||||||||
| 185 | |||||||||||
| 186 | =cut | ||||||||||
| 187 | |||||||||||
| 188 | =head1 METHODS | ||||||||||
| 189 | |||||||||||
| 190 | This package provides the following methods: | ||||||||||
| 191 | |||||||||||
| 192 | =cut | ||||||||||
| 193 | |||||||||||
| 194 | =head2 new | ||||||||||
| 195 | |||||||||||
| 196 | new(any @args) (Venus::Task::Venus::New) | ||||||||||
| 197 | |||||||||||
| 198 | The new method constructs an instance of the package. | ||||||||||
| 199 | |||||||||||
| 200 | I<Since C<4.15>> | ||||||||||
| 201 | |||||||||||
| 202 | =over 4 | ||||||||||
| 203 | |||||||||||
| 204 | =item new example 1 | ||||||||||
| 205 | |||||||||||
| 206 | package main; | ||||||||||
| 207 | |||||||||||
| 208 | use Venus::Task::Venus::New; | ||||||||||
| 209 | |||||||||||
| 210 | my $task = Venus::Task::Venus::New->new; | ||||||||||
| 211 | |||||||||||
| 212 | # bless({...}, 'Venus::Task::Venus::New') | ||||||||||
| 213 | |||||||||||
| 214 | =back | ||||||||||
| 215 | |||||||||||
| 216 | =cut | ||||||||||
| 217 | |||||||||||
| 218 | =head2 perform | ||||||||||
| 219 | |||||||||||
| 220 | perform() (Venus::Task::Venus::New) | ||||||||||
| 221 | |||||||||||
| 222 | The perform method executes the CLI logic. | ||||||||||
| 223 | |||||||||||
| 224 | I<Since C<4.15>> | ||||||||||
| 225 | |||||||||||
| 226 | =over 4 | ||||||||||
| 227 | |||||||||||
| 228 | =item perform example 1 | ||||||||||
| 229 | |||||||||||
| 230 | # given: synopsis | ||||||||||
| 231 | |||||||||||
| 232 | package main; | ||||||||||
| 233 | |||||||||||
| 234 | $task->prepare; | ||||||||||
| 235 | |||||||||||
| 236 | my $perform = $task->perform; | ||||||||||
| 237 | |||||||||||
| 238 | # bless(.., 'Venus::Task::Venus::New') | ||||||||||
| 239 | |||||||||||
| 240 | # creates a .vns.pl file | ||||||||||
| 241 | |||||||||||
| 242 | =back | ||||||||||
| 243 | |||||||||||
| 244 | =over 4 | ||||||||||
| 245 | |||||||||||
| 246 | =item perform example 2 | ||||||||||
| 247 | |||||||||||
| 248 | # given: synopsis | ||||||||||
| 249 | |||||||||||
| 250 | package main; | ||||||||||
| 251 | |||||||||||
| 252 | $task->prepare; | ||||||||||
| 253 | |||||||||||
| 254 | $task->parse('pl'); | ||||||||||
| 255 | |||||||||||
| 256 | my $perform = $task->perform; | ||||||||||
| 257 | |||||||||||
| 258 | # bless(.., 'Venus::Task::Venus::New') | ||||||||||
| 259 | |||||||||||
| 260 | # creates a .vns.pl file | ||||||||||
| 261 | |||||||||||
| 262 | =back | ||||||||||
| 263 | |||||||||||
| 264 | =over 4 | ||||||||||
| 265 | |||||||||||
| 266 | =item perform example 3 | ||||||||||
| 267 | |||||||||||
| 268 | # given: synopsis | ||||||||||
| 269 | |||||||||||
| 270 | package main; | ||||||||||
| 271 | |||||||||||
| 272 | $task->prepare; | ||||||||||
| 273 | |||||||||||
| 274 | $task->parse('perl'); | ||||||||||
| 275 | |||||||||||
| 276 | my $perform = $task->perform; | ||||||||||
| 277 | |||||||||||
| 278 | # bless(.., 'Venus::Task::Venus::New') | ||||||||||
| 279 | |||||||||||
| 280 | # creates a .vns.perl file | ||||||||||
| 281 | |||||||||||
| 282 | =back | ||||||||||
| 283 | |||||||||||
| 284 | =over 4 | ||||||||||
| 285 | |||||||||||
| 286 | =item perform example 4 | ||||||||||
| 287 | |||||||||||
| 288 | # given: synopsis | ||||||||||
| 289 | |||||||||||
| 290 | package main; | ||||||||||
| 291 | |||||||||||
| 292 | $task->prepare; | ||||||||||
| 293 | |||||||||||
| 294 | $task->parse('json'); | ||||||||||
| 295 | |||||||||||
| 296 | my $perform = $task->perform; | ||||||||||
| 297 | |||||||||||
| 298 | # bless(.., 'Venus::Task::Venus::New') | ||||||||||
| 299 | |||||||||||
| 300 | # creates a .vns.json file | ||||||||||
| 301 | |||||||||||
| 302 | =back | ||||||||||
| 303 | |||||||||||
| 304 | =over 4 | ||||||||||
| 305 | |||||||||||
| 306 | =item perform example 5 | ||||||||||
| 307 | |||||||||||
| 308 | # given: synopsis | ||||||||||
| 309 | |||||||||||
| 310 | package main; | ||||||||||
| 311 | |||||||||||
| 312 | $task->prepare; | ||||||||||
| 313 | |||||||||||
| 314 | $task->parse('js'); | ||||||||||
| 315 | |||||||||||
| 316 | my $perform = $task->perform; | ||||||||||
| 317 | |||||||||||
| 318 | # bless(.., 'Venus::Task::Venus::New') | ||||||||||
| 319 | |||||||||||
| 320 | # creates a .vns.js file | ||||||||||
| 321 | |||||||||||
| 322 | =back | ||||||||||
| 323 | |||||||||||
| 324 | =over 4 | ||||||||||
| 325 | |||||||||||
| 326 | =item perform example 6 | ||||||||||
| 327 | |||||||||||
| 328 | # given: synopsis | ||||||||||
| 329 | |||||||||||
| 330 | package main; | ||||||||||
| 331 | |||||||||||
| 332 | $task->prepare; | ||||||||||
| 333 | |||||||||||
| 334 | $task->parse('yaml'); | ||||||||||
| 335 | |||||||||||
| 336 | my $perform = $task->perform; | ||||||||||
| 337 | |||||||||||
| 338 | # bless(.., 'Venus::Task::Venus::New') | ||||||||||
| 339 | |||||||||||
| 340 | # creates a .vns.yaml file | ||||||||||
| 341 | |||||||||||
| 342 | =back | ||||||||||
| 343 | |||||||||||
| 344 | =over 4 | ||||||||||
| 345 | |||||||||||
| 346 | =item perform example 7 | ||||||||||
| 347 | |||||||||||
| 348 | # given: synopsis | ||||||||||
| 349 | |||||||||||
| 350 | package main; | ||||||||||
| 351 | |||||||||||
| 352 | $task->prepare; | ||||||||||
| 353 | |||||||||||
| 354 | $task->parse('yml'); | ||||||||||
| 355 | |||||||||||
| 356 | my $perform = $task->perform; | ||||||||||
| 357 | |||||||||||
| 358 | # bless(.., 'Venus::Task::Venus::New') | ||||||||||
| 359 | |||||||||||
| 360 | # creates a .vns.yml file | ||||||||||
| 361 | |||||||||||
| 362 | =back | ||||||||||
| 363 | |||||||||||
| 364 | =over 4 | ||||||||||
| 365 | |||||||||||
| 366 | =item perform example 8 | ||||||||||
| 367 | |||||||||||
| 368 | # given: synopsis | ||||||||||
| 369 | |||||||||||
| 370 | package main; | ||||||||||
| 371 | |||||||||||
| 372 | $task->prepare; | ||||||||||
| 373 | |||||||||||
| 374 | $task->parse('toml'); | ||||||||||
| 375 | |||||||||||
| 376 | my $perform = $task->perform; | ||||||||||
| 377 | |||||||||||
| 378 | # bless(.., 'Venus::Task::Venus::New') | ||||||||||
| 379 | |||||||||||
| 380 | # Error: type "toml" invalid | ||||||||||
| 381 | |||||||||||
| 382 | =back | ||||||||||
| 383 | |||||||||||
| 384 | =cut | ||||||||||
| 385 | |||||||||||
| 386 | =head1 AUTHORS | ||||||||||
| 387 | |||||||||||
| 388 | Awncorp, C<awncorp@cpan.org> | ||||||||||
| 389 | |||||||||||
| 390 | =cut | ||||||||||
| 391 | |||||||||||
| 392 | =head1 LICENSE | ||||||||||
| 393 | |||||||||||
| 394 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||||||||||
| 395 | |||||||||||
| 396 | This program is free software, you can redistribute it and/or modify it under | ||||||||||
| 397 | the terms of the Apache license version 2.0. | ||||||||||
| 398 | |||||||||||
| 399 | =cut | ||||||||||