| 1 | 5 | ▶ | use v5.14.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package OS::Package::Role::Build; | ||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: Provides build method for OS::Package object. | ||||||||||
| 7 | 5 | our $VERSION = '0.2.6'; # VERSION | |||||||||
| 8 | |||||||||||
| 9 | 5 | ▶ | use OS::Package::Log; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 5 | ▶ | use File::Basename qw( basename dirname ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 5 | ▶ | use IPC::Cmd qw( can_run run ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 5 | ▶ | use Env qw( $CC $HOME ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 5 | ▶ | use File::Temp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 5 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 5 | ▶ | use Role::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 5 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 5 | ▶ | use Template; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | sub build { | ||||||||||
| 20 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
build: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 21 | |||||||||||
| 22 | 0 | my $template = Path::Tiny->tempfile; | |||||||||
| 23 | |||||||||||
| 24 | 0 | my $temp_sh = sprintf '%s/install.sh', $self->artifact->workdir; | |||||||||
| 25 | |||||||||||
| 26 | 0 | my $vars = { | |||||||||
| 27 | FAKEROOT => $self->fakeroot, | ||||||||||
| 28 | WORKDIR => $self->artifact->workdir, | ||||||||||
| 29 | PREFIX => $self->prefix, | ||||||||||
| 30 | DISTFILE => $self->artifact->distfile | ||||||||||
| 31 | }; | ||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | if ( defined $self->install ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | $template->spew( $self->install ); | |||||||||
| 35 | } | ||||||||||
| 36 | else { | ||||||||||
| 37 | 0 | return 1; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | if ( ! path($self->fakeroot)->exists ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | path($self->fakeroot)->mkpath; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | my $tt = Template->new( { INCLUDE_PATH => dirname($template) } ); | |||||||||
| 45 | |||||||||||
| 46 | 0 | $tt->process( basename( $template->absolute ), $vars, $temp_sh ); | |||||||||
| 47 | |||||||||||
| 48 | 0 | my $command = [ can_run('bash'), '-e', $temp_sh ]; | |||||||||
| 49 | |||||||||||
| 50 | 0 | $LOGGER->info( sprintf 'building: %s', $self->name ); | |||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | if ( defined $self->artifact->archive ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | chdir path($self->artifact->archive->extract_path)->realpath; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | my ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||
| 57 | run( command => $command ); | ||||||||||
| 58 | |||||||||||
| 59 | 0 | foreach ( @{$full_buf} ) { | |||||||||
| 60 | 0 | $LOGGER->debug($_); | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 0 | chdir $HOME; | |||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | if ( !$success ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | $LOGGER->logcroak( sprintf "install script failed: %s\n", | |||||||||
| 67 | $error_message ); | ||||||||||
| 68 | |||||||||||
| 69 | 0 | return 2; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 0 | return 1; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | __END__ | ||||||||||
| 76 | |||||||||||
| 77 | =pod | ||||||||||
| 78 | |||||||||||
| 79 | =encoding UTF-8 | ||||||||||
| 80 | |||||||||||
| 81 | =head1 NAME | ||||||||||
| 82 | |||||||||||
| 83 | OS::Package::Role::Build - Provides build method for OS::Package object. | ||||||||||
| 84 | |||||||||||
| 85 | =head1 VERSION | ||||||||||
| 86 | |||||||||||
| 87 | version 0.2.6 | ||||||||||
| 88 | |||||||||||
| 89 | =head1 METHODS | ||||||||||
| 90 | |||||||||||
| 91 | =head2 build | ||||||||||
| 92 | |||||||||||
| 93 | Provides method to build the application. | ||||||||||
| 94 | |||||||||||
| 95 | =head1 AUTHOR | ||||||||||
| 96 | |||||||||||
| 97 | James F Wilkus <jfwilkus@cpan.org> | ||||||||||
| 98 | |||||||||||
| 99 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 100 | |||||||||||
| 101 | This software is Copyright (c) 2014 by James F Wilkus. | ||||||||||
| 102 | |||||||||||
| 103 | This is free software, licensed under: | ||||||||||
| 104 | |||||||||||
| 105 | The (three-clause) BSD License | ||||||||||
| 106 | |||||||||||
| 107 | =cut | ||||||||||