| 1 | # ABSTRACT: Shell into a distribution | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package Pinto::Shell; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use MooseX::Types::Moose qw(Str); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Pinto::Util qw(throw); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Pinto::Types qw(File Dir); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Path::Class qw(file); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Cwd::Guard qw(cwd_guard); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use overload ( q{""} => 'to_string' ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | our $VERSION = '0.14'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | has shell => ( | |||||||||||||||||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | isa => File, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | builder => '_build_shell', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | has archive => ( | |||||||||||||||||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | isa => File, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | has unpacker => ( | ||||||||||||||||||||||||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | isa => 'Pinto::ArchiveUnpacker', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | default => sub { Pinto::ArchiveUnpacker->new( archive => $_[0]->archive ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||
| 41 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | has work_dir => ( | ||||||||||||||||||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | isa => Dir, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | default => sub { $_[0]->unpacker->unpack }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||
| 49 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub _build_shell { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_shell: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | my $shell = $ENV{PINTO_SHELL} || $ENV{SHELL} || $ENV{COMSPEC} | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | or throw "You don't seem to have a SHELL"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$ENV{'PINTO_SHELL'} || $ENV{'SHELL'} || $ENV{'COMSPEC'}
$ENV{"PINTO_SHELL"} or $ENV{"SHELL"}
MC/DC0%0/3
$ENV{'PINTO_SHELL'} || $ENV{'SHELL'} || $ENV{'COMSPEC'}
$ENV{"PINTO_SHELL"}
$ENV{"SHELL"}
$ENV{'COMSPEC'}
Truth table0%0/4
A or B || C
A= $ENV{"PINTO_SHELL"}B= $ENV{"SHELL"}C= $ENV{'COMSPEC'}
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $shell_resolved = eval { file($shell)->resolve } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | or throw "Can't resolve the path to your SHELL $shell"; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | -x $shell_resolved | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | or throw "Your SHELL $shell is not executable"; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return $shell_resolved; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub spawn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spawn: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $cwd_guard = cwd_guard( $self->work_dir ); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # TODO: This probably isn't very portable, especially if the | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # shell command contains spaces or special characters. We | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # probably need to shell-quote the command and pass a list. | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return system("$self") == 0; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return $self->shell->stringify; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||||||||||||||||