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   810 use v5.22;
  1         4  
7 1     1   1954 use autodie qw( open close );
  1         53294  
  1         8  
8              
9 1     1   2000 use IO::File;
  1         12526  
  1         172  
10              
11 1     1   884 use List::MoreUtils qw( uniq );
  1         12039  
  1         9  
12              
13             ########################################################################
14             # package variables
15             ########################################################################
16              
17             our $VERSION = '0.3.0';
18             $VERSION = eval "$VERSION";
19              
20             sub import
21 0           {
22             # all this does it localize $path for the END closure.
23              
24 1     1   128 my ( undef, $path ) = @_;
25              
26             END
27             {
28             $ENV{ DEVEL_SHAREDLIBS_PRINT }
29             or return;
30              
31             $path ||= $ENV{ DEVEL_SHAREDLIBS_PATH };
32              
33             local $, = "\n";
34             local $\ = "\n";
35              
36             my $fh
37             = $path
38             ? IO::File->new( $path, 'w' )
39             : *STDOUT{ IO }
40             ;
41              
42             print $fh
43             "# ldd '$^X', '$0'" =>
44             uniq
45             sort
46             map
47             {
48             # the literal '=>' dodges linux-vdso & friends,
49             # which lack a path and also the
50             # "not a dynamic executable" messages from
51             # most of the contents.
52              
53             my ( $lib ) = m{ => \s+ (\S+) }x;
54              
55             $lib || ()
56             }
57             map
58             {
59             split "\n" => qx(ldd $_ 2>/dev/null )
60             }
61             (
62             $^X,
63             values %INC
64             );
65              
66             close $fh;
67             }
68             }
69              
70             # keep require happy
71             1
72             __END__