File Coverage

lib/Devel/SharedLibs.pm
Criterion Covered Total %
statement 12 13 92.3
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 17 18 94.4


line stmt bran cond sub pod time code
1             ########################################################################
2             # housekeeping
3             ########################################################################
4              
5             package Devel::SharedLibs;
6 1     1   620 use v5.22;
  1         3  
7 1     1   856 use autodie qw( open close );
  1         17775  
  1         4  
8              
9 1     1   1165 use IO::File;
  1         8292  
  1         172  
10              
11 1     1   873 use List::MoreUtils qw( uniq );
  1         11561  
  1         9  
12              
13             ########################################################################
14             # package variables
15             ########################################################################
16              
17             our $VERSION = 'v0.3.1';
18             $VERSION = eval "$VERSION";
19              
20             sub import
21 0           {
22             # all this does it localize $path for the END closure.
23             # kwikhak for the moment until I find out if there is
24             # any decent way to deal with ldd on BSD.
25              
26 1     1   129 my ( undef, $path ) = @_;
27              
28             END
29             {
30             $ENV{ DEVEL_SHAREDLIBS_PRINT }
31             or return;
32              
33             $path ||= $ENV{ DEVEL_SHAREDLIBS_PATH };
34              
35             # avoid stale output.
36              
37             if( $path && -e $path )
38             {
39             unlink $path
40             or do
41             {
42             say STDERR
43             "Failed unlink: '$path', aborting";
44             exit -1;
45             };
46             }
47              
48             qx{ ldd --version };
49              
50             if( $? )
51             {
52             say STDERR
53             "Non-zeo exit: ldd --version ($?), no ouptut produced.";
54              
55             exit $?
56             }
57              
58             local $, = "\n";
59             local $\ = "\n";
60              
61             my $fh
62             = $path
63             ? IO::File->new( $path, 'w' )
64             : *STDOUT{ IO }
65             ;
66              
67             print $fh
68             "# ldd '$^X', '$0'" =>
69             uniq
70             sort
71             map
72             {
73             # the literal '=>' dodges linux-vdso & friends,
74             # which lack a path and also the
75             # "not a dynamic executable" messages from
76             # most of the contents.
77              
78             my ( $lib ) = m{ => \s+ (\S+) }x;
79              
80             $lib || ()
81             }
82             map
83             {
84             split "\n" => qx(ldd $_ 2>/dev/null )
85             }
86             (
87             $^X,
88             values %INC
89             );
90              
91             close $fh;
92              
93             say STDERR "SharedLibs output: '$path'";
94             }
95             }
96              
97             # keep require happy
98             1
99             __END__