| 1 | package Shipwright::Script; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use App::CLI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Shipwright::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use base qw/App::CLI Shipwright::Base/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | __PACKAGE__->mk_accessors(qw/repository log_file log_level/); | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head2 alias | ||||||||||||||||||||||||||||
| 11 | =cut | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 9 | ▶ | sub alias { | ||||||||||||||||||||||||||
|
Subroutine
alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | return ( | ||||||||||||||||||||||||||||
| 15 | 9 | ls => 'list', | |||||||||||||||||||||||||||
| 16 | del => 'delete', | ||||||||||||||||||||||||||||
| 17 | up => 'update', | ||||||||||||||||||||||||||||
| 18 | init => 'create', | ||||||||||||||||||||||||||||
| 19 | initialize => 'create', | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head2 global_options | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 9 | ▶ | sub global_options { | ||||||||||||||||||||||||||
|
Subroutine
global_options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | ( | ||||||||||||||||||||||||||||
| 29 | 9 | 'r|repository=s' => 'repository', | |||||||||||||||||||||||||||
| 30 | 'l|log-level=s' => 'log_level', | ||||||||||||||||||||||||||||
| 31 | 'log-file=s' => 'log_file', | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head2 prepare | ||||||||||||||||||||||||||||
| 36 | =cut | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 9 | ▶ | sub prepare { | ||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=12 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | 9 | ▶ | $ARGV[0] = 'help' unless @ARGV; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 9 | ▶ | if ( $ARGV[0] =~ /--?h(elp)?/i ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 43 | 2 | $ARGV[0] = 'help'; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | elsif ( $ARGV[0] =~ /^(-v|--version|version)$/ ) { | ||||||||||||||||||||||||||||
| 46 | 0 | print( "This is Shipwright, version $Shipwright::VERSION" . "\n" ); | |||||||||||||||||||||||||||
| 47 | 0 | exit 0; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 9 | my $action = $ARGV[0]; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 9 | my $cmd = $self->SUPER::prepare(@_); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 6 | ▶ | unless ( ref $cmd eq 'Shipwright::Script::Help' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | $cmd->repository( $ENV{SHIPWRIGHT_SHIPYARD} ) | ||||||||||||||||||||||||||||
| 56 | 3 | ▶ | if !$cmd->repository && $ENV{SHIPWRIGHT_SHIPYARD}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $cmd->repository and $ENV{"SHIPWRIGHT_SHIPYARD"}
MC/DC0%0/2
not $cmd->repository and $ENV{"SHIPWRIGHT_SHIPYARD"}
not $cmd->repository
$ENV{"SHIPWRIGHT_SHIPYARD"}
Truth table66%2/3
not(A) and B
A= not $cmd->repositoryB= $ENV{"SHIPWRIGHT_SHIPYARD"}
| |||||||||||||||||||||||||||||
| 57 | $cmd->repository( $ENV{SHIPWRIGHT_REPOSITORY} ) | ||||||||||||||||||||||||||||
| 58 | 3 | ▶ | if !$cmd->repository && $ENV{SHIPWRIGHT_REPOSITORY}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $cmd->repository and $ENV{"SHIPWRIGHT_REPOSITORY"}
MC/DC0%0/2
not $cmd->repository and $ENV{"SHIPWRIGHT_REPOSITORY"}
not $cmd->repository
$ENV{"SHIPWRIGHT_REPOSITORY"}
Truth table66%2/3
not(A) and B
A= not $cmd->repositoryB= $ENV{"SHIPWRIGHT_REPOSITORY"}
| |||||||||||||||||||||||||||||
| 59 | 3 | ▶ | if ( $cmd->repository ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 2 | require Shipwright::Backend; | |||||||||||||||||||||||||||
| 61 | 2 | my $backend = Shipwright::Backend->new( | |||||||||||||||||||||||||||
| 62 | repository => $cmd->repository, | ||||||||||||||||||||||||||||
| 63 | no_sync_local_dir => 1, | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # this $shipwright object will do nothing, except for init logging | ||||||||||||||||||||||||||||
| 67 | 0 | my $shipwright = Shipwright->new( | |||||||||||||||||||||||||||
| 68 | repository => $cmd->repository, | ||||||||||||||||||||||||||||
| 69 | log_level => $cmd->log_level, | ||||||||||||||||||||||||||||
| 70 | log_file => $cmd->log_file, | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | confess_or_die 'invalid repository: ' | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 73 | . $cmd->repository | ||||||||||||||||||||||||||||
| 74 | unless $backend->check_repository( | ||||||||||||||||||||||||||||
| 75 | action => $action, | ||||||||||||||||||||||||||||
| 76 | $action eq 'create' ? ( force => $cmd->force ) : () | ||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||
| 80 | 1 | confess_or_die "need repository arg\n"; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 3 | return $cmd; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head2 log | ||||||||||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | sub log { | ||||||||||||||||||||||||||
|
Subroutine
log: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # init logging is done in prepare, no need to init here, just returns logger | ||||||||||||||||||||||||||||
| 93 | 1 | return Log::Log4perl->get_logger( ref $self ); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 2 | 1; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||