| 1 | package Win32::Packer::Base; | ||
| 2 | |||
| 3 | use Log::Any; | ||
| 4 | use Path::Tiny; | ||
| 5 | use Win32::Packer::Helpers qw(assert_dir assert_file assert_file_name assert_guid | ||
| 6 | mkpath guid to_uc); | ||
| 7 | use Carp; | ||
| 8 | use Capture::Tiny qw(capture); | ||
| 9 | |||
| 10 | use Moo; | ||
| 11 | use namespace::autoclean; | ||
| 12 | |||
| 13 | has log => ( is => 'rw', default => sub { Log::Any->get_logger } ); | ||
| 14 | has work_dir => ( is => 'lazy', coerce => \&mkpath, isa => \&assert_dir ); | ||
| 15 | has output_dir => ( is => 'ro', coerce => \&mkpath, isa => \&assert_dir, | ||
| 16 | default => sub { path('.')->realpath } ); | ||
| 17 | has app_name => ( is => 'ro', default => sub { 'PerlApp' }, | ||
| 18 | isa => \&assert_file_name ); | ||
| 19 | has app_version => ( is => 'ro', isa => \&assert_file_name); | ||
| 20 | |||
| 21 | has app_vendor => ( is => 'ro', default => 'Acme Ltd.'); | ||
| 22 | |||
| 23 | has app_id => ( is => 'lazy', default => \&guid, coerce => \&to_uc, | ||
| 24 | isa => \&assert_guid ); | ||
| 25 | |||
| 26 | has app_description => ( is => 'ro' ); | ||
| 27 | |||
| 28 | has app_keywords => ( is => 'ro' ); | ||
| 29 | |||
| 30 | has app_comments => ( is => 'ro' ); | ||
| 31 | |||
| 32 | has icon => ( is => 'ro', isa => \&assert_file, coerce => \&path ); | ||
| 33 | |||
| 34 | has system_drive => ( is => 'lazy', isa => \&assert_dir, coerce => \&path, | ||
| 35 | default => sub { $ENV{SystemDrive} // 'C://' } ); | ||
| 36 | |||
| 37 | sub _die { croak shift->log->fatal(@_) } | ||
| 38 | sub _dief { croak shift->log->fatalf(@_) } | ||
| 39 | |||
| 40 | sub _run_cmd { | ||
| 41 | my $self = shift; | ||
| 42 | my @cmd = map { ref eq 'SCALAR' ? grep length, split /\s+/, $$_ : "$_" } @_; | ||
| 43 | $self->log->debugf("running command: %s", \@cmd); | ||
| 44 | my ($out, $err, $rc) = capture { | ||
| 45 | system @cmd; | ||
| 46 | }; | ||
| 47 | $self->log->debugf("command rc: %s, out: %s, err: %s", $rc, \$out, \$err); | ||
| 48 | wantarray ? (($rc == 0), $out, $err) : ($rc == 0) | ||
| 49 | } | ||
| 50 | |||
| 51 | 1; |