autodynaload.pm

filter: Statementstmt 75.2% 85 / 113 Branchbran 25.0% 7 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.0% 17 / 20 Podpod 75.0% 3 / 4 totaltotal 67.8% 112 / 165 CC 19 SCAR 29.5
CC
19
Cov
65%
_dl_findfile
72.0
get_unresolved_deps
20.0
is_installed
6.0
CRAP 19.2
↑ Summary autorequire.pm »
1 package autodynaload ;
2 2 @ISA = qw(autorequire) ;
3  
4 2 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use autorequire ;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use DynaLoader ;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use XSLoader ;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Config ;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use ExtUtils::Installed ;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use File::Spec ;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 2 our $VERSION = '0.08' ;
15  
16 2 @autodynaload::INC = () ;
17 2 autodynaload->new($autodynaload::dl_findfile)->insert(-1) ;
18 2 $autodynaload::disable_expandspec = 1 ;
19  
20 2 my $installed = undef ;
21 2 my $dlext = $Config{dlext} ;
22  
23  
24 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
25 # We need to probe the autoloader by calling it once...
26 2 DynaLoader::dl_findfile() ;
27 2 DynaLoader::dl_expandspec($INC{'autodynaload.pm'}) ;
28  
29 2 $autodynaload::bootstrap = \&DynaLoader::bootstrap ;
30 2 $autodynaload::dl_findfile = \&DynaLoader::dl_findfile ;
31 2 $autodynaload::dl_expandspec = \&DynaLoader::dl_expandspec ;
32 }
33  
34  
35 6 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
36 6 my $class = shift ;
37 6 my $sub = shift ;
38  
39 6 return $class->SUPER::new($sub, \@autodynaload::INC) ;
40 }
41  
42  
43 5 ▶sub _bootstrap {
Subroutine _bootstrap: called CC=1 SCAR=0.0
44 5 my @args = @_ ;
45  
46 5 local $DynaLoader::do_expand = 1 ;
47 5 $autodynaload::bootstrap->(@args) ;
48 }
49  
50  
51 # Stolen from XSLoader.pm
52 5 ▶sub _bootstrap_inherit {
Subroutine _bootstrap_inherit: called CC=1 SCAR=0.0
53 package DynaLoader;
54  
55 5 my $module = $_[0];
56 2 ▶ no strict 'refs' ;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 5 local *DynaLoader::isa = *{"$module\::ISA"};
58 5 local @DynaLoader::isa = (@DynaLoader::isa, 'DynaLoader');
59 # Cannot goto due to delocalization. Will report errors on a wrong line?
60 5 require DynaLoader;
61 5 DynaLoader::bootstrap(@_);
62 }
63  
64  
65 0 ▶sub _dl_findfile {
Subroutine _dl_findfile: not called CC=8 SCAR=42.8
66 0 my @args = @_ ;
67  
68 0 my @ret = () ;
69 0 foreach my $ar (@autodynaload::INC){
70 0 ▶ next if $ar->{disabled} ;
Branch: 1 branch
BranchTrueFalseTotal
if $ar->{"disabled"} 0 0 0
71  
72 0 my $s = $ar->_get_sub() ;
73 0 ▶ if (! ref($s)){
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $s) 0 0 0
74 # Symbolic reference. It may not be defined yet.
75 0 ▶ return undef if !defined(&{$s}) ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{$s;} 0 0 0
76 0 $s = \&{$s} ;
77 }
78  
79 0 ▶ unshift @args, $ar unless $s eq $autodynaload::dl_findfile ;
Branch: 1 branch
BranchTrueFalseTotal
unless $s eq $autodynaload::dl_findfile 0 0 0
80  
81 0 local $autodynaload::disable_expandspec = 0 ;
82 0 @ret = $s->(@args) ;
83 # warn "@args -> @ret" ;
84 0 ▶ last if scalar(@ret) ;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @ret 0 0 0
85 }
86  
87 0 ▶ return wantarray ? @ret : $ret[0] ;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
88 }
89  
90  
91 0 ▶sub _dl_expandspec {
Subroutine _dl_expandspec: not called CC=2 SCAR=17.9
92 0 my @args = @_ ;
93  
94 0 ▶ return undef if $autodynaload::disable_expandspec ;
Branch: 1 branch
BranchTrueFalseTotal
if $autodynaload::disable_expandspec 0 0 0
95 0 $autodynaload::dl_expandspec->(@args) ;
96 }
97  
98  
99 2 ▶sub is_loaded {
Subroutine is_loaded: called CC=3 SCAR=11.0
Pod documented
100 2 my $class = shift ;
101 2 my $filename = shift ;
102 2 my %opts = @_ ;
103  
104 2 my $file = undef ;
105 2 foreach my $so (@DynaLoader::dl_shared_objects){
106 36 ▶ if ($so =~ /$filename\.$dlext$/){
Branch: 1 branch
BranchTrueFalseTotal
if ($so =~ /$filename\.$dlext$/) 1 35 36
107 1 $file = $so ;
108 1 last ;
109 }
110 }
111  
112 2 return $class->_name_or_open_or_slurp_file($file, %opts) ;
113 }
114  
115  
116 3 ▶sub is_installed {
Subroutine is_installed: called CC=6 SCAR=18.0
Pod documented
117 3 my $class = shift ;
118 3 my $filename = shift ;
119 3 my %opts = @_ ;
120  
121 3 ▶ $installed = new ExtUtils::Installed() unless $installed ;
Branch: 1 branch
BranchTrueFalseTotal
unless $installed 1 2 3
122  
123 3 my $file = undef ;
124 3 ▶ if (File::Spec->file_name_is_absolute($filename)){
Branch: 1 branch
BranchTrueFalseTotal
if ('File::Spec'->file_name_is_absolute($filename)) { } 0 3 3
125 0 $file = "$filename.$dlext" ;
126 }
127 else {
128 3 foreach my $module ($installed->modules()){
129 510 foreach my $test ($installed->files($module)){
130 30787 ▶ if ($test =~ /$filename\.$dlext$/){
Branch: 1 branch
BranchTrueFalseTotal
if ($test =~ /$filename\.$dlext$/) 2 30785 30787
131 2 $file = $test ;
132 2 last ;
133 }
134 }
135 }
136 }
137
138 3 return $class->_name_or_open_or_slurp_file($file, %opts) ;
139 }
140  
141  
142 0 ▶sub get_unresolved_deps {
Subroutine get_unresolved_deps: not called CC=4 SCAR=30.0
Pod undocumented
143 0 my $class = shift ;
144 0 my $so = shift ;
145  
146 0 ▶ open(LDD, "/usr/bin/ldd $so |") or
Branch: 1 branch
BranchTrueFalseTotal
open LDD, "/usr/bin/ldd $so |" or croak("Can't execute /usr/bin/ldd: $!") 0 0 0
147 croak("Can't execute /usr/bin/ldd: $!") ;
148 0 my @ret = () ;
149 0 ▶ while (<LDD>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline LDD)) 0 0 0
150 0 my $dep = $_ ;
151 0 ▶ if ($dep =~ /^\s*(.*?) => not found/){
Branch: 1 branch
BranchTrueFalseTotal
if ($dep =~ /^\s*(.*?) => not found/) 0 0 0
152 0 push @ret, $dep ;
153 }
154 }
155
156 0 return @ret ;
157 }
158  
159  
160  
161 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
162 2 local $^W ;
163 2 ▶ no strict 'refs' ;
Subroutine BEGIN: called CC=1 SCAR=0.0
164 2 *{'DynaLoader::dl_expandspec'} = \&autodynaload::_dl_expandspec ;
165 2 *{'DynaLoader::bootstrap'} = \&autodynaload::_bootstrap ;
166 2 *{'DynaLoader::dl_findfile'} = \&autodynaload::_dl_findfile ;
167 # Force XSLoader to use DynaLoader
168 2 *{'XSLoader::load'} = \&autodynaload::_bootstrap_inherit ;
169 }
170  
171  
172 2 1 ;
173 __END__
↑ Summary autorequire.pm »