File Coverage

blib/lib/SDL/Internal/Loader.pm
Criterion Covered Total %
statement 24 24 100.0
branch 6 10 60.0
condition 2 3 66.6
subroutine 5 5 100.0
pod 0 1 0.0
total 37 43 86.0


line stmt bran cond sub pod time code
1             package SDL::Internal::Loader;
2 55     55   178 use strict;
  55         53  
  55         1403  
3 55     55   182 use warnings;
  55         58  
  55         2957  
4             require Exporter;
5             our @ISA = qw(Exporter);
6             our @EXPORT = qw(internal_load_dlls);
7             our @LIBREFS = ();
8              
9 55     55   27533 use SDL::ConfigData;
  55         86  
  55         1869  
10 55     55   23650 use Alien::SDL;
  55         1655148  
  55         7383  
11              
12             # SDL::Internal::Loader is a king of "Dynaloader kung-fu" that is
13             # necessary in situations when you install Allien::SDL from sources
14             # or from prebuilt binaries as in these scenarios the SDL stuff is
15             # installed into so called 'sharedir' somewhere in perl/lib/ tree
16             # on Windows box it is e.g.
17             # C:\strawberry\perl\site\lib\auto\share\dist\Alien-SDL...
18             #
19             # What happens is that for example XS module "SDL::Video" is linked
20             # with -lSDL library which means that resulting "Video.(so|dll)" has
21             # a dependency on "libSDL.(so|dll)" - however "libSDL.(so|dll)" is
22             # neither in PATH (Win) or in LD_LIBRARY_PATH (Unix) so Dynaloader
23             # will fail to load "Video.(so|dll)".
24             #
25             # To handle this we have internal_load_dlls() which has to be called
26             # from XS modules (e.g. SDL::Video) linked with SDL libs like this:
27             #
28             # use SDL::Internal::Loader;
29             # internal_load_dlls(PACKAGE);
30              
31             sub internal_load_dlls($) {
32 427     427 0 636 my $package = shift;
33             ### check if some ld_shlib_map is defined
34 427         2398 my $shlib_map = Alien::SDL->config('ld_shlib_map');
35 427 50       84471 return unless $shlib_map; # empty shlib_map, nothing to do
36              
37             ### get list of lib nicknames based on packagename
38 427         1767 my $lib_nick = SDL::ConfigData->config('SDL_lib_translate')->{$package};
39 427 50       2105 return unless $lib_nick; # no need to load anything
40              
41             ### let us load the corresponding shlibs (*.dll|*.so)
42 427         1431 require DynaLoader;
43 427         678 foreach my $n (@$lib_nick) {
44 507         1217 my $file = $shlib_map->{$n};
45 507 100 66     11096 next unless $file && -e $file;
46 505         19934 my $libref = DynaLoader::dl_load_file( $file, 0 );
47 505 50       2559 push( @DynaLoader::dl_librefs, $libref ) if $libref;
48 505 50       2079 push( @LIBREFS, $libref ) if $libref;
49             }
50             }
51              
52             1;