1 package Module::ScanDeps::DataFeed;
2 # No compile time deps!
4 $Module::ScanDeps::DataFeed::VERSION = '0.09';
8 Module::ScanDeps::DataFeed - Runtime dependency scanning helper
16 No user-serviceable parts inside.
18 This module is used by the L<Module::ScanDeps> run- and compile-time scanners.
19 It is included in the code run by C<Module::ScanDeps> and will write
20 a string of loaded modules and C<@INC> entries to a file. This is
21 achieved using an C<END {}> hook.
23 Implementation might change, so don't use it outside of Module::ScanDeps!
30 my ($pkg, $filename) = @_;
31 # This is the file we'll write the @INC and %INC info to at END.
32 $_filename = $filename;
34 my $fname = __PACKAGE__;
36 delete $INC{"$fname.pm"} unless $Module::ScanDeps::DataFeed::Loaded;
37 $Module::ScanDeps::DataFeed::Loaded++;
41 # Write %INC and @INC to the file specified at compile time in import()
42 defined $_filename or return;
46 my @dl_so = _dl_shared_objects();
49 require File::Basename;
52 open(FH, "> $_filename") or die "Couldn't open $_filename\n";
53 print FH '%inchash = (' . "\n\t";
57 "\n\t'$_' => '%s/%s'",
58 Cwd::abs_path(File::Basename::dirname($inc{$_})),
59 File::Basename::basename($inc{$_}),
65 print FH '@incarray = (' . "\n\t";
66 # inner map escapes trailing backslashes
67 print FH join(',', map("\n\t'$_'", map {s/\\$/\\\\/; $_} @inc));
71 s/(\.so|\.dll)$/\.bs/ for @dl_bs;
73 print FH '@dl_shared_objects = (' . "\n\t";
75 ',' => map("\n\t'$_'", grep -e, @dl_so, @dl_bs)
81 sub _dl_shared_objects {
82 if (@DynaLoader::dl_shared_objects) {
83 return @DynaLoader::dl_shared_objects;
85 elsif (@DynaLoader::dl_modules) {
86 return map { _dl_mod2filename($_) } @DynaLoader::dl_modules;
92 sub _dl_mod2filename {
95 return if $mod eq 'B';
96 return unless defined &{"$mod\::bootstrap"};
98 eval { require B; require Config; 1 } or return;
99 my $dl_ext = $Config::Config{dlext} if %Config::Config;
101 # Copied from XSLoader
102 my @modparts = split(/::/, $mod);
103 my $modfname = $modparts[-1];
104 my $modpname = join('/', @modparts);
106 foreach my $dir (@INC) {
107 my $file = "$dir/auto/$modpname/$modfname.$dl_ext";
108 return $file if -r $file;
122 Edward S. Peschko E<lt>esp5@pge.comE<gt>,
123 Audrey Tang E<lt>cpan@audreyt.orgE<gt>,
124 to a lesser degree Steffen Mueller E<lt>smueller@cpan.orgE<gt>
126 L<http://par.perl.org/> is the official website for this module. You
127 can write to the mailing list at E<lt>par@perl.orgE<gt>, or send an empty
128 mail to E<lt>par-subscribe@perl.orgE<gt> to participate in the discussion.
130 Please submit bug reports to E<lt>bug-Module-ScanDeps@rt.cpan.orgE<gt>.
134 Copyright 2004-2009 by Edward S. Peschko E<lt>esp5@pge.comE<gt>,
135 Audrey Tang E<lt>cpan@audreyt.orgE<gt>,
136 Steffen Mueller E<lt>smueller@cpan.orgE<gt>
138 This program is free software; you can redistribute it and/or modify it
139 under the same terms as Perl itself.
141 See L<http://www.perl.com/perl/misc/Artistic.html>