| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Alien::Build::Plugin::Gather::IsolateDynamic; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 3 |  |  | 3 |  | 1357 | use strict; | 
|  | 3 |  |  |  |  | 15 |  | 
|  | 3 |  |  |  |  | 79 |  | 
| 4 | 3 |  |  | 3 |  | 14 | use warnings; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 60 |  | 
| 5 | 3 |  |  | 3 |  | 50 | use 5.008004; | 
|  | 3 |  |  |  |  | 10 |  | 
| 6 | 3 |  |  | 3 |  | 315 | use Alien::Build::Plugin; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 21 |  | 
| 7 | 3 |  |  | 3 |  | 17 | use Path::Tiny (); | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 68 |  | 
| 8 | 3 |  |  | 3 |  | 15 | use Alien::Build::Util qw( _destdir_prefix ); | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 157 |  | 
| 9 | 3 |  |  | 3 |  | 1292 | use File::Copy (); | 
|  | 3 |  |  |  |  | 5985 |  | 
|  | 3 |  |  |  |  | 1271 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | # ABSTRACT: Plugin to gather dynamic libraries into a separate directory | 
| 12 |  |  |  |  |  |  | our $VERSION = '2.47'; # VERSION | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub init | 
| 16 |  |  |  |  |  |  | { | 
| 17 | 9 |  |  | 9 | 1 | 16 | my($self, $meta) = @_; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | # plugin was introduced in 0.42, but had a bug which was fixed in 0.48 | 
| 20 | 9 |  |  |  |  | 27 | $meta->add_requires('share' => 'Alien::Build::Plugin::Gather::IsolateDynamic' => '0.48' ); | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | $meta->after_hook( | 
| 23 |  |  |  |  |  |  | gather_share => sub { | 
| 24 | 2 |  |  | 2 |  | 5 | my($build) = @_; | 
| 25 | 2 |  |  |  |  | 9 | $build->log("Isolating dynamic libraries ..."); | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 2 |  |  |  |  | 7 | my $install_root; | 
| 28 | 2 | 100 |  |  |  | 6 | if($build->meta_prop->{destdir}) | 
| 29 |  |  |  |  |  |  | { | 
| 30 | 1 |  |  |  |  | 4 | my $destdir = $ENV{DESTDIR}; | 
| 31 | 1 |  |  |  |  | 5 | $install_root = Path::Tiny->new(_destdir_prefix($ENV{DESTDIR}, $build->install_prop->{prefix})); | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  | else | 
| 34 |  |  |  |  |  |  | { | 
| 35 | 1 |  |  |  |  | 4 | $install_root = Path::Tiny->new($build->install_prop->{stage}); | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 2 |  |  |  |  | 91 | foreach my $dir (map { $install_root->child($_) } qw( bin lib )) | 
|  | 4 |  |  |  |  | 52 |  | 
| 39 |  |  |  |  |  |  | { | 
| 40 | 4 | 50 |  |  |  | 105 | next unless -d $dir; | 
| 41 | 4 |  |  |  |  | 68 | foreach my $from ($dir->children) | 
| 42 |  |  |  |  |  |  | { | 
| 43 | 16 | 100 | 66 |  |  | 1325 | next unless $from->basename =~ /\.so/ | 
| 44 |  |  |  |  |  |  | ||          $from->basename =~ /\.(dylib|bundle|la|dll|dll\.a)$/; | 
| 45 | 10 |  |  |  |  | 304 | my $to = $install_root->child('dynamic', $from->basename); | 
| 46 | 10 |  |  |  |  | 335 | $to->parent->mkpath; | 
| 47 | 10 | 50 |  |  |  | 968 | unlink "$to" if -e $to; | 
| 48 | 10 |  |  |  |  | 186 | $build->log("move @{[ $from->parent->basename ]}/@{[ $from->basename ]} => dynamic/@{[ $to->basename ]}"); | 
|  | 10 |  |  |  |  | 28 |  | 
|  | 10 |  |  |  |  | 521 |  | 
|  | 10 |  |  |  |  | 71 |  | 
| 49 | 10 | 50 |  |  |  | 48 | File::Copy::move("$from", "$to") || die "unable to move $from => $to $!"; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 2 |  |  |  |  | 63 | $build->log("                            Done!"); | 
| 54 |  |  |  |  |  |  | }, | 
| 55 | 9 |  |  |  |  | 60 | ); | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | 1; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | __END__ |