| 1 | package WWW::AUR::Package::File; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 5 | ▶ | use warnings 'FATAL' => 'all'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 5 | ▶ | use File::Basename qw(basename); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 5 | ▶ | use Archive::Tar qw(); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 5 | ▶ | use File::Spec qw(); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 5 | ▶ | use File::Path qw(make_path); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 5 | ▶ | use Carp qw(); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 5 | ▶ | use Cwd qw(getcwd); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 5 | ▶ | use WWW::AUR::PKGBUILD qw(); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 5 | ▶ | use WWW::AUR qw(_path_params); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | sub new | ||||||||||||||||||||
| 17 | { | ||||||||||||||||||||
| 18 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 19 | 0 | my ($path) = @_; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | ▶ | Carp::croak "$path does not exist or is not readable" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | unless -r $path; | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 0 | bless { 'srcpkg_path' => $path, | |||||||||||||||||||
| 25 | _path_params( @_ ) }, $class; | ||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | #---PUBLIC METHOD--- | ||||||||||||||||||||
| 29 | sub pkgbuild | ||||||||||||||||||||
| 30 | { | ||||||||||||||||||||
| 31 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
pkgbuild: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | return $self->{pkgbuild} | ||||||||||||||||||||
| 34 | 0 | ▶ | if $self->{pkgbuild}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | ▶ | $self->extract() unless $self->src_dir_path(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | my $pbpath = $self->make_src_path( 'PKGBUILD' ); | |||||||||||||||||||
| 39 | 0 | ▶ | open my $pbfile, '<', $pbpath or die "open: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 0 | my $pbtext = do { local $/; <$pbfile> }; | |||||||||||||||||||
| 41 | 0 | close $pbfile; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | $self->{pkgbuild} = WWW::AUR::PKGBUILD->new( $pbtext ); | |||||||||||||||||||
| 44 | return $self->{pkgbuild} | ||||||||||||||||||||
| 45 | 0 | } | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | #---PUBLIC METHOD--- | ||||||||||||||||||||
| 48 | sub name | ||||||||||||||||||||
| 49 | { | ||||||||||||||||||||
| 50 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | # Only use the PKGBUILD if it is extracted already... | ||||||||||||||||||||
| 53 | 0 | ▶ | return $self->pkgbuild->pkgname if $self->{'pkgbuild'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | # Otherwise parse the filename of the source package. | ||||||||||||||||||||
| 56 | 0 | ▶ | my $name = basename( $self->src_pkg_path(), '.src.tar.gz' ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | or die 'Failed to extract package name from filename: ' | ||||||||||||||||||||
| 58 | . $self->src_pkg_path; | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | return $name; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | #---OBJECT METHOD--- | ||||||||||||||||||||
| 64 | sub extract | ||||||||||||||||||||
| 65 | { | ||||||||||||||||||||
| 66 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
extract: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | my $pkgpath = $self->src_pkg_path(); | |||||||||||||||||||
| 69 | 0 | my $destdir = $self->{extpath}; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | make_path( $destdir ); | |||||||||||||||||||
| 72 | 0 | my $olddir = getcwd(); | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | eval { | |||||||||||||||||||
| 75 | 0 | ▶ | my $tarball = Archive::Tar->new( $pkgpath ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | or die 'Failed to create Archive::Tar object'; | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 0 | ▶ | chdir $destdir or Carp::confess "Failed to chdir to $destdir"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | ▶ | $tarball->extract() | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | or Carp::croak "Failed to extract source package file\nerror:" | ||||||||||||||||||||
| 82 | . $tarball->error; | ||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | # ALWAYS chdir back... | ||||||||||||||||||||
| 86 | 0 | { local $@; chdir $olddir; } | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | # Propogates an error if one exists... | ||||||||||||||||||||
| 89 | 0 | ▶ | die if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | my $srcpkg_dir = File::Spec->catdir( $destdir, $self->name ); | |||||||||||||||||||
| 92 | 0 | return $self->{srcpkg_dir} = $srcpkg_dir; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | #---PUBLIC METHOD--- | ||||||||||||||||||||
| 96 | sub src_pkg_path | ||||||||||||||||||||
| 97 | { | ||||||||||||||||||||
| 98 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
src_pkg_path: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 99 | 0 | return $self->{srcpkg_path}; | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | #---PUBLIC METHOD--- | ||||||||||||||||||||
| 103 | sub src_dir_path | ||||||||||||||||||||
| 104 | { | ||||||||||||||||||||
| 105 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
src_dir_path: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 106 | 0 | return $self->{srcpkg_dir}; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | #---PUBLIC METHOD--- | ||||||||||||||||||||
| 110 | sub make_src_path | ||||||||||||||||||||
| 111 | { | ||||||||||||||||||||
| 112 | 0 | ▶ | my ($self, $relpath) = @_; | ||||||||||||||||||
|
Subroutine
make_src_path: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 0 | ▶ | Carp::croak 'You must call extract() before make_src_path()' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | unless $self->src_dir_path; | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | $relpath =~ s{\A/+}{}; | |||||||||||||||||||
| 118 | 0 | return File::Spec->catfile( $self->src_dir_path, | |||||||||||||||||||
| 119 | $relpath ); | ||||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | #---PRIVATE METHOD--- | ||||||||||||||||||||
| 123 | sub _builtpkg_path | ||||||||||||||||||||
| 124 | { | ||||||||||||||||||||
| 125 | 0 | ▶ | my ($self, $pkgdest) = @_; | ||||||||||||||||||
|
Subroutine
_builtpkg_path: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 126 | 0 | my $pkgbuild = $self->pkgbuild; | |||||||||||||||||||
| 127 | 0 | my $arch = $pkgbuild->arch; | |||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 0 | ▶ | if ( eval { $arch->[0] eq 'any' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 130 | 0 | $arch = 'any'; | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 0 | ▶ | unless ( $arch eq 'any' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 134 | 0 | chomp ( $arch = `uname -m` ); | |||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 0 | my $pkgfile = sprintf '%s-%s-%d-%s.pkg.tar', | |||||||||||||||||||
| 138 | $pkgbuild->pkgname, $pkgbuild->pkgver, $pkgbuild->pkgrel, $arch; | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 0 | ($pkgfile) = ( grep { -f $_ } | |||||||||||||||||||
| 141 | 0 | map { File::Spec->catfile( $pkgdest, $_ ) } | |||||||||||||||||||
| 142 | glob( $pkgfile . '{,.xz,.gz}' )); | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 0 | return $pkgfile | |||||||||||||||||||
| 145 | } | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | #---PUBLIC METHOD--- | ||||||||||||||||||||
| 148 | sub build | ||||||||||||||||||||
| 149 | { | ||||||||||||||||||||
| 150 | 0 | ▶ | my ($self, %params) = @_; | ||||||||||||||||||
|
Subroutine
build: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | 0 | ▶ | return $self->bin_pkg_path() | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 153 | if $self->bin_pkg_path(); | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 0 | ▶ | my $srcdir = $self->src_dir_path || $self->extract(); | ||||||||||||||||||
|
Condition0%0/3
$self->src_dir_path || $self->extract
MC/DC0%0/2
$self->src_dir_path || $self->extract
$self->src_dir_path
$self->extract
Truth table0%0/3
A || B
A= $self->src_dir_pathB= $self->extract
| |||||||||||||||||||||
| 156 | 0 | my $pkgdest = $params{ pkgdest }; | |||||||||||||||||||
| 157 | 0 | ▶ | if ( $pkgdest ) { $pkgdest =~ s{/+\z}{}; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | 0 | else { $pkgdest = $self->{destpath}; } | |||||||||||||||||||
| 159 | 0 | $pkgdest = File::Spec->rel2abs( $pkgdest ); | |||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 0 | make_path( $pkgdest ); | |||||||||||||||||||
| 162 | 0 | my $oldcwd = getcwd(); | |||||||||||||||||||
| 163 | 0 | chdir $srcdir; | |||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | 0 | my $cmd = 'makepkg -f'; | |||||||||||||||||||
| 166 | 0 | ▶ | $cmd = "$params{prefix} $cmd" if $params{prefix}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 167 | 0 | ▶ | $cmd = "$cmd $params{args}" if $params{args}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | 0 | ▶ | if ( $params{quiet} ) { $cmd .= ' 2>&1 >/dev/null'; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 0 | local $ENV{PKGDEST} = $pkgdest; | |||||||||||||||||||
| 172 | 0 | system $cmd; | |||||||||||||||||||
| 173 | 0 | ▶ | unless ( $? == 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 174 | 0 | ▶ | my $errmsg = sprintf "makepkg failed to run: %s.\nError", | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 175 | ( $? & 127 | ||||||||||||||||||||
| 176 | ? sprintf 'signal %d', $? & 127 | ||||||||||||||||||||
| 177 | : sprintf 'error code %d', $? >> 8 ); | ||||||||||||||||||||
| 178 | 0 | die $errmsg; | |||||||||||||||||||
| 179 | } | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | 0 | chdir $oldcwd; | |||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | 0 | ▶ | my $built_path = $self->_builtpkg_path( $pkgdest ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 184 | or die "makepkg succeeded but the package file is missing.\nError"; | ||||||||||||||||||||
| 185 | 0 | return $self->{builtpkg_path} = $built_path; | |||||||||||||||||||
| 186 | } | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | #---PUBLIC METHOD--- | ||||||||||||||||||||
| 189 | sub bin_pkg_path | ||||||||||||||||||||
| 190 | { | ||||||||||||||||||||
| 191 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
bin_pkg_path: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 192 | 0 | return $self->{builtpkg_path}; | |||||||||||||||||||
| 193 | } | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | 5 | 1; | |||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | __END__ | ||||||||||||||||||||